ruco 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ruco/core_ext/string.rb +0 -9
- data/lib/ruco/editor.rb +1 -1
- data/lib/ruco/text_area.rb +52 -33
- data/ruco.gemspec +4 -3
- data/spec/ruco/core_ext/string_spec.rb +0 -15
- metadata +8 -11
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.20
|
data/lib/ruco/core_ext/string.rb
CHANGED
@@ -12,15 +12,6 @@ class String
|
|
12
12
|
found
|
13
13
|
end
|
14
14
|
|
15
|
-
def nth_index(text, n)
|
16
|
-
offset = -1
|
17
|
-
(n+1).times do
|
18
|
-
offset += 1
|
19
|
-
offset = index(text, offset) or return
|
20
|
-
end
|
21
|
-
offset
|
22
|
-
end
|
23
|
-
|
24
15
|
# stub for 1.8
|
25
16
|
unless method_defined?(:force_encoding)
|
26
17
|
def force_encoding(encoding)
|
data/lib/ruco/editor.rb
CHANGED
data/lib/ruco/text_area.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Ruco
|
2
2
|
class TextArea
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :lines
|
4
4
|
|
5
5
|
def initialize(content, options)
|
6
|
-
@
|
6
|
+
@lines = tabs_to_spaces(content).naive_split("\n")
|
7
7
|
@options = options
|
8
8
|
@line = 0
|
9
9
|
@column = 0
|
@@ -16,7 +16,6 @@ module Ruco
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def view
|
19
|
-
lines = self.lines
|
20
19
|
Array.new(@options[:lines]).map_with_index do |_,i|
|
21
20
|
(lines[i + @scrolled_lines] || "").slice(@scrolled_columns, @options[:columns])
|
22
21
|
end * "\n" + "\n"
|
@@ -54,29 +53,27 @@ module Ruco
|
|
54
53
|
next_whitespace = lines[@line+1].to_s.match(/^\s*/)[0]
|
55
54
|
text = text + [current_whitespace, next_whitespace].max
|
56
55
|
end
|
57
|
-
insert_into_content
|
58
|
-
move_according_to_insert
|
56
|
+
insert_into_content text
|
57
|
+
move_according_to_insert text
|
59
58
|
end
|
60
59
|
|
61
60
|
def delete(count)
|
62
61
|
if count > 0
|
63
|
-
@
|
62
|
+
if current_line[@column..-1].size >= count
|
63
|
+
current_line.slice!(@column, count)
|
64
|
+
else
|
65
|
+
with_lines_as_string do |content|
|
66
|
+
content.slice!(cursor_index, count)
|
67
|
+
end
|
68
|
+
end
|
64
69
|
else
|
65
70
|
backspace(count.abs)
|
66
71
|
end
|
67
72
|
end
|
68
73
|
|
69
|
-
# TODO this should go into editor
|
70
74
|
def delete_line
|
71
|
-
|
72
|
-
|
73
|
-
delete current_line.size
|
74
|
-
if position == [0,0]
|
75
|
-
delete(1)
|
76
|
-
else
|
77
|
-
delete(-1)
|
78
|
-
end
|
79
|
-
move :to, *old_position
|
75
|
+
lines.slice!(@line, 1)
|
76
|
+
adjust_view
|
80
77
|
end
|
81
78
|
|
82
79
|
def cursor
|
@@ -89,13 +86,23 @@ module Ruco
|
|
89
86
|
index
|
90
87
|
end
|
91
88
|
|
92
|
-
def
|
93
|
-
jump =
|
89
|
+
def position_for_index(index)
|
90
|
+
jump = content.slice(0, index).to_s.naive_split("\n")
|
94
91
|
[jump.size - 1, jump.last.size]
|
95
92
|
end
|
96
93
|
|
94
|
+
def content
|
95
|
+
(lines * "\n").freeze
|
96
|
+
end
|
97
|
+
|
97
98
|
protected
|
98
99
|
|
100
|
+
def with_lines_as_string
|
101
|
+
string = @lines * "\n"
|
102
|
+
yield string
|
103
|
+
@lines = string.naive_split("\n")
|
104
|
+
end
|
105
|
+
|
99
106
|
def after_last_word
|
100
107
|
current_line.index(/\s*$/)
|
101
108
|
end
|
@@ -125,18 +132,23 @@ module Ruco
|
|
125
132
|
end
|
126
133
|
|
127
134
|
def backspace(count)
|
128
|
-
|
129
|
-
|
130
|
-
count
|
131
|
-
|
132
|
-
|
135
|
+
if @column >= count
|
136
|
+
new_colum = @column - count
|
137
|
+
current_line.slice!(new_colum, count)
|
138
|
+
move :to_column, new_colum
|
139
|
+
else
|
140
|
+
start_index = cursor_index - count
|
141
|
+
if start_index < 0
|
142
|
+
count += start_index
|
143
|
+
start_index = 0
|
144
|
+
end
|
133
145
|
|
134
|
-
|
135
|
-
|
136
|
-
|
146
|
+
with_lines_as_string do |content|
|
147
|
+
content.slice!(start_index, count)
|
148
|
+
end
|
137
149
|
|
138
|
-
|
139
|
-
|
150
|
+
move :to, *position_for_index(start_index)
|
151
|
+
end
|
140
152
|
end
|
141
153
|
|
142
154
|
def adjust_view
|
@@ -181,12 +193,19 @@ module Ruco
|
|
181
193
|
@cursor_line = @line - @scrolled_lines
|
182
194
|
end
|
183
195
|
|
184
|
-
def insert_into_content(
|
185
|
-
|
186
|
-
|
187
|
-
|
196
|
+
def insert_into_content(text)
|
197
|
+
if text.include?("\n")
|
198
|
+
with_lines_as_string do |content|
|
199
|
+
content.insert(cursor_index, text)
|
200
|
+
end
|
201
|
+
else
|
202
|
+
# faster but complicated for newlines
|
203
|
+
lines[@line].insert(@column, text)
|
188
204
|
end
|
189
|
-
|
205
|
+
end
|
206
|
+
|
207
|
+
def position_inside_content?
|
208
|
+
@line < lines.size and @column < lines[@line].to_s.size
|
190
209
|
end
|
191
210
|
|
192
211
|
def current_line
|
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.20"
|
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-19}
|
13
13
|
s.default_executable = %q{ruco}
|
14
14
|
s.email = %q{michael@grosser.it}
|
15
15
|
s.executables = ["ruco"]
|
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
|
|
47
47
|
]
|
48
48
|
s.homepage = %q{http://github.com/grosser/ruco}
|
49
49
|
s.require_paths = ["lib"]
|
50
|
-
s.rubygems_version = %q{1.
|
50
|
+
s.rubygems_version = %q{1.3.7}
|
51
51
|
s.summary = %q{Commandline editor written in ruby}
|
52
52
|
s.test_files = [
|
53
53
|
"spec/ruco/application_spec.rb",
|
@@ -62,6 +62,7 @@ Gem::Specification.new do |s|
|
|
62
62
|
]
|
63
63
|
|
64
64
|
if s.respond_to? :specification_version then
|
65
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
65
66
|
s.specification_version = 3
|
66
67
|
|
67
68
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
@@ -14,19 +14,4 @@ describe String do
|
|
14
14
|
"".naive_split('a').should == ['']
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
18
|
-
describe :nth_index do
|
19
|
-
it "finds the first by default" do
|
20
|
-
"a a a".nth_index('a',0).should == 0
|
21
|
-
end
|
22
|
-
|
23
|
-
it "finds the n-th index" do
|
24
|
-
"a a a".nth_index('a',2).should == 4
|
25
|
-
end
|
26
|
-
|
27
|
-
it "is nil when not found" do
|
28
|
-
"b b b".nth_index('a',0).should == nil
|
29
|
-
"b b b".nth_index('a',1).should == nil
|
30
|
-
end
|
31
|
-
end
|
32
17
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 20
|
9
|
+
version: 0.0.20
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Michael Grosser
|
@@ -15,25 +14,24 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-19 00:00:00 +01:00
|
19
18
|
default_executable: ruco
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
21
|
+
name: clipboard
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
23
|
none: false
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
hash: 51
|
28
27
|
segments:
|
29
28
|
- 0
|
30
29
|
- 9
|
31
30
|
- 4
|
32
31
|
version: 0.9.4
|
32
|
+
type: :runtime
|
33
33
|
prerelease: false
|
34
34
|
version_requirements: *id001
|
35
|
-
type: :runtime
|
36
|
-
name: clipboard
|
37
35
|
description:
|
38
36
|
email: michael@grosser.it
|
39
37
|
executables:
|
@@ -87,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
85
|
requirements:
|
88
86
|
- - ">="
|
89
87
|
- !ruby/object:Gem::Version
|
90
|
-
hash:
|
88
|
+
hash: 588820097
|
91
89
|
segments:
|
92
90
|
- 0
|
93
91
|
version: "0"
|
@@ -96,14 +94,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
94
|
requirements:
|
97
95
|
- - ">="
|
98
96
|
- !ruby/object:Gem::Version
|
99
|
-
hash: 3
|
100
97
|
segments:
|
101
98
|
- 0
|
102
99
|
version: "0"
|
103
100
|
requirements: []
|
104
101
|
|
105
102
|
rubyforge_project:
|
106
|
-
rubygems_version: 1.
|
103
|
+
rubygems_version: 1.3.7
|
107
104
|
signing_key:
|
108
105
|
specification_version: 3
|
109
106
|
summary: Commandline editor written in ruby
|