ruco 0.0.10 → 0.0.11
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 +31 -3
- data/VERSION +1 -1
- data/lib/ruco.rb +8 -0
- data/lib/ruco/application.rb +33 -20
- data/lib/ruco/core_ext/object.rb +30 -1
- data/ruco.gemspec +1 -1
- data/spec/ruco/application_spec.rb +29 -1
- data/spec/spec_helper.rb +14 -1
- metadata +3 -3
data/Readme.md
CHANGED
@@ -12,6 +12,7 @@ Finished:
|
|
12
12
|
- backspace / delete
|
13
13
|
- find / go to line
|
14
14
|
- delete line
|
15
|
+
- configuration via `~/.ruco.rb`
|
15
16
|
|
16
17
|
Install
|
17
18
|
=======
|
@@ -21,12 +22,39 @@ Usage
|
|
21
22
|
=====
|
22
23
|
ruco file.rb
|
23
24
|
|
25
|
+
Customize
|
26
|
+
=========
|
27
|
+
|
28
|
+
# ~/.ruco.rb
|
29
|
+
Ruco.configure do
|
30
|
+
# bind a key, you can use Integers and Symbols
|
31
|
+
# use "ruco --debug-keys foo" to see which keys are possible
|
32
|
+
# or have a look at lib/ruco/keyboard.rb
|
33
|
+
bind(:"Ctrl+e") do
|
34
|
+
ask('delete ?') do |response|
|
35
|
+
if response or not response
|
36
|
+
editor.move(:to, 0, 0)
|
37
|
+
editor.delete(9999)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# bind an existing action
|
43
|
+
puts @actions.keys
|
44
|
+
|
45
|
+
bind(:"Ctrl+x", :quit)
|
46
|
+
bind(:"Ctrl+o", :save)
|
47
|
+
bind(:"Ctrl+k", :delete_line)
|
48
|
+
|
49
|
+
# define a new action and bind it to multiple keys
|
50
|
+
action(:first){ editor.move(:to_column, 0) }
|
51
|
+
bind(:"Ctrl+a", :first)
|
52
|
+
bind(:home, :first)
|
53
|
+
end
|
54
|
+
|
24
55
|
TODO
|
25
56
|
=====
|
26
57
|
- support typing unicode like äöß etc (rework size / make strings utf8-aware)
|
27
|
-
- bind/action must use instance_exec
|
28
|
-
- read .rucorc.rb
|
29
|
-
- write key binding guide
|
30
58
|
- smart staying at end of line/column when changing line
|
31
59
|
- indentation + paste support
|
32
60
|
- warnings / messages
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
data/lib/ruco.rb
CHANGED
@@ -16,4 +16,12 @@ require 'ruco/text_field'
|
|
16
16
|
module Ruco
|
17
17
|
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
18
18
|
TAB_SIZE = 2
|
19
|
+
|
20
|
+
class << self
|
21
|
+
attr_accessor :application
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configure(&block)
|
25
|
+
application.instance_exec(&block)
|
26
|
+
end
|
19
27
|
end
|
data/lib/ruco/application.rb
CHANGED
@@ -4,20 +4,14 @@ module Ruco
|
|
4
4
|
@file = file
|
5
5
|
@options = options
|
6
6
|
|
7
|
-
@bindings = {}
|
8
|
-
@actions = {}
|
9
|
-
|
10
|
-
@status_lines = 1
|
11
|
-
@command_lines = 1
|
12
|
-
@editor_lines = @options[:lines] - @status_lines - @command_lines
|
13
|
-
create_components
|
14
|
-
|
15
7
|
setup_actions
|
16
8
|
setup_keys
|
9
|
+
load_user_config
|
10
|
+
create_components
|
17
11
|
end
|
18
12
|
|
19
13
|
def view
|
20
|
-
|
14
|
+
status.view + "\n" + editor.view + command.view
|
21
15
|
end
|
22
16
|
|
23
17
|
def cursor
|
@@ -56,7 +50,7 @@ module Ruco
|
|
56
50
|
|
57
51
|
when :escape then # escape from focused
|
58
52
|
@focused.reset
|
59
|
-
@focused =
|
53
|
+
@focused = editor
|
60
54
|
end
|
61
55
|
end
|
62
56
|
|
@@ -71,22 +65,30 @@ module Ruco
|
|
71
65
|
end
|
72
66
|
|
73
67
|
def ask(question, options={}, &block)
|
74
|
-
@focused =
|
75
|
-
|
76
|
-
@focused =
|
68
|
+
@focused = command
|
69
|
+
command.ask(question, options) do |response|
|
70
|
+
@focused = editor
|
77
71
|
block.call(response)
|
78
72
|
end
|
79
73
|
end
|
80
74
|
|
75
|
+
def configure(&block)
|
76
|
+
instance_exec(&block)
|
77
|
+
end
|
78
|
+
|
81
79
|
private
|
82
80
|
|
81
|
+
attr_reader :editor, :status, :command
|
82
|
+
|
83
83
|
def setup_actions
|
84
|
+
@actions = {}
|
85
|
+
|
84
86
|
action :save do
|
85
|
-
|
87
|
+
editor.save
|
86
88
|
end
|
87
89
|
|
88
90
|
action :quit do
|
89
|
-
if
|
91
|
+
if editor.modified?
|
90
92
|
ask("Loose changes? Enter=Yes Esc=Cancel") do
|
91
93
|
:quit
|
92
94
|
end
|
@@ -96,19 +98,20 @@ module Ruco
|
|
96
98
|
end
|
97
99
|
|
98
100
|
action :go_to_line do
|
99
|
-
ask('Go to Line: '){|result|
|
101
|
+
ask('Go to Line: '){|result| editor.move(:to_line, result.to_i - 1) }
|
100
102
|
end
|
101
103
|
|
102
104
|
action :delete_line do
|
103
|
-
|
105
|
+
editor.delete_line
|
104
106
|
end
|
105
107
|
|
106
108
|
action :find do
|
107
|
-
ask("Find: ", :cache => true){|result|
|
109
|
+
ask("Find: ", :cache => true){|result| editor.find(result) }
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
111
113
|
def setup_keys
|
114
|
+
@bindings = {}
|
112
115
|
bind :"Ctrl+s", :save
|
113
116
|
bind :"Ctrl+w", :quit
|
114
117
|
bind :"Ctrl+q", :quit
|
@@ -117,11 +120,21 @@ module Ruco
|
|
117
120
|
bind :"Ctrl+d", :delete_line
|
118
121
|
end
|
119
122
|
|
123
|
+
def load_user_config
|
124
|
+
Ruco.application = self
|
125
|
+
config = File.expand_path("~/.ruco.rb")
|
126
|
+
load config if File.exist?(config)
|
127
|
+
end
|
128
|
+
|
120
129
|
def create_components
|
121
|
-
@
|
130
|
+
@status_lines = 1
|
131
|
+
command_lines = 1
|
132
|
+
editor_lines = @options[:lines] - @status_lines - command_lines
|
133
|
+
|
134
|
+
@editor = Ruco::Editor.new(@file, :lines => editor_lines, :columns => @options[:columns])
|
122
135
|
@status = Ruco::StatusBar.new(@editor, :columns => @options[:columns])
|
123
136
|
@command = Ruco::CommandBar.new(:columns => @options[:columns])
|
124
|
-
|
137
|
+
command.cursor_line = editor_lines
|
125
138
|
@focused = @editor
|
126
139
|
end
|
127
140
|
end
|
data/lib/ruco/core_ext/object.rb
CHANGED
@@ -14,4 +14,33 @@ end
|
|
14
14
|
EOS
|
15
15
|
end
|
16
16
|
end
|
17
|
-
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Object
|
20
|
+
unless defined? instance_exec # 1.9
|
21
|
+
module InstanceExecMethods #:nodoc:
|
22
|
+
end
|
23
|
+
include InstanceExecMethods
|
24
|
+
|
25
|
+
# Evaluate the block with the given arguments within the context of
|
26
|
+
# this object, so self is set to the method receiver.
|
27
|
+
#
|
28
|
+
# From Mauricio's http://eigenclass.org/hiki/bounded+space+instance_exec
|
29
|
+
def instance_exec(*args, &block)
|
30
|
+
begin
|
31
|
+
old_critical, Thread.critical = Thread.critical, true
|
32
|
+
n = 0
|
33
|
+
n += 1 while respond_to?(method_name = "__instance_exec#{n}")
|
34
|
+
InstanceExecMethods.module_eval { define_method(method_name, &block) }
|
35
|
+
ensure
|
36
|
+
Thread.critical = old_critical
|
37
|
+
end
|
38
|
+
|
39
|
+
begin
|
40
|
+
send(method_name, *args)
|
41
|
+
ensure
|
42
|
+
InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/ruco.gemspec
CHANGED
@@ -34,7 +34,7 @@ describe Ruco::Application do
|
|
34
34
|
app.key(50) # 2
|
35
35
|
app.key(:enter)
|
36
36
|
app.view.should == "#{status}123\n456\n789\n#{command}"
|
37
|
-
app.cursor.should == [
|
37
|
+
app.cursor.should == [2,0] # 0 offset + 1 for statusbar
|
38
38
|
end
|
39
39
|
|
40
40
|
describe 'closing' do
|
@@ -59,6 +59,22 @@ describe Ruco::Application do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
describe 'go to line' do
|
63
|
+
it "goes to the line" do
|
64
|
+
app.key(:"Ctrl+g")
|
65
|
+
app.key(?2)
|
66
|
+
app.key(:enter)
|
67
|
+
app.cursor.should == [2,0] # status bar + 2
|
68
|
+
end
|
69
|
+
|
70
|
+
it "goes to 1 when strange stuff entered" do
|
71
|
+
app.key(:"Ctrl+g")
|
72
|
+
app.key(?0)
|
73
|
+
app.key(:enter)
|
74
|
+
app.cursor.should == [1,0] # status bar + 1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
62
78
|
describe :bind do
|
63
79
|
it "can execute bound stuff" do
|
64
80
|
test = 0
|
@@ -79,4 +95,16 @@ describe Ruco::Application do
|
|
79
95
|
test.should == 1
|
80
96
|
end
|
81
97
|
end
|
98
|
+
|
99
|
+
describe '.ruco.rb' do
|
100
|
+
it "loads it and can use the bound keys" do
|
101
|
+
Tempfile.string_as_file("Ruco.configure{ bind(:'Ctrl+e'){ @editor.insert('TEST') } }") do |file|
|
102
|
+
File.stub!(:exist?).and_return true
|
103
|
+
File.should_receive(:expand_path).with("~/.ruco.rb").and_return file
|
104
|
+
app.view.should_not include('TEST')
|
105
|
+
app.key(:"Ctrl+e")
|
106
|
+
app.view.should include("TEST")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
82
110
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,15 @@
|
|
1
1
|
$LOAD_PATH.unshift 'lib'
|
2
|
-
require 'ruco'
|
2
|
+
require 'ruco'
|
3
|
+
|
4
|
+
require 'tempfile'
|
5
|
+
class Tempfile
|
6
|
+
def self.string_as_file(data)
|
7
|
+
result = nil
|
8
|
+
Tempfile.open('foo') do |f|
|
9
|
+
f.print data
|
10
|
+
f.close
|
11
|
+
result = yield(f.path)
|
12
|
+
end
|
13
|
+
result
|
14
|
+
end
|
15
|
+
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:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Grosser
|