ruco 0.0.51 → 0.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Readme.md +2 -0
- data/VERSION +1 -1
- data/lib/ruco.rb +3 -1
- data/lib/ruco/application.rb +1 -1
- data/lib/ruco/editor/history.rb +25 -0
- data/lib/ruco/editor/line_numbers.rb +50 -0
- data/lib/ruco/editor_area.rb +2 -19
- data/lib/ruco/text_area.rb +2 -2
- data/ruco.gemspec +4 -3
- data/spec/ruco/editor_spec.rb +79 -50
- data/spec/ruco/file_store_spec.rb +6 -1
- data/spec/ruco/text_area_spec.rb +9 -9
- metadata +12 -7
data/Readme.md
CHANGED
@@ -17,6 +17,7 @@ Features:
|
|
17
17
|
- keeps whatever newline format you use (\r \n \r\n)
|
18
18
|
- (optional) remove trailing whitespace on save
|
19
19
|
- (optional) blank line before eof on save
|
20
|
+
- (optional) line numbers
|
20
21
|
|
21
22
|
Install
|
22
23
|
=======
|
@@ -36,6 +37,7 @@ Customize
|
|
36
37
|
options.history_entries = 10 # default 100
|
37
38
|
options.editor_remove_trailing_whitespace_on_save = true # default false
|
38
39
|
options.editor_blank_line_before_eof_on_save = true # default false
|
40
|
+
options.editor_line_numbers = true # default false
|
39
41
|
...
|
40
42
|
|
41
43
|
# bind a key
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.52
|
data/lib/ruco.rb
CHANGED
@@ -16,6 +16,8 @@ require 'ruco/window'
|
|
16
16
|
require 'ruco/style_map'
|
17
17
|
|
18
18
|
require 'ruco/editor'
|
19
|
+
require 'ruco/editor/line_numbers'
|
20
|
+
require 'ruco/editor/history'
|
19
21
|
require 'ruco/status_bar'
|
20
22
|
require 'ruco/command_bar'
|
21
23
|
require 'ruco/application'
|
@@ -37,4 +39,4 @@ module Ruco
|
|
37
39
|
def self.configure(&block)
|
38
40
|
application.instance_exec(&block)
|
39
41
|
end
|
40
|
-
end
|
42
|
+
end
|
data/lib/ruco/application.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Ruco
|
2
|
+
class Editor
|
3
|
+
module History
|
4
|
+
def initialize(content, options)
|
5
|
+
super(content, options)
|
6
|
+
@history = Ruco::History.new((options[:history]||{}).reverse_merge(:state => state, :track => [:content], :entries => 100, :timeout => 2))
|
7
|
+
end
|
8
|
+
|
9
|
+
def undo
|
10
|
+
@history.undo
|
11
|
+
self.state = @history.state
|
12
|
+
end
|
13
|
+
|
14
|
+
def redo
|
15
|
+
@history.redo
|
16
|
+
self.state = @history.state
|
17
|
+
end
|
18
|
+
|
19
|
+
def view
|
20
|
+
@history.add(state)
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Ruco
|
2
|
+
class Editor
|
3
|
+
module LineNumbers
|
4
|
+
LINE_NUMBERS_SPACE = 5
|
5
|
+
|
6
|
+
def initialize(content, options)
|
7
|
+
options[:columns] -= LINE_NUMBERS_SPACE if options[:line_numbers]
|
8
|
+
super(content, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def view
|
12
|
+
if @options[:line_numbers]
|
13
|
+
number_room = LINE_NUMBERS_SPACE - 1
|
14
|
+
|
15
|
+
super.naive_split("\n").map_with_index do |line,i|
|
16
|
+
number = @window.top + i
|
17
|
+
number = if lines[number]
|
18
|
+
(number + 1).to_s
|
19
|
+
else
|
20
|
+
''
|
21
|
+
end.rjust(number_room).slice(0,number_room)
|
22
|
+
"#{number} #{line}"
|
23
|
+
end * "\n"
|
24
|
+
else
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def style_map
|
30
|
+
if @options[:line_numbers]
|
31
|
+
map = super
|
32
|
+
map.left_pad!(LINE_NUMBERS_SPACE)
|
33
|
+
map
|
34
|
+
else
|
35
|
+
super
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def cursor
|
40
|
+
if @options[:line_numbers]
|
41
|
+
cursor = super
|
42
|
+
cursor[1] += LINE_NUMBERS_SPACE
|
43
|
+
cursor
|
44
|
+
else
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/ruco/editor_area.rb
CHANGED
@@ -2,25 +2,8 @@ module Ruco
|
|
2
2
|
# everything that does not belong to a text-area
|
3
3
|
# but is needed for Ruco::Editor
|
4
4
|
class EditorArea < TextArea
|
5
|
-
|
6
|
-
|
7
|
-
@history = History.new((args.last[:history]||{}).reverse_merge(:state => state, :track => [:content], :entries => 100, :timeout => 2))
|
8
|
-
end
|
9
|
-
|
10
|
-
def undo
|
11
|
-
@history.undo
|
12
|
-
self.state = @history.state
|
13
|
-
end
|
14
|
-
|
15
|
-
def redo
|
16
|
-
@history.redo
|
17
|
-
self.state = @history.state
|
18
|
-
end
|
19
|
-
|
20
|
-
def view
|
21
|
-
@history.add(state)
|
22
|
-
super
|
23
|
-
end
|
5
|
+
include Ruco::Editor::LineNumbers
|
6
|
+
include Ruco::Editor::History
|
24
7
|
|
25
8
|
def delete_line
|
26
9
|
lines.slice!(line, 1)
|
data/lib/ruco/text_area.rb
CHANGED
@@ -13,7 +13,7 @@ module Ruco
|
|
13
13
|
|
14
14
|
def view
|
15
15
|
adjust_window
|
16
|
-
@window.crop(lines) * "\n"
|
16
|
+
@window.crop(lines) * "\n"
|
17
17
|
end
|
18
18
|
|
19
19
|
def cursor
|
@@ -247,4 +247,4 @@ module Ruco
|
|
247
247
|
@window.set_position(position, :max_lines => @lines.size)
|
248
248
|
end
|
249
249
|
end
|
250
|
-
end
|
250
|
+
end
|
data/ruco.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruco}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.52"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Grosser"]
|
@@ -30,6 +30,8 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/ruco/core_ext/range.rb",
|
31
31
|
"lib/ruco/core_ext/string.rb",
|
32
32
|
"lib/ruco/editor.rb",
|
33
|
+
"lib/ruco/editor/history.rb",
|
34
|
+
"lib/ruco/editor/line_numbers.rb",
|
33
35
|
"lib/ruco/editor_area.rb",
|
34
36
|
"lib/ruco/file_store.rb",
|
35
37
|
"lib/ruco/form.rb",
|
@@ -63,7 +65,7 @@ Gem::Specification.new do |s|
|
|
63
65
|
]
|
64
66
|
s.homepage = %q{http://github.com/grosser/ruco}
|
65
67
|
s.require_paths = ["lib"]
|
66
|
-
s.rubygems_version = %q{1.
|
68
|
+
s.rubygems_version = %q{1.4.2}
|
67
69
|
s.summary = %q{Commandline editor written in ruby}
|
68
70
|
s.test_files = [
|
69
71
|
"spec/ruco/application_spec.rb",
|
@@ -85,7 +87,6 @@ Gem::Specification.new do |s|
|
|
85
87
|
]
|
86
88
|
|
87
89
|
if s.respond_to? :specification_version then
|
88
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
89
90
|
s.specification_version = 3
|
90
91
|
|
91
92
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/spec/ruco/editor_spec.rb
CHANGED
@@ -31,12 +31,12 @@ describe Ruco::Editor do
|
|
31
31
|
describe "strange newline formats" do
|
32
32
|
it 'views \r normally' do
|
33
33
|
write("a\rb\rc\r")
|
34
|
-
editor.view.should == "a\nb\nc
|
34
|
+
editor.view.should == "a\nb\nc"
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'views \r\n normally' do
|
38
38
|
write("a\r\nb\r\nc\r\n")
|
39
|
-
editor.view.should == "a\nb\nc
|
39
|
+
editor.view.should == "a\nb\nc"
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'saves \r as \r' do
|
@@ -129,12 +129,12 @@ describe Ruco::Editor do
|
|
129
129
|
|
130
130
|
it "reads tab as spaces when option is set" do
|
131
131
|
editor = Ruco::Editor.new(@file, :lines => 3, :columns => 5, :convert_tabs => true)
|
132
|
-
editor.view.should == " a\n\n
|
132
|
+
editor.view.should == " a\n\n"
|
133
133
|
end
|
134
134
|
|
135
135
|
it "reads them normally when option is not set" do
|
136
136
|
editor = Ruco::Editor.new(@file, :lines => 3, :columns => 5)
|
137
|
-
editor.view.should == "\t\ta\n\n
|
137
|
+
editor.view.should == "\t\ta\n\n"
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
@@ -197,11 +197,11 @@ describe Ruco::Editor do
|
|
197
197
|
it "can scroll columns" do
|
198
198
|
write("123456789\n123")
|
199
199
|
editor.move(:relative, 0,4)
|
200
|
-
editor.view.should == "12345\n123\n
|
200
|
+
editor.view.should == "12345\n123\n"
|
201
201
|
editor.cursor.column.should == 4
|
202
202
|
|
203
203
|
editor.move(:relative, 0,1)
|
204
|
-
editor.view.should == "34567\n3\n
|
204
|
+
editor.view.should == "34567\n3\n"
|
205
205
|
editor.cursor.column.should == 3
|
206
206
|
end
|
207
207
|
|
@@ -209,17 +209,17 @@ describe Ruco::Editor do
|
|
209
209
|
write('123456789')
|
210
210
|
editor.move(:relative, 0,4)
|
211
211
|
6.times{ editor.move(:relative, 0,1) }
|
212
|
-
editor.view.should == "789\n\n
|
212
|
+
editor.view.should == "789\n\n"
|
213
213
|
editor.cursor.column.should == 3
|
214
214
|
end
|
215
215
|
|
216
216
|
it "can scroll columns backwards" do
|
217
217
|
write('0123456789')
|
218
218
|
editor.move(:relative, 0,5)
|
219
|
-
editor.view.should == "23456\n\n
|
219
|
+
editor.view.should == "23456\n\n"
|
220
220
|
|
221
221
|
editor.move(:relative, 0,-4)
|
222
|
-
editor.view.should == "01234\n\n
|
222
|
+
editor.view.should == "01234\n\n"
|
223
223
|
editor.cursor.column.should == 1
|
224
224
|
end
|
225
225
|
end
|
@@ -231,16 +231,16 @@ describe Ruco::Editor do
|
|
231
231
|
|
232
232
|
it "can scroll lines down" do
|
233
233
|
editor.move(:relative, 2,0)
|
234
|
-
editor.view.should == "1\n2\n3
|
234
|
+
editor.view.should == "1\n2\n3"
|
235
235
|
|
236
236
|
editor.move(:relative, 1,0)
|
237
|
-
editor.view.should == "3\n4\n5
|
237
|
+
editor.view.should == "3\n4\n5"
|
238
238
|
editor.cursor.line.should == 1
|
239
239
|
end
|
240
240
|
|
241
241
|
it "can scroll till end of file" do
|
242
242
|
editor.move(:relative, 15,0)
|
243
|
-
editor.view.should == "8\n9\n
|
243
|
+
editor.view.should == "8\n9\n"
|
244
244
|
editor.cursor.line.should == 1
|
245
245
|
end
|
246
246
|
end
|
@@ -330,7 +330,7 @@ describe Ruco::Editor do
|
|
330
330
|
|
331
331
|
it "moves the line" do
|
332
332
|
editor.move_line(1)
|
333
|
-
editor.view.should == "1\n0\n2
|
333
|
+
editor.view.should == "1\n0\n2"
|
334
334
|
end
|
335
335
|
|
336
336
|
it "keeps the cursor at the moved line" do
|
@@ -347,12 +347,12 @@ describe Ruco::Editor do
|
|
347
347
|
it "uses indentation of moved-to-line" do
|
348
348
|
write(" 0\n 1\n 2\n")
|
349
349
|
editor.move_line(1)
|
350
|
-
editor.view.should == " 1\n 0\n 2
|
350
|
+
editor.view.should == " 1\n 0\n 2"
|
351
351
|
end
|
352
352
|
|
353
353
|
it "cannot move past start of file" do
|
354
354
|
editor.move_line(-1)
|
355
|
-
editor.view.should == "0\n1\n2
|
355
|
+
editor.view.should == "0\n1\n2"
|
356
356
|
end
|
357
357
|
|
358
358
|
it "cannot move past end of file" do
|
@@ -361,7 +361,7 @@ describe Ruco::Editor do
|
|
361
361
|
editor.move_line(1)
|
362
362
|
editor.move_line(1)
|
363
363
|
editor.move_line(1)
|
364
|
-
editor.view.should == "1\n\n0
|
364
|
+
editor.view.should == "1\n\n0"
|
365
365
|
end
|
366
366
|
end
|
367
367
|
|
@@ -434,7 +434,7 @@ describe Ruco::Editor do
|
|
434
434
|
editor.selection.should == nil
|
435
435
|
editor.cursor.should == [0,1]
|
436
436
|
editor.move(:to, 0,0)
|
437
|
-
editor.view.should == "X4567\n\n
|
437
|
+
editor.view.should == "X4567\n\n"
|
438
438
|
end
|
439
439
|
|
440
440
|
it "replaces the multi-line-selection with insert" do
|
@@ -447,7 +447,7 @@ describe Ruco::Editor do
|
|
447
447
|
editor.selection.should == nil
|
448
448
|
editor.cursor.should == [0,2]
|
449
449
|
editor.move(:to, 0,0)
|
450
|
-
editor.view.should == "1X6\n789\n
|
450
|
+
editor.view.should == "1X6\n789\n"
|
451
451
|
end
|
452
452
|
|
453
453
|
it "deletes selection delete" do
|
@@ -459,7 +459,7 @@ describe Ruco::Editor do
|
|
459
459
|
editor.delete(1)
|
460
460
|
editor.cursor.should == [0,1]
|
461
461
|
editor.move(:to, 0,0)
|
462
|
-
editor.view.should == "16\n789\n
|
462
|
+
editor.view.should == "16\n789\n"
|
463
463
|
end
|
464
464
|
end
|
465
465
|
|
@@ -544,7 +544,7 @@ describe Ruco::Editor do
|
|
544
544
|
editor.selecting do
|
545
545
|
move(:relative, 2, 1)
|
546
546
|
end
|
547
|
-
editor.view.should == "789\n789\n789
|
547
|
+
editor.view.should == "789\n789\n789"
|
548
548
|
editor.cursor.should == [2,2]
|
549
549
|
editor.style_map.flatten.should == [
|
550
550
|
[nil, :reverse, nil, nil, nil, nil, :normal], # start to end of screen
|
@@ -560,22 +560,22 @@ describe Ruco::Editor do
|
|
560
560
|
end
|
561
561
|
|
562
562
|
it "displays an empty screen" do
|
563
|
-
editor.view.should == "\n\n
|
563
|
+
editor.view.should == "\n\n"
|
564
564
|
end
|
565
565
|
|
566
566
|
it "displays short file content" do
|
567
567
|
write('xxx')
|
568
|
-
editor.view.should == "xxx\n\n
|
568
|
+
editor.view.should == "xxx\n\n"
|
569
569
|
end
|
570
570
|
|
571
571
|
it "displays long file content" do
|
572
572
|
write('1234567')
|
573
|
-
editor.view.should == "12345\n\n
|
573
|
+
editor.view.should == "12345\n\n"
|
574
574
|
end
|
575
575
|
|
576
576
|
it "displays multiline-file content" do
|
577
577
|
write("xxx\nyyy\nzzz\niii")
|
578
|
-
editor.view.should == "xxx\nyyy\nzzz
|
578
|
+
editor.view.should == "xxx\nyyy\nzzz"
|
579
579
|
end
|
580
580
|
end
|
581
581
|
|
@@ -588,13 +588,13 @@ describe Ruco::Editor do
|
|
588
588
|
write('123')
|
589
589
|
editor.move(:relative, 0,1)
|
590
590
|
editor.insert('ab')
|
591
|
-
editor.view.should == "1ab23\n\n
|
591
|
+
editor.view.should == "1ab23\n\n"
|
592
592
|
editor.cursor.should == [0,3]
|
593
593
|
end
|
594
594
|
|
595
595
|
it "can insert new newlines" do
|
596
596
|
editor.insert("ab\nc")
|
597
|
-
editor.view.should == "ab\nc\n
|
597
|
+
editor.view.should == "ab\nc\n"
|
598
598
|
editor.cursor.should == [1,1]
|
599
599
|
end
|
600
600
|
|
@@ -602,7 +602,7 @@ describe Ruco::Editor do
|
|
602
602
|
write("abc\ndefg")
|
603
603
|
editor.move(:relative, 1,2)
|
604
604
|
editor.insert("1\n23")
|
605
|
-
editor.view.should == "abc\nde1\n23fg
|
605
|
+
editor.view.should == "abc\nde1\n23fg"
|
606
606
|
editor.cursor.should == [2,2]
|
607
607
|
end
|
608
608
|
|
@@ -610,7 +610,7 @@ describe Ruco::Editor do
|
|
610
610
|
write("abc\ndefg")
|
611
611
|
editor.move(:relative, 1,2)
|
612
612
|
editor.insert("\n")
|
613
|
-
editor.view.should == "abc\nde\nfg
|
613
|
+
editor.view.should == "abc\nde\nfg"
|
614
614
|
editor.cursor.should == [2,0]
|
615
615
|
end
|
616
616
|
|
@@ -631,7 +631,7 @@ describe Ruco::Editor do
|
|
631
631
|
|
632
632
|
it "inserts tab as spaces" do
|
633
633
|
editor.insert("\t")
|
634
|
-
editor.view.should == " \n\n
|
634
|
+
editor.view.should == " \n\n"
|
635
635
|
editor.cursor.should == [0,2]
|
636
636
|
end
|
637
637
|
|
@@ -647,7 +647,7 @@ describe Ruco::Editor do
|
|
647
647
|
write("a\nb\nc\n")
|
648
648
|
editor.selecting{move(:to, 1,1)}
|
649
649
|
editor.indent
|
650
|
-
editor.view.should == " a\n b\nc
|
650
|
+
editor.view.should == " a\n b\nc"
|
651
651
|
end
|
652
652
|
|
653
653
|
it "moves the selection" do
|
@@ -683,19 +683,19 @@ describe Ruco::Editor do
|
|
683
683
|
it "unindents single lines" do
|
684
684
|
write(" a\n\n")
|
685
685
|
editor.unindent
|
686
|
-
editor.view.should == " a\n\n
|
686
|
+
editor.view.should == " a\n\n"
|
687
687
|
end
|
688
688
|
|
689
689
|
it "unindents single lines by one" do
|
690
690
|
write(" a\n\n")
|
691
691
|
editor.unindent
|
692
|
-
editor.view.should == "a\n\n
|
692
|
+
editor.view.should == "a\n\n"
|
693
693
|
end
|
694
694
|
|
695
695
|
it "does not unindents single lines when not unindentable" do
|
696
696
|
write("a\n\n")
|
697
697
|
editor.unindent
|
698
|
-
editor.view.should == "a\n\n
|
698
|
+
editor.view.should == "a\n\n"
|
699
699
|
end
|
700
700
|
|
701
701
|
it "move the cursor when unindenting single line" do
|
@@ -709,7 +709,7 @@ describe Ruco::Editor do
|
|
709
709
|
write("a\n b\n c")
|
710
710
|
editor.selecting{ move(:to, 2,1) }
|
711
711
|
editor.unindent
|
712
|
-
editor.view.should == "a\nb\n c
|
712
|
+
editor.view.should == "a\nb\n c"
|
713
713
|
end
|
714
714
|
|
715
715
|
it "moves the selection" do
|
@@ -762,7 +762,7 @@ describe Ruco::Editor do
|
|
762
762
|
editor.insert("c")
|
763
763
|
editor.view # trigger save point
|
764
764
|
editor.undo
|
765
|
-
editor.view.should == "ba\n\n
|
765
|
+
editor.view.should == "ba\n\n"
|
766
766
|
editor.cursor.should == [0,1]
|
767
767
|
end
|
768
768
|
|
@@ -815,7 +815,7 @@ describe Ruco::Editor do
|
|
815
815
|
editor.move(:to, 0,2)
|
816
816
|
editor.instance_eval{@options[:remove_trailing_whitespace_on_save] = true}
|
817
817
|
editor.save
|
818
|
-
editor.view.should == "a\n\nb
|
818
|
+
editor.view.should == "a\n\nb"
|
819
819
|
editor.cursor.should == [0,1]
|
820
820
|
end
|
821
821
|
|
@@ -824,14 +824,14 @@ describe Ruco::Editor do
|
|
824
824
|
editor.move(:to, 2,0)
|
825
825
|
editor.instance_eval{@options[:remove_trailing_whitespace_on_save] = true}
|
826
826
|
editor.save
|
827
|
-
editor.view.should == "\n\n
|
827
|
+
editor.view.should == "\n\n"
|
828
828
|
editor.cursor.should == [2,0]
|
829
829
|
end
|
830
830
|
|
831
831
|
it "does not remove trailing whitespace by default" do
|
832
832
|
write("a \n \nb\n\n")
|
833
833
|
editor.save
|
834
|
-
editor.view.should == "a \n \nb
|
834
|
+
editor.view.should == "a \n \nb"
|
835
835
|
editor.cursor.should == [0,0]
|
836
836
|
end
|
837
837
|
end
|
@@ -841,7 +841,7 @@ describe Ruco::Editor do
|
|
841
841
|
it 'removes a char' do
|
842
842
|
write('123')
|
843
843
|
editor.delete(1)
|
844
|
-
editor.view.should == "23\n\n
|
844
|
+
editor.view.should == "23\n\n"
|
845
845
|
editor.cursor.should == [0,0]
|
846
846
|
end
|
847
847
|
|
@@ -849,7 +849,7 @@ describe Ruco::Editor do
|
|
849
849
|
write("123\n45")
|
850
850
|
editor.move(:relative, 0,3)
|
851
851
|
editor.delete(1)
|
852
|
-
editor.view.should == "12345\n\n
|
852
|
+
editor.view.should == "12345\n\n"
|
853
853
|
editor.cursor.should == [0,3]
|
854
854
|
end
|
855
855
|
|
@@ -857,7 +857,7 @@ describe Ruco::Editor do
|
|
857
857
|
write("aa")
|
858
858
|
editor.move(:relative, 0,1)
|
859
859
|
editor.delete(-3)
|
860
|
-
editor.view.should == "a\n\n
|
860
|
+
editor.view.should == "a\n\n"
|
861
861
|
editor.cursor.should == [0,0]
|
862
862
|
end
|
863
863
|
|
@@ -865,7 +865,7 @@ describe Ruco::Editor do
|
|
865
865
|
write('123')
|
866
866
|
editor.move(:relative, 0,3)
|
867
867
|
editor.delete(-1)
|
868
|
-
editor.view.should == "12\n\n
|
868
|
+
editor.view.should == "12\n\n"
|
869
869
|
editor.cursor.should == [0,2]
|
870
870
|
end
|
871
871
|
|
@@ -873,7 +873,7 @@ describe Ruco::Editor do
|
|
873
873
|
write("1\n234")
|
874
874
|
editor.move(:relative, 1,0)
|
875
875
|
editor.delete(-1)
|
876
|
-
editor.view.should == "1234\n\n
|
876
|
+
editor.view.should == "1234\n\n"
|
877
877
|
editor.cursor.should == [0,1]
|
878
878
|
end
|
879
879
|
end
|
@@ -946,27 +946,27 @@ describe Ruco::Editor do
|
|
946
946
|
it "removes the current line from first char" do
|
947
947
|
editor.move(:to, 1, 0)
|
948
948
|
editor.delete_line
|
949
|
-
editor.view.should == "1\n56789\n
|
949
|
+
editor.view.should == "1\n56789\n"
|
950
950
|
editor.cursor.should == [1, 0]
|
951
951
|
end
|
952
952
|
|
953
953
|
it "removes the current line from last char" do
|
954
954
|
editor.move(:to, 1, 3)
|
955
955
|
editor.delete_line
|
956
|
-
editor.view.should == "1\n56789\n
|
956
|
+
editor.view.should == "1\n56789\n"
|
957
957
|
editor.cursor.should == [1, 3]
|
958
958
|
end
|
959
959
|
|
960
960
|
it "can remove the first line" do
|
961
961
|
editor.delete_line
|
962
|
-
editor.view.should == "longe\n56789\n
|
962
|
+
editor.view.should == "longe\n56789\n"
|
963
963
|
editor.cursor.should == [0, 0]
|
964
964
|
end
|
965
965
|
|
966
966
|
it "can remove the last line" do
|
967
967
|
write("aaa")
|
968
968
|
editor.delete_line
|
969
|
-
editor.view.should == "\n\n
|
969
|
+
editor.view.should == "\n\n"
|
970
970
|
editor.cursor.should == [0, 0]
|
971
971
|
end
|
972
972
|
|
@@ -974,7 +974,7 @@ describe Ruco::Editor do
|
|
974
974
|
write("aaa\nbbb")
|
975
975
|
editor.move(:to, 1,1)
|
976
976
|
editor.delete_line
|
977
|
-
editor.view.should == "aaa\n\n
|
977
|
+
editor.view.should == "aaa\n\n"
|
978
978
|
editor.cursor.should == [0, 1]
|
979
979
|
end
|
980
980
|
|
@@ -990,7 +990,7 @@ describe Ruco::Editor do
|
|
990
990
|
editor.move(:to, 5, 0)
|
991
991
|
editor.move(:to, 6, 1)
|
992
992
|
editor.delete_line
|
993
|
-
editor.view.should == "5\n7\n8
|
993
|
+
editor.view.should == "5\n7\n8"
|
994
994
|
editor.cursor.should == [1, 1]
|
995
995
|
end
|
996
996
|
|
@@ -998,7 +998,36 @@ describe Ruco::Editor do
|
|
998
998
|
write('xxx')
|
999
999
|
editor.delete_line
|
1000
1000
|
editor.insert('yyy')
|
1001
|
-
editor.view.should == "yyy\n\n
|
1001
|
+
editor.view.should == "yyy\n\n"
|
1002
|
+
end
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
describe 'with line_numbers' do
|
1006
|
+
let(:editor){ Ruco::Editor.new(@file, :lines => 5, :columns => 10, :line_numbers => true) }
|
1007
|
+
|
1008
|
+
before do
|
1009
|
+
write("0\n1\n2\n3\n4\n5\n6\n7\n")
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
it "adds numbers to view" do
|
1013
|
+
editor.view.should == " 1 0\n 2 1\n 3 2\n 4 3\n 5 4"
|
1014
|
+
end
|
1015
|
+
|
1016
|
+
it "does not show numbers for empty lines" do
|
1017
|
+
editor.move(:to, 10,0)
|
1018
|
+
editor.view.should == " 6 5\n 7 6\n 8 7\n 9 \n "
|
1019
|
+
end
|
1020
|
+
|
1021
|
+
it "adjusts the cursor" do
|
1022
|
+
editor.cursor.should == [0,5]
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
it "adjusts the style map" do
|
1026
|
+
editor.selecting{ move(:to, 0,1) }
|
1027
|
+
editor.style_map.flatten.should == [
|
1028
|
+
[nil, nil, nil, nil, nil, :reverse, nil, :normal],
|
1029
|
+
nil, nil, nil, nil
|
1030
|
+
]
|
1002
1031
|
end
|
1003
1032
|
end
|
1004
1033
|
end
|
@@ -27,10 +27,15 @@ describe Ruco::FileStore do
|
|
27
27
|
|
28
28
|
it "drops least recently used key" do
|
29
29
|
store.set('xxx', 1)
|
30
|
+
sleep(0.1)
|
30
31
|
store.set('yyy', 1)
|
32
|
+
sleep(0.1)
|
31
33
|
store.set('xxx', 1)
|
34
|
+
sleep(0.1)
|
32
35
|
store.set('zzz', 1)
|
36
|
+
sleep(0.1)
|
33
37
|
store.set('aaa', 1)
|
38
|
+
sleep(0.1)
|
34
39
|
store.get('xxx').should == 1
|
35
40
|
store.get('yyy').should == nil
|
36
41
|
end
|
@@ -44,4 +49,4 @@ describe Ruco::FileStore do
|
|
44
49
|
store.set('zzz', 1)
|
45
50
|
store.get('xxx').should == 1
|
46
51
|
end
|
47
|
-
end
|
52
|
+
end
|
data/spec/ruco/text_area_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Ruco::TextArea do
|
|
6
6
|
it "can move down a page" do
|
7
7
|
text = Ruco::TextArea.new("1\n2\n3\n4\n5\n6\n7\n8\n9\n", :lines => 3, :columns => 3)
|
8
8
|
text.move(:page_down)
|
9
|
-
text.view.should == "3\n4\n5
|
9
|
+
text.view.should == "3\n4\n5"
|
10
10
|
text.cursor.should == [1,0]
|
11
11
|
end
|
12
12
|
|
@@ -14,34 +14,34 @@ describe Ruco::TextArea do
|
|
14
14
|
text = Ruco::TextArea.new("1\n2abc\n3\n4\n5ab\n6\n7\n8\n9\n", :lines => 3, :columns => 5)
|
15
15
|
text.move(:to, 1,4)
|
16
16
|
text.move(:page_down)
|
17
|
-
text.view.should == "4\n5ab\n6
|
17
|
+
text.view.should == "4\n5ab\n6"
|
18
18
|
text.cursor.should == [1,3]
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can move up a page" do
|
22
22
|
text = Ruco::TextArea.new("0\n1\n2\n3\n4\n5\n6\n7\n8\n", :lines => 3, :columns => 3)
|
23
23
|
text.move(:to, 4, 0)
|
24
|
-
text.view.should == "3\n4\n5
|
24
|
+
text.view.should == "3\n4\n5"
|
25
25
|
text.cursor.should == [1,0]
|
26
26
|
text.move(:page_up)
|
27
|
-
text.view.should == "0\n1\n2
|
27
|
+
text.view.should == "0\n1\n2"
|
28
28
|
text.cursor.should == [1,0]
|
29
29
|
end
|
30
30
|
|
31
31
|
it "keeps column position when moving up" do
|
32
32
|
text = Ruco::TextArea.new("0\n1\n2ab\n3\n4\n5abc\n6\n7\n8\n9\n10\n11\n", :lines => 3, :columns => 5)
|
33
33
|
text.move(:to, 5, 3)
|
34
|
-
text.view.should == "4\n5abc\n6
|
34
|
+
text.view.should == "4\n5abc\n6"
|
35
35
|
text.cursor.should == [1,3]
|
36
36
|
text.move(:page_up)
|
37
|
-
text.view.should == "1\n2ab\n3
|
37
|
+
text.view.should == "1\n2ab\n3"
|
38
38
|
text.cursor.should == [1,3]
|
39
39
|
end
|
40
40
|
|
41
41
|
it "moves pages symetric" do
|
42
42
|
text = Ruco::TextArea.new("0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n", :lines => 3, :columns => 3)
|
43
43
|
text.move(:to, 4, 1)
|
44
|
-
text.view.should == "3\n4\n5
|
44
|
+
text.view.should == "3\n4\n5"
|
45
45
|
text.cursor.should == [1,1]
|
46
46
|
|
47
47
|
text.move(:page_down)
|
@@ -50,8 +50,8 @@ describe Ruco::TextArea do
|
|
50
50
|
text.move(:page_up)
|
51
51
|
|
52
52
|
text.cursor.should == [1,1]
|
53
|
-
text.view.should == "3\n4\n5
|
53
|
+
text.view.should == "3\n4\n5"
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 119
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 52
|
10
|
+
version: 0.0.52
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Michael Grosser
|
@@ -18,20 +19,21 @@ date: 2011-02-24 00:00:00 +01:00
|
|
18
19
|
default_executable: ruco
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
|
-
name: clipboard
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
23
|
none: false
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
+
hash: 51
|
27
28
|
segments:
|
28
29
|
- 0
|
29
30
|
- 9
|
30
31
|
- 4
|
31
32
|
version: 0.9.4
|
32
|
-
type: :runtime
|
33
33
|
prerelease: false
|
34
34
|
version_requirements: *id001
|
35
|
+
type: :runtime
|
36
|
+
name: clipboard
|
35
37
|
description:
|
36
38
|
email: michael@grosser.it
|
37
39
|
executables:
|
@@ -57,6 +59,8 @@ files:
|
|
57
59
|
- lib/ruco/core_ext/range.rb
|
58
60
|
- lib/ruco/core_ext/string.rb
|
59
61
|
- lib/ruco/editor.rb
|
62
|
+
- lib/ruco/editor/history.rb
|
63
|
+
- lib/ruco/editor/line_numbers.rb
|
60
64
|
- lib/ruco/editor_area.rb
|
61
65
|
- lib/ruco/file_store.rb
|
62
66
|
- lib/ruco/form.rb
|
@@ -101,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
105
|
requirements:
|
102
106
|
- - ">="
|
103
107
|
- !ruby/object:Gem::Version
|
104
|
-
hash:
|
108
|
+
hash: 3
|
105
109
|
segments:
|
106
110
|
- 0
|
107
111
|
version: "0"
|
@@ -110,13 +114,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
114
|
requirements:
|
111
115
|
- - ">="
|
112
116
|
- !ruby/object:Gem::Version
|
117
|
+
hash: 3
|
113
118
|
segments:
|
114
119
|
- 0
|
115
120
|
version: "0"
|
116
121
|
requirements: []
|
117
122
|
|
118
123
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.
|
124
|
+
rubygems_version: 1.4.2
|
120
125
|
signing_key:
|
121
126
|
specification_version: 3
|
122
127
|
summary: Commandline editor written in ruby
|