ruco 0.0.7 → 0.0.8

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 CHANGED
@@ -5,10 +5,10 @@ Alpha, lets see if this works...
5
5
  Finished:
6
6
 
7
7
  - viewing / scrolling / editing / saving / creating
8
- - Home/End
8
+ - Home/End + Page up/down
9
9
  - basic Tab support (tab == 2 space)
10
- - change-indicator
11
- - writeable indicator
10
+ - change-indicator (*)
11
+ - writeable indicator (!)
12
12
  - backspace / delete
13
13
  - find / go to line
14
14
  - delete line
@@ -23,7 +23,10 @@ Usage
23
23
 
24
24
  TODO
25
25
  =====
26
- - buffer <-> faster response via ssh session
26
+ - backspace on mac ?
27
+ - bind/action must use instance_exec
28
+ - read .rucorc.rb
29
+ - write key binding guide
27
30
  - smart staying at end of line/column when changing line
28
31
  - indentation + paste support
29
32
  - warnings / messages
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
data/bin/ruco CHANGED
@@ -18,7 +18,8 @@ Usage:
18
18
 
19
19
  Options:
20
20
  BANNER
21
- opts.on("--show-cache","Show caching in action(ugly)") { options[:show_cache] = true }
21
+ opts.on("--debug-cache","Show caching in action") { options[:debug_cache] = true }
22
+ opts.on("--debug-keys", "Show pressed keys") { options[:debug_keys] = true }
22
23
  opts.on("-h", "--help","Show this.") { puts opts; exit }
23
24
  end
24
25
  parser.parse!
@@ -63,7 +64,7 @@ def display(lines, offset, color)
63
64
  @screen[line] = content
64
65
 
65
66
  write(line, 0, content)
66
- write(line, 0, (rand(899)+100).to_s) if @options[:show_cache]
67
+ write(line, 0, (rand(899)+100).to_s) if @options[:debug_cache]
67
68
  end
68
69
  end
69
70
 
@@ -78,6 +79,12 @@ def show_app(app)
78
79
  Curses.setpos(app.cursor.line, app.cursor.column)
79
80
  end
80
81
 
82
+ def debug_key(key)
83
+ @key_line ||= -1
84
+ @key_line = (@key_line + 1) % Curses.stdscr.maxy
85
+ write(@key_line, 0, "#{key}---")
86
+ end
87
+
81
88
  @options = parse_options
82
89
 
83
90
  require 'ruco'
@@ -89,6 +96,7 @@ init_screen do
89
96
  show_app app
90
97
 
91
98
  Keyboard.listen do |key|
99
+ debug_key(key) if @options[:debug_keys]
92
100
  result = app.key key
93
101
  break if result == :quit
94
102
  show_app app
@@ -4,10 +4,16 @@ module Ruco
4
4
  @file = file
5
5
  @options = options
6
6
 
7
+ @bindings = {}
8
+ @actions = {}
9
+
7
10
  @status_lines = 1
8
11
  @command_lines = 1
9
12
  @editor_lines = @options[:lines] - @status_lines - @command_lines
10
13
  create_components
14
+
15
+ setup_actions
16
+ setup_keys
11
17
  end
12
18
 
13
19
  def view
@@ -19,6 +25,15 @@ module Ruco
19
25
  end
20
26
 
21
27
  def key(key)
28
+ if bound = @bindings[key]
29
+ result = if bound.is_a?(Symbol)
30
+ @actions[bound].call
31
+ else
32
+ bound.call
33
+ end
34
+ return result
35
+ end
36
+
22
37
  case key
23
38
 
24
39
  # move
@@ -28,6 +43,8 @@ module Ruco
28
43
  when :left then @focused.move(:relative, 0,-1)
29
44
  when :end then @focused.move :to_eol
30
45
  when :home then @focused.move :to_bol
46
+ when :page_up then @focused.move :page_up
47
+ when :page_down then @focused.move :page_down
31
48
 
32
49
  # modify
33
50
  when :tab then @focused.insert("\t")
@@ -41,23 +58,56 @@ module Ruco
41
58
  when :backspace then @focused.delete(-1)
42
59
  when :delete then @focused.delete(1)
43
60
 
44
- # misc
45
- when :"Ctrl+d" then
46
- @editor.delete_line
47
- when :"Ctrl+f" then
48
- @focused = @command
49
- @command.find
50
- when :"Ctrl+g" then
51
- @focused = @command
52
- @command.move_to_line
53
61
  when :escape then # escape from focused
54
62
  @focused.reset
55
63
  @focused = @editor
56
- when :"Ctrl+s" then @editor.save
57
- when :"Ctrl+w", :"Ctrl+q" then return(:quit) # quit
58
64
  end
59
65
  end
60
66
 
67
+ def bind(key, action=nil, &block)
68
+ raise if action and block
69
+ @bindings[key] = action || block
70
+ end
71
+
72
+ def action(name, &block)
73
+ @actions[name] = block
74
+ end
75
+
76
+ private
77
+
78
+ def setup_actions
79
+ action :save do
80
+ @editor.save
81
+ end
82
+
83
+ action :quit do
84
+ :quit
85
+ end
86
+
87
+ action :go_to_line do
88
+ @focused = @command
89
+ @command.move_to_line
90
+ end
91
+
92
+ action :delete_line do
93
+ @editor.delete_line
94
+ end
95
+
96
+ action :find do
97
+ @focused = @command
98
+ @command.find
99
+ end
100
+ end
101
+
102
+ def setup_keys
103
+ bind :"Ctrl+s", :save
104
+ bind :"Ctrl+w", :quit
105
+ bind :"Ctrl+q", :quit
106
+ bind :"Ctrl+g", :go_to_line
107
+ bind :"Ctrl+f", :find
108
+ bind :"Ctrl+d", :delete_line
109
+ end
110
+
61
111
  def create_components
62
112
  @editor = Ruco::Editor.new(@file, :lines => @editor_lines, :columns => @options[:columns])
63
113
  @status = Ruco::StatusBar.new(@editor, :columns => @options[:columns])
@@ -27,6 +27,7 @@ module Ruco
27
27
 
28
28
  def find
29
29
  @forms_cache[:find] ||= Form.new('Find: ', :columns => @options[:columns]) do |value|
30
+ @form = nil
30
31
  Command.new(:find, value)
31
32
  end
32
33
  @form = @forms_cache[:find]
@@ -34,7 +35,7 @@ module Ruco
34
35
 
35
36
  def move_to_line
36
37
  @form = Form.new('Go to Line: ', :columns => @options[:columns], :type => :integer) do |value|
37
- reset
38
+ @form = nil
38
39
  Command.new(:move, :to_line, value.to_i)
39
40
  end
40
41
  end
data/lib/ruco/keyboard.rb CHANGED
@@ -3,32 +3,38 @@ class Keyboard
3
3
  loop do
4
4
  key = Curses.getch
5
5
 
6
- case key
6
+ code = case key
7
7
 
8
8
  # move
9
- when Curses::Key::UP then yield(:up)
10
- when Curses::Key::DOWN then yield(:down)
11
- when Curses::Key::RIGHT then yield(:right)
12
- when Curses::Key::LEFT then yield(:left)
13
- when Curses::KEY_END then yield(:end)
14
- when Curses::KEY_HOME then yield(:home)
9
+ when Curses::Key::UP then :up
10
+ when Curses::Key::DOWN then :down
11
+ when Curses::Key::RIGHT then :right
12
+ when Curses::Key::LEFT then :left
13
+ when Curses::KEY_END then :end
14
+ when Curses::KEY_HOME then :home
15
+ when Curses::KEY_NPAGE then :page_down
16
+ when Curses::KEY_PPAGE then :page_up
15
17
 
16
18
  # modify
17
- when 9 then yield(:tab)
18
- when 32..126 then yield(key) # printable
19
- when 10 then yield(:enter)
20
- when 263 then yield(:backspace)
21
- when Curses::KEY_DC then yield(:delete)
19
+ when 9 then :tab
20
+ when 32..126 then key # printable
21
+ when 10 then :enter
22
+ when 263 then :backspace
23
+ when Curses::KEY_DC then :delete
22
24
 
23
25
  # misc
24
- when ?\C-d then yield(:"Ctrl+d")
25
- when ?\C-f then yield(:"Ctrl+f")
26
- when ?\C-g then yield(:"Ctrl+g")
27
- when 27 then yield(:escape)
28
- when ?\C-s then yield(:"Ctrl+s")
29
- when ?\C-w then yield(:"Ctrl+w")
30
- when ?\C-q then yield(:"Ctrl+q")
26
+ when ?\C-d then :"Ctrl+d"
27
+ when ?\C-f then :"Ctrl+f"
28
+ when ?\C-g then :"Ctrl+g"
29
+ when 27 then :escape
30
+ when ?\C-s then :"Ctrl+s"
31
+ when ?\C-w then :"Ctrl+w"
32
+ when ?\C-q then :"Ctrl+q"
33
+ else
34
+ key
31
35
  end
36
+
37
+ yield code
32
38
  end
33
39
  end
34
40
  end
@@ -32,6 +32,14 @@ module Ruco
32
32
  when :to_eol then move_to_eol(*args)
33
33
  when :to_line then @line = args.first
34
34
  when :to_column then @column = args.first
35
+ when :page_down then
36
+ shift = @options[:lines] - 1
37
+ @line += shift
38
+ @scrolled_lines += shift
39
+ when :page_up then
40
+ shift = @options[:lines] - 1
41
+ @line -= shift
42
+ @scrolled_lines -= shift
35
43
  else
36
44
  raise "Unknown move type #{where} with #{args.inspect}"
37
45
  end
data/ruco.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruco}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
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"]
12
- s.date = %q{2011-01-12}
12
+ s.date = %q{2011-01-13}
13
13
  s.default_executable = %q{ruco}
14
14
  s.email = %q{michael@grosser.it}
15
15
  s.executables = ["ruco"]
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
42
42
  "spec/ruco/editor_spec.rb",
43
43
  "spec/ruco/form_spec.rb",
44
44
  "spec/ruco/status_bar_spec.rb",
45
+ "spec/ruco/text_area_spec.rb",
45
46
  "spec/ruco_spec.rb",
46
47
  "spec/spec_helper.rb"
47
48
  ]
@@ -57,6 +58,7 @@ Gem::Specification.new do |s|
57
58
  "spec/ruco/editor_spec.rb",
58
59
  "spec/ruco/form_spec.rb",
59
60
  "spec/ruco/status_bar_spec.rb",
61
+ "spec/ruco/text_area_spec.rb",
60
62
  "spec/ruco_spec.rb",
61
63
  "spec/spec_helper.rb"
62
64
  ]
@@ -10,7 +10,7 @@ describe Ruco::Application do
10
10
  end
11
11
 
12
12
  let(:app){ Ruco::Application.new(@file, :lines => 5, :columns => 10) }
13
- let(:status){ "Ruco 0.0.6 -- spec/temp.txt \n" }
13
+ let(:status){ "Ruco #{Ruco::VERSION} -- spec/temp.txt \n" }
14
14
  let(:command){ "^W Exit" }
15
15
 
16
16
  it "renders status + editor + command" do
@@ -36,4 +36,30 @@ describe Ruco::Application do
36
36
  app.view.should == "#{status}123\n456\n789\n#{command}"
37
37
  app.cursor.should == [3,0] # 0 offset + 1 for statusbar
38
38
  end
39
+
40
+ it "can quit" do
41
+ result = app.key(:"Ctrl+w")
42
+ result.should == :quit
43
+ end
44
+
45
+ describe :bind do
46
+ it "can execute bound stuff" do
47
+ test = 0
48
+ app.bind :'Ctrl+q' do
49
+ test = 1
50
+ end
51
+ app.key(:'Ctrl+q')
52
+ test.should == 1
53
+ end
54
+
55
+ it "can execute an action via bind" do
56
+ test = 0
57
+ app.action :foo do
58
+ test = 1
59
+ end
60
+ app.bind :'Ctrl+q', :foo
61
+ app.key(:'Ctrl+q')
62
+ test.should == 1
63
+ end
64
+ end
39
65
  end
@@ -32,6 +32,7 @@ describe Ruco::CommandBar do
32
32
  it "keeps entered stuff" do
33
33
  bar.find
34
34
  bar.insert('abc')
35
+ bar.insert("\n")
35
36
  bar.find
36
37
  bar.view.should == "Find: abc"
37
38
  bar.cursor.column.should == 9
@@ -40,7 +41,6 @@ describe Ruco::CommandBar do
40
41
  it "can reset the search" do
41
42
  bar.find
42
43
  bar.insert('abc')
43
- bar.insert("\n")
44
44
  bar.reset
45
45
 
46
46
  bar.view.should == default_view
@@ -59,6 +59,7 @@ describe Ruco::CommandBar do
59
59
  bar.find
60
60
  bar.insert('abcd')
61
61
  bar.insert("\n")
62
+ bar.find
62
63
  result = bar.insert("\n")
63
64
  result.should == Ruco::Command.new(:find, 'abcd')
64
65
  end
@@ -0,0 +1,57 @@
1
+ require File.expand_path('spec/spec_helper')
2
+
3
+ describe Ruco::TextArea do
4
+ describe :move do
5
+ describe 'pages' do
6
+ it "can move down a page" do
7
+ text = Ruco::TextArea.new("1\n2\n3\n4\n5\n6\n7\n8\n9\n", :lines => 3, :columns => 3)
8
+ text.move(:page_down)
9
+ text.view.should == "3\n4\n5\n"
10
+ text.cursor.should == [0,0]
11
+ end
12
+
13
+ it "keeps cursor position when moving down" do
14
+ text = Ruco::TextArea.new("1\n2abc\n3\n4ab\n5\n6\n7\n8\n9\n", :lines => 3, :columns => 5)
15
+ text.move(:to, 1,4)
16
+ text.move(:page_down)
17
+ text.view.should == "3\n4ab\n5\n"
18
+ text.cursor.should == [1,3]
19
+ end
20
+
21
+ it "can move up a page" do
22
+ text = Ruco::TextArea.new("0\n1\n2\n3\n4\n5\n6\n7\n8\n", :lines => 3, :columns => 3)
23
+ text.move(:to, 4, 0)
24
+ text.view.should == "2\n3\n4\n"
25
+ text.cursor.should == [2,0]
26
+ text.move(:page_up)
27
+ text.view.should == "0\n1\n2\n"
28
+ text.cursor.should == [2,0]
29
+ end
30
+
31
+ it "keeps column position when moving up" do
32
+ text = Ruco::TextArea.new("0\n1\n2\n3ab\n4\n5abc\n6\n7\n8\n", :lines => 3, :columns => 5)
33
+ text.move(:to, 5, 4)
34
+ text.view.should == "3ab\n4\n5abc\n"
35
+ text.cursor.should == [2,4]
36
+ text.move(:page_up)
37
+ text.view.should == "1\n2\n3ab\n"
38
+ text.cursor.should == [2,3]
39
+ end
40
+
41
+ it "moves pages symetric" do
42
+ text = Ruco::TextArea.new("0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n", :lines => 3, :columns => 3)
43
+ text.move(:to, 4, 1)
44
+ text.view.should == "2\n3\n4\n"
45
+ text.cursor.should == [2,1]
46
+
47
+ text.move(:page_down)
48
+ text.move(:page_down)
49
+ text.move(:page_up)
50
+ text.move(:page_up)
51
+
52
+ text.cursor.should == [2,1]
53
+ text.view.should == "2\n3\n4\n"
54
+ end
55
+ end
56
+ end
57
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruco
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Grosser
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-12 00:00:00 +01:00
18
+ date: 2011-01-13 00:00:00 +01:00
19
19
  default_executable: ruco
20
20
  dependencies: []
21
21
 
@@ -56,6 +56,7 @@ files:
56
56
  - spec/ruco/editor_spec.rb
57
57
  - spec/ruco/form_spec.rb
58
58
  - spec/ruco/status_bar_spec.rb
59
+ - spec/ruco/text_area_spec.rb
59
60
  - spec/ruco_spec.rb
60
61
  - spec/spec_helper.rb
61
62
  has_rdoc: true
@@ -100,5 +101,6 @@ test_files:
100
101
  - spec/ruco/editor_spec.rb
101
102
  - spec/ruco/form_spec.rb
102
103
  - spec/ruco/status_bar_spec.rb
104
+ - spec/ruco/text_area_spec.rb
103
105
  - spec/ruco_spec.rb
104
106
  - spec/spec_helper.rb