ruco 0.0.6 → 0.0.7

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
@@ -23,6 +23,7 @@ Usage
23
23
 
24
24
  TODO
25
25
  =====
26
+ - buffer <-> faster response via ssh session
26
27
  - smart staying at end of line/column when changing line
27
28
  - indentation + paste support
28
29
  - warnings / messages
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
data/bin/ruco CHANGED
@@ -4,7 +4,8 @@ require 'optparse'
4
4
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
5
 
6
6
  def parse_options
7
- options = OptionParser.new do |opts|
7
+ options = {}
8
+ parser = OptionParser.new do |opts|
8
9
  opts.banner = <<BANNER
9
10
  [Ru]by [Co]mmandline editor
10
11
 
@@ -17,14 +18,17 @@ Usage:
17
18
 
18
19
  Options:
19
20
  BANNER
21
+ opts.on("--show-cache","Show caching in action(ugly)") { options[:show_cache] = true }
20
22
  opts.on("-h", "--help","Show this.") { puts opts; exit }
21
23
  end
22
- options.parse!
24
+ parser.parse!
23
25
 
24
26
  if ARGV.empty?
25
- puts options
27
+ puts parser
26
28
  exit
27
29
  end
30
+
31
+ options
28
32
  end
29
33
 
30
34
  def write(line,row,text)
@@ -45,77 +49,48 @@ def init_screen
45
49
  end
46
50
  end
47
51
 
48
- def display(widget, offset, color)
52
+ def display(lines, offset, color)
53
+ @screen ||= [] # current screen is used as cache
49
54
  Curses.attrset color
50
- lines = widget.view.naive_split("\n")
51
- Curses.stdscr.maxy.times do |i|
52
- line = lines[i] || ''
53
- clearer = Curses.stdscr.maxx - line.size
55
+
56
+ lines.each_with_index do |content, line|
57
+ line += offset
58
+ clearer = Curses.stdscr.maxx - content.size
54
59
  clearer = " " * clearer
55
- write(i + offset, 0, line + clearer)
60
+ content += clearer
61
+
62
+ next if @screen[line] == content
63
+ @screen[line] = content
64
+
65
+ write(line, 0, content)
66
+ write(line, 0, (rand(899)+100).to_s) if @options[:show_cache]
56
67
  end
57
68
  end
58
69
 
59
- parse_options
70
+ def show_app(app)
71
+ lines = app.view.naive_split("\n")
60
72
 
61
- require 'ruco'
62
- status_lines = 1
63
- command_lines = 1
64
- editor_lines = Curses.stdscr.maxy - status_lines - command_lines
73
+ # TODO move this logic into application
74
+ display([lines.first], 0, Curses::A_REVERSE)
75
+ display(lines[1..-2], 1, Curses::A_NORMAL)
76
+ display([lines.last], Curses.stdscr.maxy - 1, Curses::A_REVERSE)
65
77
 
66
- editor = Ruco::Editor.new(ARGV[0], :lines => editor_lines, :columns => Curses.stdscr.maxx)
67
- status = Ruco::StatusBar.new(editor, :columns => Curses.stdscr.maxx)
68
- command = Ruco::CommandBar.new(:columns => Curses.stdscr.maxx)
69
- command.cursor_line = editor_lines
78
+ Curses.setpos(app.cursor.line, app.cursor.column)
79
+ end
80
+
81
+ @options = parse_options
70
82
 
71
- focused = editor
83
+ require 'ruco'
84
+ require 'ruco/keyboard' # needs curses <-> not loaded for specs
85
+
86
+ app = Ruco::Application.new(ARGV[0], :lines => Curses.stdscr.maxy, :columns => Curses.stdscr.maxx)
72
87
 
73
88
  init_screen do
74
- loop do
75
- display status, 0, Curses::A_REVERSE
76
- display editor, status_lines, Curses::A_NORMAL
77
- display command, status_lines + editor_lines, Curses::A_REVERSE
78
-
79
- Curses.setpos(focused.cursor.line + status_lines, focused.cursor.column)
80
-
81
- key = Curses.getch
82
-
83
- case key
84
-
85
- # move
86
- when Curses::Key::UP then focused.move(:relative, -1,0)
87
- when Curses::Key::DOWN then focused.move(:relative, 1,0)
88
- when Curses::Key::RIGHT then focused.move(:relative, 0,1)
89
- when Curses::Key::LEFT then focused.move(:relative, 0,-1)
90
- when Curses::KEY_END then focused.move :to_eol
91
- when Curses::KEY_HOME then focused.move :to_bol
92
-
93
- # modify
94
- when 9 then focused.insert(key.chr) # tab
95
- when 32..126 then focused.insert(key.chr) # printable
96
- when 10 then # enter
97
- result = focused.insert("\n")
98
- if result.is_a?(Ruco::Command)
99
- result.send_to(editor)
100
- focused = editor
101
- end
102
- when 263 then focused.delete(-1) # backspace
103
- when Curses::KEY_DC then focused.delete(1) # delete
104
-
105
- # misc
106
- when ?\C-d then
107
- editor.delete_line
108
- when ?\C-f then
109
- focused = command
110
- command.find
111
- when ?\C-g then
112
- focused = command
113
- command.move_to_line
114
- when 27 then
115
- focused.reset
116
- focused = editor # escape from focused
117
- when ?\C-s then editor.save
118
- when ?\C-w, ?\C-q then break # quit
119
- end
89
+ show_app app
90
+
91
+ Keyboard.listen do |key|
92
+ result = app.key key
93
+ break if result == :quit
94
+ show_app app
120
95
  end
121
96
  end
@@ -0,0 +1,69 @@
1
+ module Ruco
2
+ class Application
3
+ def initialize(file, options)
4
+ @file = file
5
+ @options = options
6
+
7
+ @status_lines = 1
8
+ @command_lines = 1
9
+ @editor_lines = @options[:lines] - @status_lines - @command_lines
10
+ create_components
11
+ end
12
+
13
+ def view
14
+ @status.view + "\n" + @editor.view + @command.view
15
+ end
16
+
17
+ def cursor
18
+ Cursor.new(@focused.cursor.line + @status_lines, @focused.cursor.column)
19
+ end
20
+
21
+ def key(key)
22
+ case key
23
+
24
+ # move
25
+ when :up then @focused.move(:relative, -1,0)
26
+ when :down then @focused.move(:relative, 1,0)
27
+ when :right then @focused.move(:relative, 0,1)
28
+ when :left then @focused.move(:relative, 0,-1)
29
+ when :end then @focused.move :to_eol
30
+ when :home then @focused.move :to_bol
31
+
32
+ # modify
33
+ when :tab then @focused.insert("\t")
34
+ when 32..126 then @focused.insert(key.chr) # printable
35
+ when :enter then
36
+ result = @focused.insert("\n")
37
+ if result.is_a?(Ruco::Command)
38
+ result.send_to(@editor)
39
+ @focused = @editor
40
+ end
41
+ when :backspace then @focused.delete(-1)
42
+ when :delete then @focused.delete(1)
43
+
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
+ when :escape then # escape from focused
54
+ @focused.reset
55
+ @focused = @editor
56
+ when :"Ctrl+s" then @editor.save
57
+ when :"Ctrl+w", :"Ctrl+q" then return(:quit) # quit
58
+ end
59
+ end
60
+
61
+ def create_components
62
+ @editor = Ruco::Editor.new(@file, :lines => @editor_lines, :columns => @options[:columns])
63
+ @status = Ruco::StatusBar.new(@editor, :columns => @options[:columns])
64
+ @command = Ruco::CommandBar.new(:columns => @options[:columns])
65
+ @command.cursor_line = @editor_lines
66
+ @focused = @editor
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,34 @@
1
+ class Keyboard
2
+ def self.listen
3
+ loop do
4
+ key = Curses.getch
5
+
6
+ case key
7
+
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)
15
+
16
+ # 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)
22
+
23
+ # 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")
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/ruco.rb CHANGED
@@ -8,6 +8,7 @@ require 'ruco/command'
8
8
  require 'ruco/editor'
9
9
  require 'ruco/status_bar'
10
10
  require 'ruco/command_bar'
11
+ require 'ruco/application'
11
12
 
12
13
  require 'ruco/form'
13
14
  require 'ruco/text_area'
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.6"
8
+ s.version = "0.0.7"
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-11}
12
+ s.date = %q{2011-01-12}
13
13
  s.default_executable = %q{ruco}
14
14
  s.email = %q{michael@grosser.it}
15
15
  s.executables = ["ruco"]
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  "VERSION",
22
22
  "bin/ruco",
23
23
  "lib/ruco.rb",
24
+ "lib/ruco/application.rb",
24
25
  "lib/ruco/command.rb",
25
26
  "lib/ruco/command_bar.rb",
26
27
  "lib/ruco/core_ext/array.rb",
@@ -29,10 +30,12 @@ Gem::Specification.new do |s|
29
30
  "lib/ruco/cursor.rb",
30
31
  "lib/ruco/editor.rb",
31
32
  "lib/ruco/form.rb",
33
+ "lib/ruco/keyboard.rb",
32
34
  "lib/ruco/status_bar.rb",
33
35
  "lib/ruco/text_area.rb",
34
36
  "lib/ruco/text_field.rb",
35
37
  "ruco.gemspec",
38
+ "spec/ruco/application_spec.rb",
36
39
  "spec/ruco/command_bar_spec.rb",
37
40
  "spec/ruco/command_spec.rb",
38
41
  "spec/ruco/core_ext/string_spec.rb",
@@ -47,6 +50,7 @@ Gem::Specification.new do |s|
47
50
  s.rubygems_version = %q{1.3.7}
48
51
  s.summary = %q{Commandline editor written in ruby}
49
52
  s.test_files = [
53
+ "spec/ruco/application_spec.rb",
50
54
  "spec/ruco/command_bar_spec.rb",
51
55
  "spec/ruco/command_spec.rb",
52
56
  "spec/ruco/core_ext/string_spec.rb",
@@ -0,0 +1,39 @@
1
+ require File.expand_path('spec/spec_helper')
2
+
3
+ describe Ruco::Application do
4
+ before do
5
+ @file = 'spec/temp.txt'
6
+ end
7
+
8
+ def write(content)
9
+ File.open(@file,'w'){|f| f.write(content) }
10
+ end
11
+
12
+ let(:app){ Ruco::Application.new(@file, :lines => 5, :columns => 10) }
13
+ let(:status){ "Ruco 0.0.6 -- spec/temp.txt \n" }
14
+ let(:command){ "^W Exit" }
15
+
16
+ it "renders status + editor + command" do
17
+ write("xxx\nyyy\nzzz")
18
+ app.view.should == "#{status}xxx\nyyy\nzzz\n#{command}"
19
+ end
20
+
21
+ it "can enter stuff" do
22
+ write("")
23
+ app.key(50)
24
+ app.key(50)
25
+ app.key(:enter)
26
+ app.key(50)
27
+ app.key(:enter)
28
+ app.view.should == "#{status.sub('.txt ','.txt*')}22\n2\n\n#{command}"
29
+ end
30
+
31
+ it "can execute a command" do
32
+ write("123\n456\n789\n")
33
+ app.key(:"Ctrl+g") # go to line
34
+ app.key(50) # 2
35
+ app.key(:enter)
36
+ app.view.should == "#{status}123\n456\n789\n#{command}"
37
+ app.cursor.should == [3,0] # 0 offset + 1 for statusbar
38
+ end
39
+ 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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
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-11 00:00:00 +01:00
18
+ date: 2011-01-12 00:00:00 +01:00
19
19
  default_executable: ruco
20
20
  dependencies: []
21
21
 
@@ -35,6 +35,7 @@ files:
35
35
  - VERSION
36
36
  - bin/ruco
37
37
  - lib/ruco.rb
38
+ - lib/ruco/application.rb
38
39
  - lib/ruco/command.rb
39
40
  - lib/ruco/command_bar.rb
40
41
  - lib/ruco/core_ext/array.rb
@@ -43,10 +44,12 @@ files:
43
44
  - lib/ruco/cursor.rb
44
45
  - lib/ruco/editor.rb
45
46
  - lib/ruco/form.rb
47
+ - lib/ruco/keyboard.rb
46
48
  - lib/ruco/status_bar.rb
47
49
  - lib/ruco/text_area.rb
48
50
  - lib/ruco/text_field.rb
49
51
  - ruco.gemspec
52
+ - spec/ruco/application_spec.rb
50
53
  - spec/ruco/command_bar_spec.rb
51
54
  - spec/ruco/command_spec.rb
52
55
  - spec/ruco/core_ext/string_spec.rb
@@ -90,6 +93,7 @@ signing_key:
90
93
  specification_version: 3
91
94
  summary: Commandline editor written in ruby
92
95
  test_files:
96
+ - spec/ruco/application_spec.rb
93
97
  - spec/ruco/command_bar_spec.rb
94
98
  - spec/ruco/command_spec.rb
95
99
  - spec/ruco/core_ext/string_spec.rb