ruco 0.0.30 → 0.0.31

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
@@ -7,7 +7,7 @@ Features:
7
7
  - Tab -> indent / Shift+Tab -> unindent (tab == 2 space)
8
8
  - keeps indentation (+ paste-detection e.g. via Cmd+v)
9
9
  - change (*) + writable (!) indicators
10
- - find / go to line / delete line
10
+ - find / go to line / delete line / search & replace
11
11
  - configuration via `~/.ruco.rb`
12
12
  - cut, copy and paste -> Ctrl+x/c/v
13
13
 
@@ -57,13 +57,14 @@ TIPS
57
57
 
58
58
  TODO
59
59
  =====
60
+ - add selection colors to forms in command_bar
60
61
  - session storage (stay at same line/column when reopening)
61
62
  - smart staying at end of line/column when changing line
62
63
  - warnings / messages
63
64
  - syntax highlighting
64
65
  - raise when binding to a unsupported key
65
66
  - search options regex + case-sensitive
66
- - search & replace
67
+ - add auto-confirm to 'replace?' dialog -> type s == skip, no enter needed
67
68
  - 1.8: unicode support <-> already finished but unusable due to Curses (see encoding branch)
68
69
  - support Alt+Fx keys
69
70
  - (later) extract keyboard and html-style components into seperate project
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.30
1
+ 0.0.31
@@ -102,6 +102,13 @@ module Ruco
102
102
  end
103
103
  end
104
104
 
105
+ def loop_ask(question, options={}, &block)
106
+ ask(question, options) do |result|
107
+ finished = (block.call(result) == :finished)
108
+ loop_ask(question, options, &block) unless finished
109
+ end
110
+ end
111
+
105
112
  def configure(&block)
106
113
  instance_exec(&block)
107
114
  end
@@ -165,6 +172,23 @@ module Ruco
165
172
  action :find do
166
173
  ask("Find: ", :cache => true){|result| editor.find(result) }
167
174
  end
175
+
176
+ action :find_and_replace do
177
+ ask("Find: ", :cache => true) do |term|
178
+ if editor.find(term)
179
+ ask("Replace with: ", :cache => true) do |replace|
180
+ loop_ask("Replace=Enter Skip=s Cancel=Esc") do |ok|
181
+ if ok == '' # enter
182
+ editor.insert(replace)
183
+ elsif ok != 's'
184
+ stop = true
185
+ end
186
+ :finished if stop or not editor.find(term)
187
+ end
188
+ end
189
+ end
190
+ end
191
+ end
168
192
  end
169
193
 
170
194
  def setup_keys
@@ -174,6 +198,7 @@ module Ruco
174
198
  bind :"Ctrl+q", :quit
175
199
  bind :"Ctrl+g", :go_to_line
176
200
  bind :"Ctrl+f", :find
201
+ bind :"Ctrl+r", :find_and_replace
177
202
  bind :"Ctrl+a", :select_all
178
203
  bind :"Ctrl+d", :delete_line
179
204
  bind :"Ctrl+x", :cut
@@ -1,7 +1,7 @@
1
1
  module Ruco
2
2
  class CommandBar
3
3
  attr_accessor :cursor_line, :form
4
- delegate :move, :delete, :insert, :to => :form
4
+ delegate :move, :delete, :insert, :selecting, :selection, :text_in_selection, :to => :form
5
5
 
6
6
  SHORTCUTS = [
7
7
  '^W Exit',
@@ -51,7 +51,9 @@ module Ruco
51
51
 
52
52
  def cached_form_if(cache, question)
53
53
  if cache
54
- @forms_cache[question] ||= yield
54
+ new_form = yield
55
+ new_form.insert(@forms_cache[question].value) if @forms_cache[question]
56
+ @forms_cache[question] = new_form
55
57
  else
56
58
  yield
57
59
  end
data/lib/ruco/editor.rb CHANGED
@@ -4,7 +4,7 @@ module Ruco
4
4
  attr_reader :text_area
5
5
  private :text_area
6
6
  delegate :view, :color_mask, :cursor,
7
- :selecting, :selection, :text_in_selection,
7
+ :selecting, :selection, :text_in_selection, :reset,
8
8
  :move, :resize,
9
9
  :to => :text_area
10
10
 
@@ -23,14 +23,14 @@ module Ruco
23
23
  end
24
24
 
25
25
  def find(text)
26
+ move(:relative, 0,0) # reset selection
26
27
  return unless start = text_area.content.index(text, text_area.index_for_position+1)
27
28
  finish = start + text.size
28
29
  move(:to_index, finish)
29
30
  selecting{ move(:to_index, start) }
31
+ true
30
32
  end
31
33
 
32
- def reset;end
33
-
34
34
  def insert(text)
35
35
  text_area.insert(text)
36
36
  @modified = true
data/lib/ruco/form.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ruco
2
2
  class Form
3
- delegate :move, :delete, :to => :text_field
3
+ delegate :move, :delete, :value, :selecting, :selection, :text_in_selection, :to => :text_field
4
4
 
5
5
  def initialize(label, options, &submit)
6
6
  @options = options
@@ -88,6 +88,10 @@ module Ruco
88
88
  content.slice(start, finish-start)
89
89
  end
90
90
 
91
+ def reset
92
+ @selection = nil
93
+ end
94
+
91
95
  def insert(text)
92
96
  delete_content_in_selection if @selection
93
97
 
data/ruco.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruco}
8
- s.version = "0.0.30"
8
+ s.version = "0.0.31"
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"]
@@ -52,7 +52,7 @@ Gem::Specification.new do |s|
52
52
  ]
53
53
  s.homepage = %q{http://github.com/grosser/ruco}
54
54
  s.require_paths = ["lib"]
55
- s.rubygems_version = %q{1.4.2}
55
+ s.rubygems_version = %q{1.3.7}
56
56
  s.summary = %q{Commandline editor written in ruby}
57
57
  s.test_files = [
58
58
  "spec/ruco/application_spec.rb",
@@ -69,6 +69,7 @@ Gem::Specification.new do |s|
69
69
  ]
70
70
 
71
71
  if s.respond_to? :specification_version then
72
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
72
73
  s.specification_version = 3
73
74
 
74
75
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -15,6 +15,10 @@ describe Ruco::Application do
15
15
  view.naive_split("\n")[1..-2].join("\n")
16
16
  end
17
17
 
18
+ def type(*keys)
19
+ keys.each{|k| app.key k }
20
+ end
21
+
18
22
  let(:app){ Ruco::Application.new(@file, :lines => 5, :columns => 10) }
19
23
  let(:status){ "Ruco #{Ruco::VERSION} -- spec/temp.txt \n" }
20
24
  let(:command){ "^W Exit" }
@@ -101,6 +105,60 @@ describe Ruco::Application do
101
105
  end
102
106
  end
103
107
 
108
+ describe 'Find and replace' do
109
+ it "stops when nothing is found" do
110
+ write 'abc'
111
+ type :"Ctrl+r", 'x', :enter
112
+ app.view.should_not include("Replace with:")
113
+ end
114
+
115
+ it "can find and replace multiple times" do
116
+ write 'xabac'
117
+ type :"Ctrl+r", 'a', :enter
118
+ app.view.should include("Replace with:")
119
+ type 'd', :enter
120
+ app.view.should include("Replace")
121
+ type :enter # replace first
122
+ app.view.should include("Replace")
123
+ type :enter # replace second -> finished
124
+ app.view.should_not include("Replace")
125
+ editor_part(app.view).should == "xdbdc\n\n"
126
+ end
127
+
128
+ it "can find and skip replace multiple times" do
129
+ write 'xabac'
130
+ type :"Ctrl+r", 'a', :enter
131
+ app.view.should include("Replace with:")
132
+ type 'd', :enter
133
+ app.view.should include("Replace")
134
+ type 's', :enter # skip
135
+ app.view.should include("Replace")
136
+ type 's', :enter # skip
137
+ app.view.should_not include("Replace")
138
+ editor_part(app.view).should == "xabac\n\n"
139
+ end
140
+
141
+ it "breaks if neither s nor enter is entered" do
142
+ write 'xabac'
143
+ type :"Ctrl+r", 'a', :enter
144
+ app.view.should include("Replace with:")
145
+ type "d", :enter
146
+ app.view.should include("Replace")
147
+ type 'x', :enter
148
+ app.view.should_not include("Replace")
149
+ editor_part(app.view).should == "xabac\n\n"
150
+ end
151
+
152
+ it "reuses find" do
153
+ write 'xabac'
154
+ type :"Ctrl+f", 'a', :enter
155
+ type :"Ctrl+r"
156
+ app.view.should include("Find: a")
157
+ type :enter
158
+ app.view.should include("Replace with:")
159
+ end
160
+ end
161
+
104
162
  describe :bind do
105
163
  it "can execute bound stuff" do
106
164
  test = 0
@@ -44,6 +44,15 @@ describe Ruco::CommandBar do
44
44
  bar.cursor.column.should == 9
45
45
  end
46
46
 
47
+ it "does not keep block when cached" do
48
+ x = 0
49
+ bar.ask('Find: ', :cache => true){ x = 1 }
50
+ bar.insert("\n")
51
+ bar.ask('Find: ', :cache => true){ x = 2 }
52
+ bar.insert("\n")
53
+ x.should == 2
54
+ end
55
+
47
56
  it "reset the question when cached" do
48
57
  bar.ask('Find: ', :cache => true){}
49
58
  bar.insert('abc')
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruco
3
3
  version: !ruby/object:Gem::Version
4
- hash: 35
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 30
10
- version: 0.0.30
8
+ - 31
9
+ version: 0.0.31
11
10
  platform: ruby
12
11
  authors:
13
12
  - Michael Grosser
@@ -19,21 +18,20 @@ date: 2011-01-27 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:
@@ -92,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
90
  requirements:
93
91
  - - ">="
94
92
  - !ruby/object:Gem::Version
95
- hash: 3
93
+ hash: 732794355
96
94
  segments:
97
95
  - 0
98
96
  version: "0"
@@ -101,14 +99,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
99
  requirements:
102
100
  - - ">="
103
101
  - !ruby/object:Gem::Version
104
- hash: 3
105
102
  segments:
106
103
  - 0
107
104
  version: "0"
108
105
  requirements: []
109
106
 
110
107
  rubyforge_project:
111
- rubygems_version: 1.4.2
108
+ rubygems_version: 1.3.7
112
109
  signing_key:
113
110
  specification_version: 3
114
111
  summary: Commandline editor written in ruby