ruco 0.2.0.beta → 0.2.0.beta2

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.
@@ -1,6 +1,6 @@
1
1
  module Ruco
2
2
  class StyleMap
3
- attr_accessor :lines, :foreground, :background
3
+ attr_accessor :lines
4
4
 
5
5
  def initialize(lines)
6
6
  @lines = Array.new(lines)
@@ -20,7 +20,7 @@ module Ruco
20
20
  @lines.map do |styles|
21
21
  next unless styles
22
22
 
23
- # change to style at start and recalculate one after the end
23
+ # change to style at start and revert to normal one after the end
24
24
  points_of_change = styles.map{|s,c| [c.first, c.last_element+1] }.flatten.uniq
25
25
 
26
26
  flat = []
@@ -50,15 +50,9 @@ module Ruco
50
50
  end
51
51
 
52
52
  def style_map(selection)
53
- map = StyleMap.new(lines)
54
- if selection
55
- add_selection_styles(map, selection)
56
- else
57
- map
58
- end
59
- end
53
+ mask = StyleMap.new(lines)
54
+ return mask unless selection
60
55
 
61
- def add_selection_styles(map, selection)
62
56
  lines.times do |line|
63
57
  visible = visible_area(line)
64
58
  next unless selection.overlap?(visible)
@@ -68,9 +62,10 @@ module Ruco
68
62
  last = [selection.last, visible.last].min
69
63
  last = last[1] - left
70
64
 
71
- map.add(:reverse, line, first...last)
65
+ mask.add(:reverse, line, first...last)
72
66
  end
73
- map
67
+
68
+ mask
74
69
  end
75
70
 
76
71
  def left=(x)
@@ -82,14 +77,6 @@ module Ruco
82
77
  @top = [[line, max_top].min, 0].max
83
78
  end
84
79
 
85
- def visible_lines
86
- @top..(@top+@lines-1)
87
- end
88
-
89
- def visible_columns
90
- @left..(@left+@columns-1)
91
- end
92
-
93
80
  private
94
81
 
95
82
  def adjustment(current, allowed, threshold, offset)
@@ -108,5 +95,13 @@ module Ruco
108
95
  end_of_line = [line, last_visible_column]
109
96
  start_of_line..end_of_line
110
97
  end
98
+
99
+ def visible_lines
100
+ @top..(@top+@lines-1)
101
+ end
102
+
103
+ def visible_columns
104
+ @left..(@left+@columns-1)
105
+ end
111
106
  end
112
- end
107
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruco}
8
- s.version = "0.2.0.beta"
8
+ s.version = "0.2.0.beta2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2011-09-23}
12
+ s.date = %q{2011-09-24}
13
13
  s.default_executable = %q{ruco}
14
14
  s.email = %q{michael@grosser.it}
15
15
  s.executables = ["ruco"]
@@ -22,7 +22,6 @@ Gem::Specification.new do |s|
22
22
  "bin/ruco",
23
23
  "lib/ruco.rb",
24
24
  "lib/ruco/application.rb",
25
- "lib/ruco/array_processor.rb",
26
25
  "lib/ruco/command_bar.rb",
27
26
  "lib/ruco/core_ext/array.rb",
28
27
  "lib/ruco/core_ext/file.rb",
@@ -31,7 +30,6 @@ Gem::Specification.new do |s|
31
30
  "lib/ruco/core_ext/range.rb",
32
31
  "lib/ruco/core_ext/string.rb",
33
32
  "lib/ruco/editor.rb",
34
- "lib/ruco/editor/colors.rb",
35
33
  "lib/ruco/editor/history.rb",
36
34
  "lib/ruco/editor/line_numbers.rb",
37
35
  "lib/ruco/editor_area.rb",
@@ -44,19 +42,12 @@ Gem::Specification.new do |s|
44
42
  "lib/ruco/screen.rb",
45
43
  "lib/ruco/status_bar.rb",
46
44
  "lib/ruco/style_map.rb",
47
- "lib/ruco/syntax_parser.rb",
48
45
  "lib/ruco/text_area.rb",
49
46
  "lib/ruco/text_field.rb",
50
- "lib/ruco/tm_theme.rb",
51
47
  "lib/ruco/version.rb",
52
48
  "lib/ruco/window.rb",
53
- "playground/benchmark_syntax_parser.rb",
54
49
  "ruco.gemspec",
55
- "spec/fixtures/railscasts.tmTheme",
56
- "spec/fixtures/slow.js",
57
- "spec/fixtures/test.tmTheme",
58
50
  "spec/ruco/application_spec.rb",
59
- "spec/ruco/array_processor_spec.rb",
60
51
  "spec/ruco/command_bar_spec.rb",
61
52
  "spec/ruco/core_ext/array_spec.rb",
62
53
  "spec/ruco/core_ext/range_spec.rb",
@@ -70,9 +61,7 @@ Gem::Specification.new do |s|
70
61
  "spec/ruco/screen_spec.rb",
71
62
  "spec/ruco/status_bar_spec.rb",
72
63
  "spec/ruco/style_map_spec.rb",
73
- "spec/ruco/syntax_parser_spec.rb",
74
64
  "spec/ruco/text_area_spec.rb",
75
- "spec/ruco/tm_theme_spec.rb",
76
65
  "spec/ruco/window_spec.rb",
77
66
  "spec/ruco_spec.rb",
78
67
  "spec/spec_helper.rb"
@@ -86,6 +75,26 @@ Gem::Specification.new do |s|
86
75
  s.require_paths = ["lib"]
87
76
  s.rubygems_version = %q{1.6.2}
88
77
  s.summary = %q{Commandline editor written in ruby}
78
+ s.test_files = [
79
+ "spec/ruco/application_spec.rb",
80
+ "spec/ruco/command_bar_spec.rb",
81
+ "spec/ruco/core_ext/array_spec.rb",
82
+ "spec/ruco/core_ext/range_spec.rb",
83
+ "spec/ruco/core_ext/string_spec.rb",
84
+ "spec/ruco/editor_spec.rb",
85
+ "spec/ruco/file_store_spec.rb",
86
+ "spec/ruco/form_spec.rb",
87
+ "spec/ruco/history_spec.rb",
88
+ "spec/ruco/keyboard_spec.rb",
89
+ "spec/ruco/option_accessor_spec.rb",
90
+ "spec/ruco/screen_spec.rb",
91
+ "spec/ruco/status_bar_spec.rb",
92
+ "spec/ruco/style_map_spec.rb",
93
+ "spec/ruco/text_area_spec.rb",
94
+ "spec/ruco/window_spec.rb",
95
+ "spec/ruco_spec.rb",
96
+ "spec/spec_helper.rb"
97
+ ]
89
98
 
90
99
  if s.respond_to? :specification_version then
91
100
  s.specification_version = 3
@@ -10,28 +10,4 @@ describe Range do
10
10
  (1...3).last_element.should == 2
11
11
  end
12
12
  end
13
-
14
- describe :move do
15
- it "does not modify the original" do
16
- a = 1..3
17
- a.move(3)
18
- a.should == (1..3)
19
- end
20
-
21
- it "can move 0" do
22
- (1..3).move(0).should == (1..3)
23
- end
24
-
25
- it "can move right" do
26
- (1..3).move(1).should == (2..4)
27
- end
28
-
29
- it "can move left" do
30
- (1..3).move(-2).should == (-1..1)
31
- end
32
-
33
- it "can move exclusive ranges" do
34
- (1...3).move(2).should == (3...5)
35
- end
36
- end
37
13
  end
@@ -9,17 +9,8 @@ describe Ruco::Editor do
9
9
  File.binary_read(@file)
10
10
  end
11
11
 
12
- def color(c)
13
- {
14
- :string => ["#718C00", nil],
15
- :keyword => ["#8959A8", nil],
16
- :instance_variable => ["#C82829", nil],
17
- }[c]
18
- end
19
-
20
- let(:language){ LanguageSniffer::Language.new(:name => 'ruby', :lexer => 'ruby') }
21
12
  let(:editor){
22
- editor = Ruco::Editor.new(@file, :lines => 3, :columns => 5, :language => language)
13
+ editor = Ruco::Editor.new(@file, :lines => 3, :columns => 5)
23
14
  # only scroll when we reach end of lines/columns <-> able to test with smaller area
24
15
  editor.send(:text_area).instance_eval{
25
16
  @window.instance_eval{
@@ -35,7 +26,6 @@ describe Ruco::Editor do
35
26
  before do
36
27
  `rm -rf ~/.ruco/sessions`
37
28
  @file = 'spec/temp.txt'
38
- write('')
39
29
  end
40
30
 
41
31
  describe "strange newline formats" do
@@ -580,7 +570,7 @@ describe Ruco::Editor do
580
570
  end
581
571
 
582
572
  it "shows one-line selection" do
583
- write('abcdefghi')
573
+ write('12345678')
584
574
  editor.selecting do
585
575
  move(:to, 0, 4)
586
576
  end
@@ -592,7 +582,7 @@ describe Ruco::Editor do
592
582
  end
593
583
 
594
584
  it "shows multi-line selection" do
595
- write("abc\nabc\nabc")
585
+ write("012\n345\n678")
596
586
  editor.move(:to, 0,1)
597
587
  editor.selecting do
598
588
  move(:to, 1, 1)
@@ -605,7 +595,7 @@ describe Ruco::Editor do
605
595
  end
606
596
 
607
597
  it "shows the selection from offset" do
608
- write('abcdefghi')
598
+ write('12345678')
609
599
  editor.move(:to, 0, 2)
610
600
  editor.selecting do
611
601
  move(:to, 0, 4)
@@ -618,7 +608,7 @@ describe Ruco::Editor do
618
608
  end
619
609
 
620
610
  it "shows the selection in nth line" do
621
- write("\nabcdefghi")
611
+ write("\n12345678")
622
612
  editor.move(:to, 1, 2)
623
613
  editor.selecting do
624
614
  move(:to, 1, 4)
@@ -646,112 +636,6 @@ describe Ruco::Editor do
646
636
  [:reverse, nil, :normal] # 0 to end of selection
647
637
  ]
648
638
  end
649
-
650
- it "shows keywords" do
651
- write("class")
652
- editor.style_map.flatten.should == [
653
- [color(:keyword), nil, nil, nil, nil, :normal],
654
- nil,
655
- nil
656
- ]
657
- end
658
-
659
- it "shows keywords for moved window" do
660
- write("\n\n\n\n\n if ")
661
- editor.move(:to, 5, 6)
662
- editor.cursor.should == [1,3]
663
- editor.view.should == "\n if \n"
664
- editor.style_map.flatten.should == [
665
- nil,
666
- [nil, nil, color(:keyword), nil, :normal],
667
- nil
668
- ]
669
- end
670
-
671
- it "shows multiple syntax elements" do
672
- write("if @x")
673
- editor.style_map.flatten.should == [
674
- [color(:keyword), nil, :normal, color(:instance_variable), nil, :normal],
675
- nil,
676
- nil
677
- ]
678
- end
679
-
680
- it "does not show keywords inside strings" do
681
- write("'Foo'")
682
- editor.style_map.flatten.should == [
683
- [color(:string), nil, nil, nil, nil, :normal],
684
- nil,
685
- nil
686
- ]
687
- end
688
-
689
- xit "shows multiline comments" do
690
- write("=begin\na\nb\n=end")
691
- editor.move(:to, 3,0)
692
- editor.view.should == "b\n=end\n"
693
- editor.style_map.flatten.should == [
694
- [["#8E908C", nil], nil, :normal],
695
- [["#8E908C", nil], nil, nil, nil, :normal],
696
- nil
697
- ]
698
- end
699
-
700
- it "shows selection on top" do
701
- write("class")
702
- editor.selecting do
703
- move(:relative, 0, 3)
704
- end
705
- editor.style_map.flatten.should == [
706
- [:reverse, nil, nil, ["#8959A8", nil], nil, :normal],
707
- nil,
708
- nil
709
- ]
710
- end
711
-
712
- it "times out when styling takes too long" do
713
- begin
714
- STDERR.should_receive(:puts)
715
- old = Ruco::Editor::Colors::STYLING_TIMEOUT
716
- silence_warnings{ Ruco::Editor::Colors::STYLING_TIMEOUT = 0.001 }
717
- write(File.read('lib/ruco.rb'))
718
- editor.style_map.flatten.should == [nil,nil,nil]
719
- ensure
720
- silence_warnings{ Ruco::Editor::Colors::STYLING_TIMEOUT = old }
721
- end
722
- end
723
-
724
- describe 'with theme' do
725
- before do
726
- write("class")
727
- `rm -rf ~/.ruco/themes`
728
- end
729
-
730
- it "can download a theme" do
731
- editor = Ruco::Editor.new(@file,
732
- :lines => 3, :columns => 5, :language => language,
733
- :color_theme => 'https://raw.github.com/ChrisKempson/Tomorrow-Theme/master/TextMate/Tomorrow-Night-Bright.tmTheme'
734
- )
735
- editor.style_map.flatten.should == [
736
- [["#C397D8", nil], nil, nil, nil, nil, :normal],
737
- nil,
738
- nil
739
- ]
740
- end
741
-
742
- it "does not fail with invalid theme url" do
743
- STDERR.should_receive(:puts)
744
- editor = Ruco::Editor.new(@file,
745
- :lines => 3, :columns => 5, :language => language,
746
- :color_theme => 'foooooo'
747
- )
748
- editor.style_map.flatten.should == [
749
- [["#8959A8", nil], nil, nil, nil, nil, :normal],
750
- nil,
751
- nil
752
- ]
753
- end
754
- end
755
639
  end
756
640
 
757
641
  describe :view do
@@ -961,17 +845,17 @@ describe Ruco::Editor do
961
845
  stack.length.should == 2
962
846
  stack[0][:state][:content].should == "a"
963
847
  stack[1][:state][:content].should == "ba"
964
-
848
+
965
849
  editor.undo
966
850
  editor.history.position.should == 0
967
-
851
+
968
852
  editor.insert("c")
969
853
  editor.view # trigger save point
970
854
  stack.length.should == 2
971
855
  stack[0][:state][:content].should == "a"
972
856
  stack[1][:state][:content].should == "ca"
973
857
  end
974
-
858
+
975
859
  it "can undo an action" do
976
860
  write("a")
977
861
  editor.insert("b")
@@ -1108,7 +992,6 @@ describe Ruco::Editor do
1108
992
  end
1109
993
 
1110
994
  it "is changed after delete" do
1111
- write("abc")
1112
995
  editor.delete(1)
1113
996
  editor.modified?.should == true
1114
997
  end
@@ -1125,7 +1008,6 @@ describe Ruco::Editor do
1125
1008
  end
1126
1009
 
1127
1010
  it "is changed after delete_line" do
1128
- write("\n\n\n")
1129
1011
  editor.delete_line
1130
1012
  editor.modified?.should == true
1131
1013
  end
@@ -1227,16 +1109,16 @@ describe Ruco::Editor do
1227
1109
  let(:editor){ Ruco::Editor.new(@file, :lines => 5, :columns => 10, :line_numbers => true) }
1228
1110
 
1229
1111
  before do
1230
- write("a\nb\nc\nd\ne\nf\ng\nh\n")
1112
+ write("0\n1\n2\n3\n4\n5\n6\n7\n")
1231
1113
  end
1232
1114
 
1233
1115
  it "adds numbers to view" do
1234
- editor.view.should == " 1 a\n 2 b\n 3 c\n 4 d\n 5 e"
1116
+ editor.view.should == " 1 0\n 2 1\n 3 2\n 4 3\n 5 4"
1235
1117
  end
1236
1118
 
1237
1119
  it "does not show numbers for empty lines" do
1238
1120
  editor.move(:to, 10,0)
1239
- editor.view.should == " 6 f\n 7 g\n 8 h\n 9 \n "
1121
+ editor.view.should == " 6 5\n 7 6\n 8 7\n 9 \n "
1240
1122
  end
1241
1123
 
1242
1124
  it "adjusts the cursor" do
@@ -16,10 +16,6 @@ describe Ruco::FileStore do
16
16
 
17
17
  let(:store){ Ruco::FileStore.new(@folder, :keep => 3) }
18
18
 
19
- it "can get unstored stuff" do
20
- store.get('xxx').should == nil
21
- end
22
-
23
19
  it "can store stuff" do
24
20
  store.set('xxx', 1)
25
21
  store.get('xxx').should == 1
@@ -45,45 +41,4 @@ describe Ruco::FileStore do
45
41
  store.set('zzz', 1)
46
42
  store.get('xxx').should == 1
47
43
  end
48
-
49
- it "can cache" do
50
- store.cache('x'){ 1 }.should == 1
51
- store.cache('x'){ 2 }.should == 1
52
- end
53
-
54
- it "can cache false" do
55
- store.cache('x'){ false }.should == false
56
- store.cache('x'){ 2 }.should == false
57
- end
58
-
59
- it "does not cache nil" do
60
- store.cache('x'){ nil }.should == nil
61
- store.cache('x'){ 2 }.should == 2
62
- end
63
-
64
- it "can delete" do
65
- store.set('x', 1)
66
- store.set('y', 2)
67
- store.delete('x')
68
- store.get('x').should == nil
69
- store.get('y').should == 2
70
- end
71
-
72
- it "can delete uncached" do
73
- store.set('x', 1)
74
- store.delete('z')
75
- store.get('x').should == 1
76
- store.get('z').should == nil
77
- end
78
-
79
- it "can clear" do
80
- store.set('x', 1)
81
- store.clear
82
- store.get('x').should == nil
83
- end
84
-
85
- it "can clear unstored" do
86
- store.clear
87
- store.get('x').should == nil
88
- end
89
44
  end