ruco 0.0.29 → 0.0.30
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 +1 -0
- data/VERSION +1 -1
- data/lib/ruco.rb +1 -0
- data/lib/ruco/editor.rb +1 -1
- data/lib/ruco/editor_area.rb +48 -0
- data/lib/ruco/keyboard.rb +5 -4
- data/lib/ruco/text_area.rb +0 -44
- data/ruco.gemspec +3 -2
- data/spec/ruco/keyboard_spec.rb +5 -0
- metadata +5 -4
data/Readme.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.30
|
data/lib/ruco.rb
CHANGED
data/lib/ruco/editor.rb
CHANGED
@@ -18,7 +18,7 @@ module Ruco
|
|
18
18
|
raise "#{@file} contains tabs.\nRuco atm does not support tabs, but will happily convert them to spaces if started with --convert-tabs or -c"
|
19
19
|
end
|
20
20
|
end
|
21
|
-
@text_area =
|
21
|
+
@text_area = EditorArea.new(content, options)
|
22
22
|
@modified = false
|
23
23
|
end
|
24
24
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Ruco
|
2
|
+
# everything that does not belong to a text-area
|
3
|
+
# but is needed for Ruco::Editor
|
4
|
+
class EditorArea < TextArea
|
5
|
+
def delete_line
|
6
|
+
lines.slice!(@line, 1)
|
7
|
+
adjust_view
|
8
|
+
end
|
9
|
+
|
10
|
+
def indent
|
11
|
+
selected_lines.each do |line|
|
12
|
+
@lines[line].insert(0, ' ' * Ruco::TAB_SIZE)
|
13
|
+
end
|
14
|
+
adjust_to_indentation Ruco::TAB_SIZE
|
15
|
+
adjust_view
|
16
|
+
end
|
17
|
+
|
18
|
+
def unindent
|
19
|
+
lines_to_unindent = (selection ? selected_lines : [@line])
|
20
|
+
removed = lines_to_unindent.map do |line|
|
21
|
+
remove = [@lines[line].leading_whitespace.size, Ruco::TAB_SIZE].min
|
22
|
+
@lines[line].slice!(0, remove)
|
23
|
+
remove
|
24
|
+
end
|
25
|
+
|
26
|
+
adjust_to_indentation -removed.first, -removed.last
|
27
|
+
adjust_view
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def adjust_to_indentation(first, last=nil)
|
33
|
+
last ||= first
|
34
|
+
if selection
|
35
|
+
cursor_adjustment = (selection.first == position ? first : last)
|
36
|
+
selection.first.column = [selection.first.column + first, 0].max
|
37
|
+
selection.last.column = [selection.last.column + last, 0].max
|
38
|
+
@column += cursor_adjustment
|
39
|
+
else
|
40
|
+
@column += first
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def selected_lines
|
45
|
+
selection.first.line.upto(selection.last.line)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/ruco/keyboard.rb
CHANGED
@@ -3,6 +3,7 @@ require 'curses'
|
|
3
3
|
class Keyboard
|
4
4
|
MAX_CHAR = 255
|
5
5
|
ENTER = 13
|
6
|
+
ESCAPE = 27
|
6
7
|
IS_18 = RUBY_VERSION =~ /^1\.8/
|
7
8
|
SEQUENCE_TIMEOUT = 0.01
|
8
9
|
NOTHING = (2**32 - 1) # getch returns this as 'nothing' on 1.8 but nil on 1.9.2
|
@@ -64,7 +65,7 @@ class Keyboard
|
|
64
65
|
# misc
|
65
66
|
when 0 then :"Ctrl+space"
|
66
67
|
when 1..26 then :"Ctrl+#{A_TO_Z[key-1]}"
|
67
|
-
when
|
68
|
+
when ESCAPE then :escape
|
68
69
|
when Curses::KEY_RESIZE then :resize
|
69
70
|
else
|
70
71
|
key > MAX_CHAR ? key : key.chr
|
@@ -140,13 +141,13 @@ class Keyboard
|
|
140
141
|
end
|
141
142
|
|
142
143
|
def self.escape_sequence?(sequence)
|
143
|
-
sequence[0] ==
|
144
|
+
sequence[0] == ESCAPE and sequence.size.between?(2,6) # Esc
|
144
145
|
end
|
145
146
|
|
146
147
|
def self.escape_sequence_to_key(sequence)
|
147
148
|
case sequence
|
148
|
-
when [
|
149
|
-
when [
|
149
|
+
when [ESCAPE, 91, 49, 59, 50, 65] then :"Shift+up"
|
150
|
+
when [ESCAPE, 91, 49, 59, 50, 66] then :"Shift+down"
|
150
151
|
else
|
151
152
|
if sequence.size == 2
|
152
153
|
:"Alt+#{sequence[1].chr}"
|
data/lib/ruco/text_area.rb
CHANGED
@@ -120,34 +120,6 @@ module Ruco
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
-
# TODO should be on editor
|
124
|
-
def delete_line
|
125
|
-
lines.slice!(@line, 1)
|
126
|
-
adjust_view
|
127
|
-
end
|
128
|
-
|
129
|
-
# TODO should be on editor
|
130
|
-
def indent
|
131
|
-
selected_lines.each do |line|
|
132
|
-
@lines[line].insert(0, ' ' * Ruco::TAB_SIZE)
|
133
|
-
end
|
134
|
-
adjust_to_indentation Ruco::TAB_SIZE
|
135
|
-
adjust_view
|
136
|
-
end
|
137
|
-
|
138
|
-
# TODO should be on editor
|
139
|
-
def unindent
|
140
|
-
lines_to_unindent = (selection ? selected_lines : [@line])
|
141
|
-
removed = lines_to_unindent.map do |line|
|
142
|
-
remove = [@lines[line].leading_whitespace.size, Ruco::TAB_SIZE].min
|
143
|
-
@lines[line].slice!(0, remove)
|
144
|
-
remove
|
145
|
-
end
|
146
|
-
|
147
|
-
adjust_to_indentation -removed.first, -removed.last
|
148
|
-
adjust_view
|
149
|
-
end
|
150
|
-
|
151
123
|
def cursor
|
152
124
|
Position.new @cursor_line, @cursor_column
|
153
125
|
end
|
@@ -317,21 +289,5 @@ module Ruco
|
|
317
289
|
end_of_line = [line, last_visible_column]
|
318
290
|
start_of_line..end_of_line
|
319
291
|
end
|
320
|
-
|
321
|
-
def adjust_to_indentation(first, last=nil)
|
322
|
-
last ||= first
|
323
|
-
if selection
|
324
|
-
adjust_cursor = selection.first == position ? first : last
|
325
|
-
selection.first.column = [selection.first.column + first, 0].max
|
326
|
-
selection.last.column = [selection.last.column + last, 0].max
|
327
|
-
@column += adjust_cursor
|
328
|
-
else
|
329
|
-
@column += first
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
def selected_lines
|
334
|
-
selection.first.line.upto(selection.last.line)
|
335
|
-
end
|
336
292
|
end
|
337
293
|
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.
|
8
|
+
s.version = "0.0.30"
|
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
|
+
s.date = %q{2011-01-27}
|
13
13
|
s.default_executable = %q{ruco}
|
14
14
|
s.email = %q{michael@grosser.it}
|
15
15
|
s.executables = ["ruco"]
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/ruco/core_ext/range.rb",
|
30
30
|
"lib/ruco/core_ext/string.rb",
|
31
31
|
"lib/ruco/editor.rb",
|
32
|
+
"lib/ruco/editor_area.rb",
|
32
33
|
"lib/ruco/form.rb",
|
33
34
|
"lib/ruco/keyboard.rb",
|
34
35
|
"lib/ruco/position.rb",
|
data/spec/ruco/keyboard_spec.rb
CHANGED
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: 35
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 30
|
10
|
+
version: 0.0.30
|
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-
|
18
|
+
date: 2011-01-27 00:00:00 +01:00
|
19
19
|
default_executable: ruco
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/ruco/core_ext/range.rb
|
59
59
|
- lib/ruco/core_ext/string.rb
|
60
60
|
- lib/ruco/editor.rb
|
61
|
+
- lib/ruco/editor_area.rb
|
61
62
|
- lib/ruco/form.rb
|
62
63
|
- lib/ruco/keyboard.rb
|
63
64
|
- lib/ruco/position.rb
|