jareditor 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7c8e3df3bf5baf5322111c11ee4c374bd466cd0
4
- data.tar.gz: 658397e3d424c784a722faebe74a5821ac51dbbb
3
+ metadata.gz: 74ddec2036fa178c8a8afd9c7a113860c1efdc61
4
+ data.tar.gz: f70dc7ca5473dfbc93eb0efc88a1e3e93cd16edf
5
5
  SHA512:
6
- metadata.gz: 0122f6e42df9b6696b1de598c6b182047d05948b06dffa8833aac7eaf4f18df68d56325a64c468f597e9fab69650c16af797a1cc39477d1dabd97c283c3fd2ba
7
- data.tar.gz: c592be92a95219df7f0506c143f40f022382170cf348fe2da81fd002d61d0bd80289fa8b204032b7e705ca5650fcdd8d08b76fccc639233b3e05850be2d2e217
6
+ metadata.gz: ac436f1d41c626009ed5d0c3d362aad486c2850a8aeacdea326aaaa197cb75a7504d254275f3fd739161746145645b45304de652f4bffc772d4e64cefe7b3312
7
+ data.tar.gz: 7ad0b45f39fa8ad57c34273920ff1f25a98013713ebbe524f9dd7dc535a4a71a590feb7d2a2dea54568759fd3fa7fc6c406fff8ea4bc337dfe0c5954290d75af
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /vendor
data/.rubocop.yml ADDED
@@ -0,0 +1,149 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ Style/FrozenStringLiteralComment:
5
+ Enabled: false
6
+
7
+ Style/EachWithObject:
8
+ Enabled: false
9
+
10
+ # Relaxed.Ruby.Style
11
+
12
+ Style/Alias:
13
+ Enabled: false
14
+ StyleGuide: http://relaxed.ruby.style/#stylealias
15
+
16
+ Style/BeginBlock:
17
+ Enabled: false
18
+ StyleGuide: http://relaxed.ruby.style/#stylebeginblock
19
+
20
+ Style/BlockDelimiters:
21
+ Enabled: false
22
+ StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
23
+
24
+ Style/Documentation:
25
+ Enabled: false
26
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
27
+
28
+ Style/DotPosition:
29
+ Enabled: false
30
+ StyleGuide: http://relaxed.ruby.style/#styledotposition
31
+
32
+ Style/DoubleNegation:
33
+ Enabled: false
34
+ StyleGuide: http://relaxed.ruby.style/#styledoublenegation
35
+
36
+ Style/EndBlock:
37
+ Enabled: false
38
+ StyleGuide: http://relaxed.ruby.style/#styleendblock
39
+
40
+ Style/FormatString:
41
+ Enabled: false
42
+ StyleGuide: http://relaxed.ruby.style/#styleformatstring
43
+
44
+ Style/IfUnlessModifier:
45
+ Enabled: false
46
+ StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
47
+
48
+ Style/Lambda:
49
+ Enabled: false
50
+ StyleGuide: http://relaxed.ruby.style/#stylelambda
51
+
52
+ Style/ModuleFunction:
53
+ Enabled: false
54
+ StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
55
+
56
+ Style/MultilineBlockChain:
57
+ Enabled: false
58
+ StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
59
+
60
+ Style/NegatedIf:
61
+ Enabled: false
62
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedif
63
+
64
+ Style/NegatedWhile:
65
+ Enabled: false
66
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
67
+
68
+ Style/ParallelAssignment:
69
+ Enabled: false
70
+ StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
71
+
72
+ Style/PercentLiteralDelimiters:
73
+ Enabled: false
74
+ StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
75
+
76
+ Style/PerlBackrefs:
77
+ Enabled: false
78
+ StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
79
+
80
+ Style/Semicolon:
81
+ Enabled: false
82
+ StyleGuide: http://relaxed.ruby.style/#stylesemicolon
83
+
84
+ Style/SignalException:
85
+ Enabled: false
86
+ StyleGuide: http://relaxed.ruby.style/#stylesignalexception
87
+
88
+ Style/SingleLineBlockParams:
89
+ Enabled: false
90
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
91
+
92
+ Style/SingleLineMethods:
93
+ Enabled: false
94
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
95
+
96
+ Style/SpaceBeforeBlockBraces:
97
+ Enabled: false
98
+ StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
99
+
100
+ Style/SpaceInsideParens:
101
+ Enabled: false
102
+ StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
103
+
104
+ Style/SpecialGlobalVars:
105
+ Enabled: false
106
+ StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
107
+
108
+ Style/StringLiterals:
109
+ Enabled: false
110
+ StyleGuide: http://relaxed.ruby.style/#stylestringliterals
111
+
112
+ Style/WhileUntilModifier:
113
+ Enabled: false
114
+ StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
115
+
116
+ Lint/AmbiguousRegexpLiteral:
117
+ Enabled: false
118
+ StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
119
+
120
+ Lint/AssignmentInCondition:
121
+ Enabled: false
122
+ StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
123
+
124
+ Metrics/AbcSize:
125
+ Enabled: false
126
+
127
+ Metrics/BlockNesting:
128
+ Enabled: false
129
+
130
+ Metrics/ClassLength:
131
+ Enabled: false
132
+
133
+ Metrics/ModuleLength:
134
+ Enabled: false
135
+
136
+ Metrics/CyclomaticComplexity:
137
+ Enabled: false
138
+
139
+ Metrics/LineLength:
140
+ Enabled: false
141
+
142
+ Metrics/MethodLength:
143
+ Enabled: false
144
+
145
+ Metrics/ParameterLists:
146
+ Enabled: false
147
+
148
+ Metrics/PerceivedComplexity:
149
+ Enabled: false
data/README.md CHANGED
@@ -4,7 +4,9 @@ The jerk's text editor.
4
4
 
5
5
  ## Installation
6
6
 
7
- $ gem install jareditor
7
+ ```sh
8
+ $ gem install jareditor
9
+ ```
8
10
 
9
11
  ## Usage
10
12
 
@@ -12,15 +14,9 @@ Don't.
12
14
 
13
15
  ## Development
14
16
 
15
- After checking out the repo, run `bin/setup` to install dependencies. Then, run
16
- `rake test` to run the tests. You can also run `bin/console` for an interactive
17
- prompt that will allow you to experiment.
17
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
18
18
 
19
- To install this gem onto your local machine, run `bundle exec rake install`. To
20
- release a new version, update the version number in `version.rb`, and then run
21
- `bundle exec rake release`, which will create a git tag for the version, push
22
- git commits and tags, and push the `.gem` file to
23
- [rubygems.org](https://rubygems.org).
19
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
24
20
 
25
21
  ## Roadmap
26
22
 
@@ -31,8 +27,4 @@ git commits and tags, and push the `.gem` file to
31
27
 
32
28
  ## Contributing
33
29
 
34
- Bug reports and pull requests are welcome on GitHub at
35
- https://github.com/jarednorman/jared. This project is intended to be a safe,
36
- welcoming space for collaboration, and contributors are expected to adhere to
37
- the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
-
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jarednorman/jared. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
8
  end
9
9
 
10
- task :default => :spec
10
+ task default: :test
data/bin/console CHANGED
@@ -1,14 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require "bundler/setup"
4
- require "jar_ed"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
3
+ require "jared"
4
+ require "pry"
5
+ Pry.start
data/lib/jared.rb CHANGED
@@ -1,27 +1,20 @@
1
1
  require "curses"
2
+ require "logger"
2
3
  require "jared/version"
3
4
  require "jared/pane"
5
+ require "jared/file_view"
4
6
  require "jared/buffer"
5
7
 
6
8
  module JarEd
7
9
  class << self
8
10
  def start(args)
9
- buffer = Buffer.new File.open(args[0], "r")
10
- pane.buffer = buffer
11
+ buffer = Buffer.new(args[0])
12
+ pane = Pane.new
13
+ pane.view = FileView.new buffer
11
14
 
12
15
  take_input do |char|
13
- case char
14
- when "h"
15
- buffer.cursor(0, -1)
16
- when "j"
17
- buffer.cursor(1, 0)
18
- when "k"
19
- buffer.cursor(-1, 0)
20
- when "l"
21
- buffer.cursor(0, 1)
22
- when "\e"
23
- break
24
- end
16
+ # FIXME: This should normalize incoming escape sequences and such.
17
+ pane.send_input char
25
18
  pane.refresh(window)
26
19
  end
27
20
  end
@@ -30,14 +23,31 @@ module JarEd
30
23
  "Jared Norman"
31
24
  end
32
25
 
26
+ def logger
27
+ @logger ||=
28
+ begin
29
+ log_directory_path = File.join(jared_folder_path, "logs")
30
+ FileUtils.mkdir_p log_directory_path
31
+ log_file_path = File.join(log_directory_path, "jared.log")
32
+ logger = Logger.new(log_file_path, 10)
33
+ logger.level = Logger::DEBUG
34
+ logger
35
+ end
36
+ end
37
+
33
38
  private
34
39
 
35
- def pane
36
- @pane ||= Pane.new
40
+ def jared_folder_path
41
+ @jared_folder_path ||=
42
+ begin
43
+ path = File.join(Dir.home, ".jared")
44
+ FileUtils.mkdir_p(path)
45
+ path
46
+ end
37
47
  end
38
48
 
39
49
  def window
40
- @window ||= Curses::Window.new(Curses.lines, Curses.cols, 0, 0)
50
+ @window ||= Curses::Window.new(0, 0, 0, 0)
41
51
  end
42
52
 
43
53
  def take_input
@@ -51,7 +61,12 @@ module JarEd
51
61
  Curses.doupdate
52
62
 
53
63
  loop do
54
- yield Curses.getch.chr
64
+ begin
65
+ yield Curses.getch.chr
66
+ rescue RangeError
67
+ yield nil
68
+ end
69
+
55
70
  Curses.doupdate
56
71
  end
57
72
  ensure
data/lib/jared/buffer.rb CHANGED
@@ -1,24 +1,20 @@
1
+ require 'jared/buffer_line'
2
+
1
3
  module JarEd
2
4
  class Buffer
3
- attr_reader :window_position,
4
- :cursor_row,
5
- :cursor_column
6
-
7
- def initialize(file)
8
- @file = file
9
- @window_position = 0
10
- @cursor_row = 0
11
- @cursor_column = 0
5
+ def initialize(filename)
6
+ @file = File.open(filename, "r")
12
7
  end
13
8
 
14
9
  def lines
15
- @lines ||= file.each_line.to_a
10
+ @lines ||= file.each_line.to_a.map { |line| BufferLine.new(line) }
16
11
  end
17
12
 
18
- # @todo Restrict cursor position to file/line length.
19
- def cursor(rows, columns)
20
- @cursor_row = [0, cursor_row + rows].max
21
- @cursor_column = [0, cursor_column + columns].max
13
+ def wrapped_lines(width:, height:, offset:)
14
+ lines.
15
+ slice(offset, lines.length - 1).
16
+ flat_map { |line| line.wrap(width: width) }.
17
+ first(height)
22
18
  end
23
19
 
24
20
  private
@@ -0,0 +1,25 @@
1
+ module JarEd
2
+ class BufferLine
3
+ attr_reader :raw_text
4
+
5
+ def initialize(raw_text)
6
+ @raw_text = raw_text
7
+ end
8
+
9
+ def text
10
+ @text ||= raw_text.chomp
11
+ end
12
+
13
+ def blank?
14
+ text == ""
15
+ end
16
+
17
+ def wrap(width:)
18
+ if blank?
19
+ [""]
20
+ else
21
+ text.scan(/.{1,#{width}}/)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,108 @@
1
+ require 'jared/screen'
2
+
3
+ module JarEd
4
+ class FileView
5
+ attr_accessor :pane
6
+
7
+ def initialize(buffer)
8
+ @buffer = buffer
9
+ @row_offset = 0
10
+ @cursor_row = 0
11
+ @cursor_column = 0
12
+ end
13
+
14
+ # @todo Make this method not awful.
15
+ def to_screen
16
+ Screen.new(
17
+ cursor_column: screen_cursor_column,
18
+ cursor_row: screen_cursor_row,
19
+ lines: screen_lines
20
+ )
21
+ end
22
+
23
+ def send_input(input)
24
+ case input
25
+ when "h"
26
+ update_cursor(column: cursor_column - 1)
27
+ when "j"
28
+ update_cursor(row: cursor_row + 1)
29
+ when "k"
30
+ update_cursor(row: cursor_row - 1)
31
+ when "l"
32
+ update_cursor(column: cursor_column + 1)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :buffer
39
+
40
+ attr_accessor :cursor_row,
41
+ :cursor_column,
42
+ :row_offset
43
+
44
+ def width
45
+ pane.width
46
+ end
47
+
48
+ def height
49
+ pane.height
50
+ end
51
+
52
+ def update_cursor(row: cursor_row, column: cursor_column)
53
+ row = [0, row].max
54
+ row = [row, buffer.lines.length - 1].min
55
+ @cursor_row = row
56
+
57
+ column = [0, column].max
58
+ column = [column, current_line.raw_text.length - 1].min
59
+ @cursor_column = column
60
+
61
+ if row < row_offset
62
+ self.row_offset = row
63
+ end
64
+
65
+ # FIXME: Can probably do this more efficiently.
66
+ # FIXME: This only fits the first row worth of the current line on the
67
+ # screen. The desired behaviour is that all the rows of the current line
68
+ # are fit on in this scenario.
69
+ while screen_cursor_row >= height
70
+ self.row_offset = row_offset + 1
71
+ end
72
+ end
73
+
74
+ def current_line
75
+ buffer.lines[cursor_row]
76
+ end
77
+
78
+ def screen_cursor_column
79
+ if cursor_column < width
80
+ cursor_column
81
+ else
82
+ cursor_column % width
83
+ end
84
+ end
85
+
86
+ def screen_cursor_row
87
+ buffer.lines.slice(row_offset, buffer.lines.length - 1).reduce(0) do |acc, line|
88
+ if line == current_line
89
+ if cursor_column < width
90
+ break acc
91
+ else
92
+ break acc + cursor_column / width
93
+ end
94
+ else
95
+ acc + line.wrap(width: width).length
96
+ end
97
+ end
98
+ end
99
+
100
+ def screen_lines
101
+ buffer.wrapped_lines(
102
+ offset: row_offset,
103
+ width: width,
104
+ height: height
105
+ )
106
+ end
107
+ end
108
+ end
data/lib/jared/pane.rb CHANGED
@@ -1,21 +1,49 @@
1
1
  module JarEd
2
2
  class Pane
3
- attr_accessor :buffer
4
-
5
3
  def refresh(window)
6
- window.setpos(0, 0)
7
- draw_lines(window)
8
- window.setpos(buffer.cursor_row, buffer.cursor_column)
4
+ screen = view.to_screen
5
+ validate!(screen)
6
+ window.clear
7
+ draw_screen(window, screen)
8
+ window.setpos(screen.cursor_row, screen.cursor_column)
9
9
  window.noutrefresh
10
10
  end
11
11
 
12
+ def send_input(char)
13
+ view.send_input(char)
14
+ end
15
+
16
+ def view=(view)
17
+ view.pane = self
18
+ @view = view
19
+ end
20
+
21
+ def width
22
+ Curses.cols
23
+ end
24
+
25
+ def height
26
+ Curses.lines
27
+ end
28
+
12
29
  private
13
30
 
14
- def draw_lines(window)
15
- buffer.lines.each do |line|
16
- # line_height = line.scan(/.{1,#{Curses.cols}}/)
31
+ attr_reader :view
32
+
33
+ def draw_screen(window, screen)
34
+ screen.lines.each_with_index do |line, index|
35
+ window.setpos index, 0
17
36
  window.addstr line
18
37
  end
19
38
  end
39
+
40
+ # @todo Validate that the screen fits in the pane.
41
+ def validate!(screen)
42
+ screen.cursor_column >= 0 &&
43
+ screen.cursor_row >= 0 &&
44
+ screen.cursor_column < width &&
45
+ screen.cursor_row < height ||
46
+ raise("Invalid screen.")
47
+ end
20
48
  end
21
49
  end
@@ -0,0 +1,20 @@
1
+ module JarEd
2
+ class Screen
3
+ attr_reader :lines, :cursor_column, :cursor_row
4
+
5
+ # @todo Rename these to cursor_row/column
6
+ def initialize(lines:, cursor_column:, cursor_row:)
7
+ @lines = lines
8
+ @cursor_column = cursor_column
9
+ @cursor_row = cursor_row
10
+ end
11
+
12
+ def width
13
+ lines.map(&:length).max
14
+ end
15
+
16
+ def height
17
+ lines.length
18
+ end
19
+ end
20
+ end
data/lib/jared/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JarEd
2
- VERSION = "2.0.0"
2
+ VERSION = "3.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jareditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Norman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-20 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -117,6 +117,7 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - ".gitignore"
120
+ - ".rubocop.yml"
120
121
  - ".travis.yml"
121
122
  - CODE_OF_CONDUCT.md
122
123
  - Gemfile
@@ -128,7 +129,10 @@ files:
128
129
  - jareditor.gemspec
129
130
  - lib/jared.rb
130
131
  - lib/jared/buffer.rb
132
+ - lib/jared/buffer_line.rb
133
+ - lib/jared/file_view.rb
131
134
  - lib/jared/pane.rb
135
+ - lib/jared/screen.rb
132
136
  - lib/jared/version.rb
133
137
  homepage: https://github.com/jarednorman/jared
134
138
  licenses: []