rawline 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,30 @@
1
+ == Version 0.3.0
2
+
3
+ * Fixed linux-specific bugs.
4
+ * Added RawLine::Line#words method, which returns the words typed in the current line.
5
+ * undo and redo action now bound to C-u and C-r instead of C-z and C-y to avoid conflicts on Linux.
6
+ * test file and directory renaming.
7
+ * Fixed #1 [#21300] bad requirement because sensitive case error.
8
+ * Fixed #2 [#21301] unitialized constant when no WIN32CONSOLE.
9
+ * Added Ruby 1.9.1 support.
10
+ * Editor#read now takes an optional parameter (default: false) to enable or disable history.
11
+ * Line is no longer added to history when calling Editor#history_back.
12
+ * Added Editor#filename_completion_proc.
13
+ * Editor#completion_proc defaults to Editor#filename_completion_proc.
14
+ * RawLine is now a drop-in replacement for Readline.
15
+ * Added examples/readline_emulation.rb.
16
+ * Moved repository to GitHub.
17
+
18
+ == Version 0.2.0
19
+
20
+ * Added /examples and /test directory to gem.
21
+ * Escape codes can now be used in prompt.
22
+ * It is now possible to use bind(key, &block) with a String as key, even if the corresponding escape sequence is not defined.
23
+ * Added Editor#write_line(string) to print a any string (and "hit return").
24
+ * Library name changed to "RawLine" to avoid name collision issues (Bug 18879: http://rubyforge.org/tracker/?func=detail&aid=18879&group_id=5622&atid=21788).
25
+ * Provided alternative implementation for left and right arrows if terminal
26
+ supports escape sequences (on Windows, it requires the Win32Console gem).
27
+
28
+ == Version 0.1.0
29
+
30
+ First preview release of InLine, implementing some of the functionality provided by the ReadLine library such as basic line editing, history and word completion.
data/LICENSE CHANGED
@@ -1,11 +1,11 @@
1
- Copyright (c) 2008, Fabio Cevasco
2
- All rights reserved.
3
-
4
- - Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
- - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
- - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7
- Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8
-
9
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10
-
11
-
1
+ Copyright (c) 2008, Fabio Cevasco
2
+ All rights reserved.
3
+
4
+ - Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+ - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+ - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7
+ Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8
+
9
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10
+
11
+
@@ -11,7 +11,7 @@ RawLine was created to provide a 100% Ruby alternative to the ReadLine library,
11
11
 
12
12
  The simplest method to install RawLine is to install the gem:
13
13
 
14
- gem install -r rawline
14
+ gem install rawline
15
15
 
16
16
  == Usage
17
17
 
@@ -37,7 +37,24 @@ Setup word completion
37
37
 
38
38
  Read input:
39
39
 
40
- editor.read("=> ")
40
+ editor.read("=> ", true)
41
41
 
42
+ == Replacing Readline
42
43
 
44
+ Simply include the RawLine (or Rawline) module:
45
+
46
+ include Rawline
47
+
48
+ ...and you'll get:
49
+
50
+ readline(prompt, add_history) # RawLine::Editor#read(prompt, add_history)
51
+ HISTORY # RawLine::Editor#history
52
+ FILENAME_COMPLETION_PROC # Rawline::Editor#filename_completion_proc
53
+ ...
54
+
55
+ but also:
56
+
57
+ Rawline.editor # RawLine::Editor
58
+
59
+ ...which opens a world of endless possibilities! ;-)
43
60
 
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
4
  require 'highline/system_extensions'
@@ -12,8 +12,10 @@ loop do
12
12
  print "=> "
13
13
  char = get_character
14
14
  case char
15
- when ?\C-x: print "Exiting..."; exit;
16
- else puts "#{char.chr} [#{char}] (hex: #{char.to_s(16)})";
15
+ when ?\C-x.ord then
16
+ puts "Exiting..."; exit;
17
+ else
18
+ puts "#{char.chr} [#{char}] (hex: #{char.to_s(16)})";
17
19
  end
18
20
 
19
21
  end
@@ -1,16 +1,16 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!usr/bin/env ruby
2
2
 
3
3
  require File.dirname(File.expand_path(__FILE__))+'/../lib/rawline'
4
4
 
5
5
  puts "*** Rawline Editor Test Shell ***"
6
6
  puts " * Press CTRL+X to exit"
7
- puts " * Press CTRL+C to clear command history"
7
+ puts " * Press CTRL+G to clear command history"
8
8
  puts " * Press CTRL+D for line-related information"
9
9
  puts " * Press CTRL+E to view command history"
10
10
 
11
11
  editor = RawLine::Editor.new
12
12
 
13
- editor.bind(:ctrl_c) { editor.clear_history }
13
+ editor.bind(:ctrl_g) { editor.clear_history }
14
14
  editor.bind(:ctrl_d) { editor.debug_line }
15
15
  editor.bind(:ctrl_e) { editor.show_history }
16
16
  editor.bind(:ctrl_x) { puts; puts "Exiting..."; exit }
@@ -22,5 +22,5 @@ editor.completion_proc = lambda do |word|
22
22
  end
23
23
 
24
24
  loop do
25
- puts "You typed: [#{editor.read("=> ").chomp!}]"
25
+ puts "You typed: [#{editor.read("=> ", true).chomp!}]"
26
26
  end
@@ -0,0 +1,17 @@
1
+ #!usr/bin/env ruby
2
+
3
+ require File.dirname(File.expand_path(__FILE__))+'/../lib/rawline'
4
+
5
+ include Rawline
6
+
7
+ puts "*** Readline emulation Test Shell ***"
8
+ puts " * Press CTRL+X to exit"
9
+ puts " * Press <TAB> for file completion"
10
+
11
+ Rawline.editor.bind(:ctrl_x) { puts; puts "Exiting..."; exit }
12
+
13
+ Dir.chdir '..'
14
+
15
+ loop do
16
+ puts "You typed: [#{readline("=> ", true).chomp!}]"
17
+ end
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # editor.rb
@@ -35,7 +35,11 @@ module RawLine
35
35
 
36
36
  include HighLine::SystemExtensions
37
37
 
38
- attr_accessor :char, :history_size, :line_history_size, :terminal, :keys, :word_separator, :mode, :completion_proc, :line, :history, :completion_append_string
38
+ attr_accessor :char, :history_size, :line_history_size
39
+ attr_accessor :terminal, :keys, :mode
40
+ attr_accessor :completion_proc, :line, :history, :completion_append_string
41
+ attr_accessor :match_hidden_files, :completion_matches
42
+ attr_accessor :word_break_characters
39
43
 
40
44
  #
41
45
  # Create an instance of RawLine::Editor which can be used
@@ -43,75 +47,96 @@ module RawLine
43
47
  # This method takes an optional block used to override the
44
48
  # following instance attributes:
45
49
  # * <tt>@history_size</tt> - the size of the editor history buffer (30).
46
- # * <tt>@line_history_size</tt> - the size of the editor line history
47
- # buffer (50).
48
- # * <tt>@keys</tt> - the keys (arrays of character codes)
49
- # bound to specific actions.
50
- # * <tt>@word_separator</tt> - a string used as word separator (' ').
50
+ # * <tt>@line_history_size</tt> - the size of the editor line history buffer (50).
51
+ # * <tt>@keys</tt> - the keys (arrays of character codes) bound to specific actions.
52
+ # * <tt>@word_break_characters</tt> - a string listing all characters which can be used as word separators (" \t\n\"\\'`@$><=;|&{(/").
51
53
  # * <tt>@mode</tt> - The editor's character insertion mode (:insert).
52
54
  # * <tt>@completion_proc</tt> - a Proc object used to perform word completion.
53
- # * <tt>@completion_append_string</tt> - a string to append to completed words.
54
- # * <tt>@terminal</tt> - an RawLine::Terminal containing character key codes.
55
+ # * <tt>@completion_append_string</tt> - a string to append to completed words ('').
56
+ # * <tt>@completion_matches</tt> - word completion candidates.
57
+ # * <tt>@terminal</tt> - a RawLine::Terminal containing character key codes.
55
58
  #
56
59
  def initialize(input=STDIN, output=STDOUT)
57
- @win32_io = Win32::Console::ANSI::IO.new if WIN32CONSOLE
58
60
  @input = input
59
61
  @output = output
60
- case PLATFORM
61
- when /win32/i then
62
+ case RUBY_PLATFORM
63
+ when /mswin/i then
62
64
  @terminal = WindowsTerminal.new
65
+ if RawLine.win32console? then
66
+ @win32_io = Win32::Console::ANSI::IO.new
67
+ end
63
68
  else
64
69
  @terminal = VT220Terminal.new
65
70
  end
66
71
  @history_size = 30
67
72
  @line_history_size = 50
68
73
  @keys = {}
69
- @word_separator = ' '
74
+ @word_break_characters = " \t\n\"\\'`@$><=;|&{(/"
70
75
  @mode = :insert
71
- @completion_proc = []
72
- @completion_append_string = ' '
76
+ @completion_proc = filename_completion_proc
77
+ @completion_append_string = ''
78
+ @match_hidden_files = false
73
79
  @completion_matches = HistoryBuffer.new(0) { |h| h.duplicates = false; h.cycle = true }
74
80
  set_default_keys
75
81
  yield self if block_given?
82
+ update_word_separator
83
+ @add_history = false
76
84
  @history = HistoryBuffer.new(@history_size) do |h|
77
85
  h.duplicates = false;
78
86
  h.exclude = lambda { |item| item.strip == "" }
79
87
  end
80
88
  @char = nil
81
- @newline = true
82
89
  end
83
-
90
+
91
+ #
92
+ # Return the current RawLine version
93
+ #
94
+ def library_version
95
+ "RawLine v#{RawLine.version}"
96
+ end
97
+
84
98
  #
85
99
  # Read characters from <tt>@input</tt> until the user presses ENTER
86
100
  # (use it in the same way as you'd use IO#gets)
87
- # An optional prompt can be specified to be printed at the beginning of the line.
101
+ # * An optional prompt can be specified to be printed at the beginning of the line ("").
102
+ # * An optional flag can be specified to enable/disable editor history (false)
88
103
  #
89
- def read(prompt="")
90
- @newline = true
104
+ def read(prompt="", add_history=false)
105
+ update_word_separator
106
+ @output.print prompt if prompt != ""
107
+ @add_history = add_history
91
108
  @line = Line.new(@line_history_size) do |l|
92
109
  l.prompt = prompt
93
110
  l.word_separator = @word_separator
94
111
  end
95
112
  add_to_line_history
96
113
  loop do
97
- @output.print prompt if @newline
98
- @newline = false
99
114
  read_character
100
115
  process_character
101
116
  break if @char == @terminal.keys[:enter] || !@char
102
117
  end
103
- puts
118
+ @output.print "\n"
104
119
  "#{@line.text}\n"
105
120
  end
106
121
 
107
- #
108
- # Read and parse a character from <tt>@input</tt>.
109
- # This method is called automatically by <tt>read</tt>
110
- #
111
- def read_character
112
- c = get_character(@input)
113
- @char = parse_key_code(c) || c
114
- end
122
+ # Readline compatibility aliases
123
+ alias readline read
124
+ alias completion_append_char completion_append_string
125
+ alias completion_append_char= completion_append_string=
126
+ alias basic_word_break_characters word_break_characters
127
+ alias basic_word_break_characters= word_break_characters=
128
+ alias completer_word_break_characters word_break_characters
129
+ alias completer_word_break_characters= word_break_characters=
130
+
131
+ #
132
+ # Read and parse a character from <tt>@input</tt>.
133
+ # This method is called automatically by <tt>read</tt>
134
+ #
135
+ def read_character
136
+ @output.flush
137
+ c = get_character(@input)
138
+ @char = parse_key_code(c) || c
139
+ end
115
140
 
116
141
  #
117
142
  # Parse a key or key sequence into the corresponding codes.
@@ -142,10 +167,10 @@ module RawLine
142
167
  string.each_byte { |c| print_character c, true }
143
168
  add_to_line_history
144
169
  end
145
-
170
+
146
171
  #
147
172
  # Write a new line to <tt>@output</tt>, overwriting any existing text
148
- # and printing a end of line character.
173
+ # and printing an end of line character.
149
174
  #
150
175
  def write_line(string)
151
176
  clear_line
@@ -179,7 +204,7 @@ module RawLine
179
204
  # * An Array identifying a character or character sequence defined for the current terminal
180
205
  # * A String identifying a character or character sequence, even if it is not defined for the current terminal
181
206
  # * An Hash identifying a character or character sequence, even if it is not defined for the current terminal
182
- #
207
+ #
183
208
  # If <tt>key</tt> is a hash, then:
184
209
  #
185
210
  # * It must contain only one key/value pair
@@ -199,7 +224,11 @@ module RawLine
199
224
  raise BindingException, "Unknown key or key sequence '#{key.to_s}' (#{key.class.to_s})" unless @terminal.keys.has_value? [key]
200
225
  @keys[[key]] = block
201
226
  when 'String' then
202
- bind_hash({:"#{key}" => key}, block)
227
+ if key.length == 1 then
228
+ @keys[[key.ord]] = block
229
+ else
230
+ bind_hash({:"#{key}" => key}, block)
231
+ end
203
232
  when 'Hash' then
204
233
  raise BindingException, "Cannot bind more than one key or key sequence at once" unless key.values.length == 1
205
234
  bind_hash(key, block)
@@ -240,16 +269,15 @@ module RawLine
240
269
  # won't be saved in the history of the current line.
241
270
  #
242
271
  def print_character(char=@char, no_line_history = false)
243
- unless @line.length >= @line.max_length-2
244
- case
245
- when @line.position < @line.length then
272
+ unless @line.length >= @line.max_length-2 then
273
+ if @line.position < @line.length then
246
274
  chars = select_characters_from_cursor if @mode == :insert
247
275
  @output.putc char
248
276
  @line.text[@line.position] = (@mode == :insert) ? "#{char.chr}#{@line.text[@line.position].chr}" : "#{char.chr}"
249
277
  @line.right
250
278
  if @mode == :insert then
251
279
  raw_print chars
252
- chars.length.times { putc ?\b } # move cursor back
280
+ chars.length.times { @output.putc ?\b.ord } # move cursor back
253
281
  end
254
282
  else
255
283
  @output.putc char
@@ -259,7 +287,7 @@ module RawLine
259
287
  add_to_line_history unless no_line_history
260
288
  end
261
289
  end
262
-
290
+
263
291
  #
264
292
  # Complete the current word according to what returned by
265
293
  # <tt>@completion_proc</tt>. Characters can be appended to the
@@ -276,7 +304,7 @@ module RawLine
276
304
  @completion_matches.empty
277
305
  word_start = @line.word[:start]
278
306
  sub_word = @line.text[@line.word[:start]..@line.position-1] || ""
279
- matches = @completion_proc.call(sub_word)
307
+ matches = @completion_proc.call(sub_word) unless @completion_proc == []
280
308
  matches = (matches.is_a?(Array)) ? matches.sort.reverse : []
281
309
  complete_word = lambda do |match|
282
310
  unless @line.word[:text].length == 0
@@ -305,6 +333,25 @@ module RawLine
305
333
  end
306
334
  end
307
335
 
336
+ #
337
+ # Complete file and directory names.
338
+ # Hidden files and directories are matched only if <tt>@match_hidden_files</tt> is true.
339
+ #
340
+ def filename_completion_proc
341
+ lambda do |word|
342
+ dirs = @line.text.split('/')
343
+ path = @line.text.match(/^\/|[a-zA-Z]:\//) ? "/" : Dir.pwd+"/"
344
+ if dirs.length == 0 then # starting directory
345
+ dir = path
346
+ else
347
+ dirs.delete(dirs.last) unless File.directory?(path+dirs.join('/'))
348
+ dir = path+dirs.join('/')
349
+ end
350
+ Dir.entries(dir).select { |e| (e =~ /^\./ && @match_hidden_files && word == '') || (e =~ /^#{word}/ && e !~ /^\./) }
351
+ end
352
+ end
353
+
354
+
308
355
  #
309
356
  # Adds <tt>@line.text</tt> to the editor history. This action is
310
357
  # bound to the enter key by default.
@@ -319,14 +366,14 @@ module RawLine
319
366
  # This action is bound to the left arrow key by default.
320
367
  #
321
368
  def move_left
322
- unless @line.bol?:
323
- @output.putc ?\b
369
+ unless @line.bol? then
370
+ @output.putc ?\b.ord
324
371
  @line.left
325
372
  return true
326
373
  end
327
374
  false
328
375
  end
329
-
376
+
330
377
  #
331
378
  # Move the cursor right (if possible) by re-printing the
332
379
  # character at the right of the cursor, if any, and updating
@@ -334,7 +381,7 @@ module RawLine
334
381
  # This action is bound to the right arrow key by default.
335
382
  #
336
383
  def move_right
337
- unless @line.position > @line.eol:
384
+ unless @line.position > @line.eol then
338
385
  @line.right
339
386
  @output.putc @line.text[@line.position-1]
340
387
  return true
@@ -405,8 +452,8 @@ module RawLine
405
452
  chars = (@line.eol?) ? ' ' : select_characters_from_cursor(1)
406
453
  # remove character from console and shift characters
407
454
  raw_print chars
408
- putc ?\s
409
- (chars.length+1).times { putc ?\b }
455
+ @output.putc ?\s.ord
456
+ (chars.length+1).times { @output.putc ?\b.ord }
410
457
  #remove character from line
411
458
  @line[@line.position] = ''
412
459
  add_to_line_history unless no_line_history
@@ -421,8 +468,8 @@ module RawLine
421
468
  def clear_line
422
469
  @output.putc ?\r
423
470
  print @line.prompt
424
- @line.length.times { putc ?\s }
425
- @line.length.times { putc ?\b }
471
+ @line.length.times { @output.putc ?\s.ord }
472
+ @line.length.times { @output.putc ?\b.ord }
426
473
  add_to_line_history
427
474
  @line.text = ""
428
475
  @line.position = 0
@@ -456,7 +503,7 @@ module RawLine
456
503
  current_line = @line.text.dup
457
504
  # Temporarily override exclusion rules
458
505
  exclude = @history.exclude.dup
459
- @history.exclude = lambda { nil }
506
+ @history.exclude = lambda{|a|}
460
507
  # Add current line
461
508
  @history << current_line
462
509
  @history.exclude = exclude
@@ -489,7 +536,7 @@ module RawLine
489
536
  # Add the current line (<tt>@line.text</tt>) to the editor history.
490
537
  #
491
538
  def add_to_history
492
- @history << @line.text.dup unless @line.text == ""
539
+ @history << @line.text.dup if @add_history && @line.text != ""
493
540
  end
494
541
 
495
542
  #
@@ -510,13 +557,13 @@ module RawLine
510
557
  def overwrite_line(new_line, position=nil)
511
558
  pos = position || new_line.length
512
559
  text = @line.text
513
- putc ?\r
560
+ @output.putc ?\r.ord
514
561
  print @line.prompt
515
562
  raw_print new_line
516
563
  n = text.length-new_line.length+1
517
564
  if n > 0
518
- n.times { putc ?\s }
519
- n.times { putc ?\b }
565
+ n.times { @output.putc ?\s.ord }
566
+ n.times { @output.putc ?\b.ord }
520
567
  end
521
568
  @line.position = new_line.length
522
569
  move_to_position(pos)
@@ -539,9 +586,19 @@ module RawLine
539
586
 
540
587
  private
541
588
 
589
+ def update_word_separator
590
+ chars = []
591
+ @word_break_characters.each_byte do |c|
592
+ ch = (c.is_a? Fixnum) ? c : c.ord
593
+ value = (ch == ?\s.ord) ? ' ' : Regexp.escape(ch.chr).to_s
594
+ chars << value
595
+ end
596
+ @word_separator = /#{chars.join('|')}/
597
+ end
598
+
542
599
  def bind_hash(key, block)
543
600
  key.each_pair do |j,k|
544
- raise BindingException, "'#{k[0].chr}' is not a legal escape code for '#{@terminal.class.to_s}'." unless k.length > 1 && @terminal.escape_codes.include?(k[0])
601
+ raise BindingException, "'#{k[0].chr}' is not a legal escape code for '#{@terminal.class.to_s}'." unless k.length > 1 && @terminal.escape_codes.include?(k[0].ord)
545
602
  code = []
546
603
  case k.class.to_s
547
604
  when 'Fixnum' then
@@ -557,7 +614,7 @@ module RawLine
557
614
  @keys[code] = block
558
615
  end
559
616
  end
560
-
617
+
561
618
  def select_characters_from_cursor(offset=0)
562
619
  select_characters(:right, @line.length-@line.position, offset)
563
620
  end
@@ -589,12 +646,12 @@ module RawLine
589
646
  end
590
647
 
591
648
  def set_default_keys
592
- bind(:return) { newline }
649
+ bind(:enter) { newline }
593
650
  bind(:tab) { complete }
594
651
  bind(:backspace) { delete_left_character }
595
652
  bind(:ctrl_k) { clear_line }
596
- bind(:ctrl_z) { undo }
597
- bind(:ctrl_y) { self.redo }
653
+ bind(:ctrl_u) { undo }
654
+ bind(:ctrl_r) { self.redo }
598
655
  bind(:left_arrow) { move_left }
599
656
  bind(:right_arrow) { move_right }
600
657
  bind(:up_arrow) { history_back }
@@ -605,11 +662,11 @@ module RawLine
605
662
 
606
663
  end
607
664
 
608
- if ANSI then
665
+ if RawLine.ansi? then
609
666
 
610
667
  class Editor
611
-
612
- if WIN32CONSOLE then
668
+
669
+ if RUBY_PLATFORM.match(/mswin/) && RawLine.win32console? then
613
670
  def escape(string)
614
671
  string.each_byte { |c| @win32_io.putc c }
615
672
  end
@@ -621,17 +678,17 @@ module RawLine
621
678
 
622
679
  undef move_left
623
680
  def move_left
624
- unless @line.bol?:
681
+ unless @line.bol? then
625
682
  @line.left
626
683
  escape "\e[D"
627
684
  return true
628
685
  end
629
686
  false
630
687
  end
631
-
688
+
632
689
  undef move_right
633
690
  def move_right
634
- unless @line.position > @line.eol:
691
+ unless @line.position > @line.eol then
635
692
  @line.right
636
693
  escape "\e[C"
637
694
  return true
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # history_buffer.rb
@@ -27,15 +27,13 @@ module RawLine
27
27
  # Create an instance of RawLine::HistoryBuffer.
28
28
  # This method takes an optional block used to override the
29
29
  # following instance attributes:
30
- # * <tt>@duplicates</tt> - whether or not duplicate items will be stored in the
31
- # buffer.
32
- # * <tt>@exclude</tt> - a Proc object defining exclusion rules to prevent items
33
- # from being added to the buffer.
30
+ # * <tt>@duplicates</tt> - whether or not duplicate items will be stored in the buffer.
31
+ # * <tt>@exclude</tt> - a Proc object defining exclusion rules to prevent items from being added to the buffer.
34
32
  # * <tt>@cycle</tt> - Whether or not the buffer is cyclic.
35
33
  #
36
34
  def initialize(size)
37
35
  @duplicates = true
38
- @exclude = lambda { nil }
36
+ @exclude = lambda{|a|}
39
37
  @cycle = false
40
38
  yield self if block_given?
41
39
  @size = size
@@ -90,9 +88,12 @@ module RawLine
90
88
  def back
91
89
  return nil unless length > 0
92
90
  case @position
93
- when nil: @position = length-1
94
- when 0: @position = length-1 if @cycle
95
- else @position -= 1
91
+ when nil then
92
+ @position = length-1
93
+ when 0 then
94
+ @position = length-1 if @cycle
95
+ else
96
+ @position -= 1
96
97
  end
97
98
  end
98
99
 
@@ -102,9 +103,12 @@ module RawLine
102
103
  def forward
103
104
  return nil unless length > 0
104
105
  case @position
105
- when nil: @position = length-1
106
- when length-1: @position = 0 if @cycle
107
- else @position += 1
106
+ when nil then
107
+ @position = length-1
108
+ when length-1 then
109
+ @position = 0 if @cycle
110
+ else
111
+ @position += 1
108
112
  end
109
113
  end
110
114
 
data/lib/rawline/line.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # line.rb
@@ -39,7 +39,6 @@ module RawLine
39
39
  @prompt = ""
40
40
  @word_separator = ' '
41
41
  yield self if block_given?
42
- @words = []
43
42
  @history = RawLine::HistoryBuffer.new(@history_size)
44
43
  @history << "" # Add empty line for complete undo...
45
44
  @offset = @prompt.length
@@ -63,11 +62,15 @@ module RawLine
63
62
  last = @text.index(@word_separator, @position)
64
63
  first = @text.rindex(@word_separator, @position)
65
64
  # Trim word separators and handle EOL and BOL
66
- if first: first +=1
67
- else first = bol
65
+ if first then
66
+ first +=1
67
+ else
68
+ first = bol
68
69
  end
69
- if last: last -=1
70
- else last = eol+1 unless last
70
+ if last then
71
+ last -=1
72
+ else
73
+ last = eol+1 unless last
71
74
  end
72
75
  # Swap if overlapping
73
76
  last, first = first, last if last < first
@@ -84,6 +87,13 @@ module RawLine
84
87
  {:start => first, :end => last, :text => text}
85
88
  end
86
89
 
90
+ #
91
+ # Return an array containing the words present in the current line
92
+ #
93
+ def words
94
+ @text.split @word_separator
95
+ end
96
+
87
97
  #
88
98
  # Return the position corresponding to the beginning of the line.
89
99
  #
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # vt220_terminal.rb
@@ -19,44 +19,44 @@ module RawLine
19
19
 
20
20
  def initialize
21
21
  super
22
- @escape_codes = [?\e]
22
+ @escape_codes = [?\e.ord]
23
23
  @keys.merge!(
24
24
  {
25
- :up_arrow => [?\e, ?[, ?A],
26
- :down_arrow => [?\e, ?[, ?B],
27
- :right_arrow => [?\e, ?[, ?C],
28
- :left_arrow => [?\e, ?[, ?D],
29
- :insert => [?\e, ?[, ?2, ?~],
30
- :delete => [?\e, ?[, ?3, ?~],
31
- :backspace => [?\C-?],
32
- :enter => [?\n],
25
+ :up_arrow => [?\e.ord, ?[.ord, ?A.ord],
26
+ :down_arrow => [?\e.ord, ?[.ord, ?B.ord],
27
+ :right_arrow => [?\e.ord, ?[.ord, ?C.ord],
28
+ :left_arrow => [?\e.ord, ?[.ord, ?D.ord],
29
+ :insert => [?\e.ord, ?[, ?2.ord, ?~.ord],
30
+ :delete => [?\e.ord, ?[, ?3.ord, ?~.ord],
31
+ :backspace => [?\C-?.ord],
32
+ :enter => (HighLine::SystemExtensions::CHARACTER_MODE == 'termios' ? [?\n.ord] : [?\r]),
33
33
 
34
- :ctrl_alt_a => [?\e, ?\C-a],
35
- :ctrl_alt_b => [?\e, ?\C-b],
36
- :ctrl_alt_c => [?\e, ?\C-c],
37
- :ctrl_alt_d => [?\e, ?\C-d],
38
- :ctrl_alt_e => [?\e, ?\C-e],
39
- :ctrl_alt_f => [?\e, ?\C-f],
40
- :ctrl_alt_g => [?\e, ?\C-g],
41
- :ctrl_alt_h => [?\e, ?\C-h],
42
- :ctrl_alt_i => [?\e, ?\C-i],
43
- :ctrl_alt_j => [?\e, ?\C-j],
44
- :ctrl_alt_k => [?\e, ?\C-k],
45
- :ctrl_alt_l => [?\e, ?\C-l],
46
- :ctrl_alt_m => [?\e, ?\C-m],
47
- :ctrl_alt_n => [?\e, ?\C-n],
48
- :ctrl_alt_o => [?\e, ?\C-o],
49
- :ctrl_alt_p => [?\e, ?\C-p],
50
- :ctrl_alt_q => [?\e, ?\C-q],
51
- :ctrl_alt_r => [?\e, ?\C-r],
52
- :ctrl_alt_s => [?\e, ?\C-s],
53
- :ctrl_alt_t => [?\e, ?\C-t],
54
- :ctrl_alt_u => [?\e, ?\C-u],
55
- :ctrl_alt_v => [?\e, ?\C-v],
56
- :ctrl_alt_w => [?\e, ?\C-w],
57
- :ctrl_alt_x => [?\e, ?\C-x],
58
- :ctrl_alt_y => [?\e, ?\C-y],
59
- :ctrl_alt_z => [?\e, ?\C-z]
34
+ :ctrl_alt_a => [?\e.ord, ?\C-a.ord],
35
+ :ctrl_alt_b => [?\e.ord, ?\C-b.ord],
36
+ :ctrl_alt_c => [?\e.ord, ?\C-c.ord],
37
+ :ctrl_alt_d => [?\e.ord, ?\C-d.ord],
38
+ :ctrl_alt_e => [?\e.ord, ?\C-e.ord],
39
+ :ctrl_alt_f => [?\e.ord, ?\C-f.ord],
40
+ :ctrl_alt_g => [?\e.ord, ?\C-g.ord],
41
+ :ctrl_alt_h => [?\e.ord, ?\C-h.ord],
42
+ :ctrl_alt_i => [?\e.ord, ?\C-i.ord],
43
+ :ctrl_alt_j => [?\e.ord, ?\C-j.ord],
44
+ :ctrl_alt_k => [?\e.ord, ?\C-k.ord],
45
+ :ctrl_alt_l => [?\e.ord, ?\C-l.ord],
46
+ :ctrl_alt_m => [?\e.ord, ?\C-m.ord],
47
+ :ctrl_alt_n => [?\e.ord, ?\C-n.ord],
48
+ :ctrl_alt_o => [?\e.ord, ?\C-o.ord],
49
+ :ctrl_alt_p => [?\e.ord, ?\C-p.ord],
50
+ :ctrl_alt_q => [?\e.ord, ?\C-q.ord],
51
+ :ctrl_alt_r => [?\e.ord, ?\C-r.ord],
52
+ :ctrl_alt_s => [?\e.ord, ?\C-s.ord],
53
+ :ctrl_alt_t => [?\e.ord, ?\C-t.ord],
54
+ :ctrl_alt_u => [?\e.ord, ?\C-u.ord],
55
+ :ctrl_alt_v => [?\e.ord, ?\C-v.ord],
56
+ :ctrl_alt_w => [?\e.ord, ?\C-w.ord],
57
+ :ctrl_alt_x => [?\e.ord, ?\C-x.ord],
58
+ :ctrl_alt_y => [?\e.ord, ?\C-y.ord],
59
+ :ctrl_alt_z => [?\e.ord, ?\C-z.ord]
60
60
  })
61
61
  end
62
62
 
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # windows_terminal.rb
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # terminal.rb
@@ -31,37 +31,37 @@ module RawLine
31
31
  def initialize
32
32
  @keys =
33
33
  {
34
- :tab => [?\t],
35
- :return => [?\r],
36
- :newline => [?\n],
37
- :escape => [?\e],
34
+ :tab => [?\t.ord],
35
+ :return => [?\r.ord],
36
+ :newline => [?\n.ord],
37
+ :escape => [?\e.ord],
38
38
 
39
- :ctrl_a => [?\C-a],
40
- :ctrl_b => [?\C-b],
41
- :ctrl_c => [?\C-c],
42
- :ctrl_d => [?\C-d],
43
- :ctrl_e => [?\C-e],
44
- :ctrl_f => [?\C-f],
45
- :ctrl_g => [?\C-g],
46
- :ctrl_h => [?\C-h],
47
- :ctrl_i => [?\C-i],
48
- :ctrl_j => [?\C-j],
49
- :ctrl_k => [?\C-k],
50
- :ctrl_l => [?\C-l],
51
- :ctrl_m => [?\C-m],
52
- :ctrl_n => [?\C-n],
53
- :ctrl_o => [?\C-o],
54
- :ctrl_p => [?\C-p],
55
- :ctrl_q => [?\C-q],
56
- :ctrl_r => [?\C-r],
57
- :ctrl_s => [?\C-s],
58
- :ctrl_t => [?\C-t],
59
- :ctrl_u => [?\C-u],
60
- :ctrl_v => [?\C-v],
61
- :ctrl_w => [?\C-w],
62
- :ctrl_x => [?\C-x],
63
- :ctrl_y => [?\C-y],
64
- :ctrl_z => [?\C-z]
39
+ :ctrl_a => [?\C-a.ord],
40
+ :ctrl_b => [?\C-b.ord],
41
+ :ctrl_c => [?\C-c.ord],
42
+ :ctrl_d => [?\C-d.ord],
43
+ :ctrl_e => [?\C-e.ord],
44
+ :ctrl_f => [?\C-f.ord],
45
+ :ctrl_g => [?\C-g.ord],
46
+ :ctrl_h => [?\C-h.ord],
47
+ :ctrl_i => [?\C-i.ord],
48
+ :ctrl_j => [?\C-j.ord],
49
+ :ctrl_k => [?\C-k.ord],
50
+ :ctrl_l => [?\C-l.ord],
51
+ :ctrl_m => [?\C-m.ord],
52
+ :ctrl_n => [?\C-n.ord],
53
+ :ctrl_o => [?\C-o.ord],
54
+ :ctrl_p => [?\C-p.ord],
55
+ :ctrl_q => [?\C-q.ord],
56
+ :ctrl_r => [?\C-r.ord],
57
+ :ctrl_s => [?\C-s.ord],
58
+ :ctrl_t => [?\C-t.ord],
59
+ :ctrl_u => [?\C-u.ord],
60
+ :ctrl_v => [?\C-v.ord],
61
+ :ctrl_w => [?\C-w.ord],
62
+ :ctrl_x => [?\C-x.ord],
63
+ :ctrl_y => [?\C-y.ord],
64
+ :ctrl_z => [?\C-z.ord]
65
65
  }
66
66
  @escape_codes = []
67
67
  @escape_sequences = []
data/lib/rawline.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!usr/bin/env ruby
2
2
 
3
3
  #
4
4
  # RawLine.rb
@@ -9,24 +9,111 @@
9
9
  # This is Free Software. See LICENSE for details.
10
10
  #
11
11
 
12
+ require "rubygems"
13
+
14
+ #
15
+ # The RawLine (or Rawline) module can be used in the same way
16
+ # as the Readline one.
17
+ #
18
+ # <tt>require 'rawline'</tt>
19
+ # <tt>include Rawline</tt>
20
+ #
21
+ # You'll get...
22
+ #
23
+ # * <tt>readline(prompt="", add_history=false)</tt> - to read characters from $stdin
24
+ # * <tt>Rawline::HISTORY</tt> - to access line history (an instance of RawLine::HistoryBuffer)
25
+ # * <tt>Rawline::FILENAME_COMPLETION_PROC</tt> - a Proc object used for filename completion
26
+ # * <tt>Rawline.completion_proc</tt> - the Proc object used for TAB completion (defaults to FILENAME_COMPLETION_PROC).
27
+ # * <tt>Rawline.completion_matches</tt> - an array of completion matches.
28
+ # * <tt>Rawline.completion_append_char</tt> - a character to append after a successful completion.
29
+ # * <tt>Rawline.basic_word_break_characters</tt> - a String listing all the characters used as word separators.
30
+ # * <tt>Rawline.completer_word_break_characters</tt> - same as above.
31
+ # * <tt>Rawline.library_version</tt> - the current version of the Rawline library.
32
+ # * <tt>Rawline.clear_history</tt> - to clear the current history.
33
+ # * <tt>Rawline.match_hidden_files</tt> - whether FILENAME_COMPLETION_PROC matches hidden files and folders or not.
34
+ #
35
+ # And also <tt>Rawline.editor</tt>, an instance of RawLine::Editor which can be used for anything you like.
36
+ #
12
37
  module RawLine
13
- HOME = File.dirname(File.expand_path(__FILE__))
14
- class BindingException < Exception; end
15
- begin
16
- WIN32CONSOLE = require "win32console" if PLATFORM.match(/win32/i)
17
- ANSI = true
18
- rescue
19
- ANSI = false
38
+
39
+ def self.rawline_version
40
+ "0.3.0"
41
+ end
42
+
43
+ class BindingException < RuntimeError; end
44
+
45
+ if RUBY_PLATFORM.match(/mswin/i) then
46
+ begin
47
+ def self.win32console?; true; end
48
+ def self.ansi?; true; end
49
+ rescue Exception
50
+ def self.win32console?; false; end
51
+ def self.ansi?; false; end
52
+ end
53
+ else # Unix-like
54
+ def self.ansi?; true; end
20
55
  end
21
56
  end
22
57
 
23
- require "rubygems"
58
+ Rawline = RawLine
59
+
60
+ dir = File.dirname(File.expand_path(__FILE__))
24
61
  require "highline"
25
- require "#{RawLine::HOME}/RawLine/terminal"
26
- require "#{RawLine::HOME}/RawLine/terminal/windows_terminal"
27
- require "#{RawLine::HOME}/RawLine/terminal/vt220_terminal"
28
- require "#{RawLine::HOME}/RawLine/history_buffer"
29
- require "#{RawLine::HOME}/RawLine/line"
30
- require "#{RawLine::HOME}/RawLine/editor"
62
+ require "#{dir}/rawline/terminal"
63
+ require "#{dir}/rawline/terminal/windows_terminal"
64
+ require "#{dir}/rawline/terminal/vt220_terminal"
65
+ require "#{dir}/rawline/history_buffer"
66
+ require "#{dir}/rawline/line"
67
+ require "#{dir}/rawline/editor"
68
+
69
+ module RawLine
70
+ self.instance_eval do
71
+ class << self; attr_accessor :editor, :implemented_methods; end
72
+ @editor = RawLine::Editor.new
73
+
74
+ @implemented_methods =
75
+ [
76
+ :completion_proc,
77
+ :completion_proc=,
78
+ :completion_matches,
79
+ :completion_append_char,
80
+ :completion_append_char=,
81
+ :basic_word_break_characters,
82
+ :basic_word_break_characters=,
83
+ :completer_word_break_characters,
84
+ :completer_word_break_characters=,
85
+ :library_version,
86
+ :clear_history,
87
+ :match_hidden_files,
88
+ :match_hidden_files=
89
+ ]
90
+
91
+ self.module_eval do
92
+ HISTORY = RawLine.editor.history
93
+ FILENAME_COMPLETION_PROC = RawLine.editor.filename_completion_proc
31
94
 
95
+ def readline(prompt="", add_history=false)
96
+ RawLine.editor.read prompt, add_history
97
+ end
32
98
 
99
+ alias rawline readline
100
+ end
101
+
102
+ @implemented_methods.each do |meth|
103
+ self.class.module_eval do
104
+ define_method meth do |*args|
105
+ case args.length
106
+ when 0 then
107
+ @editor.send(meth)
108
+ when 1 then
109
+ @editor.send(meth, args[0])
110
+ else
111
+ raise ArgumentError, "There are no Readline methods with more than one parameter"
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ end
@@ -1,20 +1,18 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!/usr/bin/env ruby
2
2
 
3
- module RawLine
4
- TEST_HOME = File.dirname(File.expand_path(__FILE__))+'/..' unless const_defined?(:TEST_HOME)
5
- end
3
+ dir = File.dirname(File.expand_path(__FILE__))+'/..'
6
4
 
7
5
  require 'highline/system_extensions'
8
6
 
9
7
  module HighLine::SystemExtensions
10
8
  # Override Windows' character reading so it's not tied to STDIN.
11
9
  def get_character( input = STDIN )
12
- input.getc
10
+ input.getbyte
13
11
  end
14
12
  end
15
13
 
16
14
  require 'stringio'
17
- require "#{RawLine::TEST_HOME}/lib/RawLine"
15
+ require "#{dir}/lib/rawline"
18
16
 
19
17
  describe RawLine::Editor do
20
18
 
@@ -29,7 +27,7 @@ describe RawLine::Editor do
29
27
  @input.rewind
30
28
  @editor.read
31
29
  @editor.line.text.should == "test #1"
32
- @output.string.should == "test #1"
30
+ @output.string.should == "test #1\n"
33
31
  end
34
32
 
35
33
  it "can bind keys to code blocks" do
@@ -38,23 +36,23 @@ describe RawLine::Editor do
38
36
  @editor.bind(21) { "test #2c" }
39
37
  @editor.bind([22]) { "test #2d" }
40
38
  @editor.terminal.escape_codes = [] # remove any existing escape codes
41
- lambda {@editor.bind({:test => [?\e, ?t, ?e, ?s, ?t]}) { "test #2e" }}.should raise_error(RawLine::BindingException)
42
- @editor.terminal.escape_codes << ?\e
39
+ lambda {@editor.bind({:test => [?\e.ord, ?t.ord, ?e.ord, ?s.ord, ?t.ord]}) { "test #2e" }}.should raise_error(RawLine::BindingException)
40
+ @editor.terminal.escape_codes << ?\e.ord
43
41
  lambda {@editor.bind({:test => "\etest"}) { "test #2e" }}.should_not raise_error(RawLine::BindingException)
44
42
  lambda {@editor.bind("\etest2") { "test #2f" }}.should_not raise_error(RawLine::BindingException)
45
43
  @input << ?\C-w.chr
46
44
  @input.rewind
47
45
  @editor.read
48
46
  @editor.line.text.should == "test #2a"
49
- @editor.char = [?\C-q]
47
+ @editor.char = [?\C-q.ord]
50
48
  @editor.press_key.should == "test #2b"
51
- @editor.char = [?\C-u]
49
+ @editor.char = [?\C-u.ord]
52
50
  @editor.press_key.should == "test #2c"
53
- @editor.char = [?\C-v]
51
+ @editor.char = [?\C-v.ord]
54
52
  @editor.press_key.should == "test #2d"
55
- @editor.char = [?\e, ?t, ?e, ?s, ?t]
53
+ @editor.char = [?\e.ord, ?t.ord, ?e.ord, ?s.ord, ?t.ord]
56
54
  @editor.press_key.should == "test #2e"
57
- @editor.char = [?\e, ?t, ?e, ?s, ?t, ?2]
55
+ @editor.char = [?\e.ord, ?t.ord, ?e.ord, ?s.ord, ?t.ord, ?2.ord]
58
56
  @editor.press_key.should == "test #2f"
59
57
  end
60
58
 
@@ -103,19 +101,19 @@ describe RawLine::Editor do
103
101
  it "supports history" do
104
102
  @input << "test #7a"
105
103
  @input.rewind
106
- @editor.read
104
+ @editor.read "", true
107
105
  @editor.newline
108
106
  @input << "test #7b"
109
107
  @input.pos = 8
110
- @editor.read
108
+ @editor.read "", true
111
109
  @editor.newline
112
110
  @input << "test #7c"
113
111
  @input.pos = 16
114
- @editor.read
112
+ @editor.read "", true
115
113
  @editor.newline
116
114
  @input << "test #7d"
117
115
  @input.pos = 24
118
- @editor.read
116
+ @editor.read "", true
119
117
  @editor.newline
120
118
  @editor.history_back
121
119
  @editor.line.text.should == "test #7c"
@@ -138,7 +136,7 @@ describe RawLine::Editor do
138
136
  @editor.completion_append_string = "\t"
139
137
  @editor.bind(:tab) { @editor.complete }
140
138
  @editor.completion_proc = lambda do |word|
141
- if word
139
+ if word then
142
140
  ['select', 'update', 'delete', 'debug', 'destroy'].find_all { |e| e.match(/^#{Regexp.escape(word)}/) }
143
141
  end
144
142
  end
@@ -159,9 +157,9 @@ describe RawLine::Editor do
159
157
  @input << "test 0"
160
158
  @editor.terminal.keys[:left_arrow].each { |k| @input << k.chr }
161
159
  @input << "#1"
162
- @input.pos = 10
160
+ @input.rewind
163
161
  @editor.read
164
- @editor.line.text.should == "test #1"
162
+ @editor.line.text.should == "test #1test #1"
165
163
  end
166
164
 
167
165
 
@@ -1,10 +1,8 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!/usr/bin/env ruby
2
2
 
3
- module RawLine
4
- TEST_HOME = File.dirname(File.expand_path(__FILE__))+'/..' unless const_defined?(:TEST_HOME)
5
- end
3
+ dir = File.dirname(File.expand_path(__FILE__))+'/..'
6
4
 
7
- require "#{RawLine::TEST_HOME}/lib/RawLine/history_buffer"
5
+ require "#{dir}/lib/rawline/history_buffer"
8
6
 
9
7
  describe RawLine::HistoryBuffer do
10
8
 
@@ -13,7 +11,7 @@ describe RawLine::HistoryBuffer do
13
11
  end
14
12
 
15
13
  it "instantiates an empty array when created" do
16
- @history.length.should == 0
14
+ @history.length.should == 0
17
15
  end
18
16
 
19
17
  it "allows items to be added to the history" do
@@ -27,7 +25,7 @@ describe RawLine::HistoryBuffer do
27
25
  @history << "line #3"
28
26
  @history.should == ["line #1", "line #3", "line #2", "line #3"]
29
27
  @history.exclude = lambda { |i| i.match(/line #[456]/) }
30
- @history << "line #4"
28
+ @history << "line #4"
31
29
  @history << "line #5"
32
30
  @history << "line #6"
33
31
  @history.should == ["line #1", "line #3", "line #2", "line #3"]
@@ -107,7 +105,4 @@ describe RawLine::HistoryBuffer do
107
105
  @history.size.should == 6
108
106
  @history.position.should == nil
109
107
  end
110
-
111
108
  end
112
-
113
-
@@ -1,13 +1,12 @@
1
- #!/usr/local/bin/ruby -w
1
+ #!/usr/bin/env ruby
2
2
 
3
- module RawLine
4
- TEST_HOME = File.dirname(File.expand_path(__FILE__))+'/..' unless const_defined?(:TEST_HOME)
5
- end
3
+ dir = File.dirname(File.expand_path(__FILE__))+'/..'
6
4
 
5
+ require 'rubygems'
7
6
  require 'highline'
8
7
 
9
- require "#{RawLine::TEST_HOME}/lib/RawLine/history_buffer"
10
- require "#{RawLine::TEST_HOME}/lib/RawLine/line"
8
+ require "#{dir}/lib/rawline/history_buffer"
9
+ require "#{dir}/lib/rawline/line"
11
10
 
12
11
  describe RawLine::Line do
13
12
 
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ dir = File.dirname(File.expand_path(__FILE__))
4
+ require "#{dir}/history_buffer_spec"
5
+ require "#{dir}/line_spec"
6
+ require "#{dir}/editor_spec"
metadata CHANGED
@@ -1,76 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: rawline
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2008-04-01 00:00:00 +02:00
8
- summary: A library for definign custom key bindings and perform line editing operations
9
- require_paths:
10
- - lib
11
- email: h3rald@h3rald.com
12
- homepage: http://rubyforge.org/projects/rawline
13
- rubyforge_project: inline
14
- description: RawLine can be used to define custom key bindings, perform common line editing operations, manage command history and define custom command completion rules.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.3.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Fabio Cevasco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-01 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: highline
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.0
24
+ version:
25
+ description: RawLine can be used to define custom key bindings, perform common line editing operations, manage command history and define custom command completion rules.
26
+ email: h3rald@h3rald.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ - LICENSE
34
+ - CHANGELOG.rdoc
31
35
  files:
36
+ - lib/rawline.rb
32
37
  - lib/rawline
33
- - lib/rawline/editor.rb
34
38
  - lib/rawline/history_buffer.rb
39
+ - lib/rawline/terminal.rb
40
+ - lib/rawline/editor.rb
35
41
  - lib/rawline/line.rb
36
42
  - lib/rawline/terminal
37
- - lib/rawline/terminal/vt220_terminal.rb
38
43
  - lib/rawline/terminal/windows_terminal.rb
39
- - lib/rawline/terminal.rb
40
- - lib/rawline.rb
44
+ - lib/rawline/terminal/vt220_terminal.rb
45
+ - examples/readline_emulation.rb
41
46
  - examples/key_tester.rb
42
47
  - examples/rawline_shell.rb
43
- - test/test_all.rb
44
- - test/test_editor.rb
45
- - test/test_history_buffer.rb
46
- - test/test_line.rb
47
- - README
48
+ - spec/history_buffer_spec.rb
49
+ - spec/line_spec.rb
50
+ - spec/rawline_spec.rb
51
+ - spec/editor_spec.rb
52
+ - README.rdoc
48
53
  - LICENSE
49
- - CHANGELOG
50
- test_files:
51
- - test/test_all.rb
54
+ - CHANGELOG.rdoc
55
+ has_rdoc: true
56
+ homepage: http://rubyforge.org/projects/rawline
57
+ post_install_message:
52
58
  rdoc_options:
53
59
  - --main
54
- - README
60
+ - README.rdoc
55
61
  - --exclude
56
- - test
57
- extra_rdoc_files:
58
- - README
59
- - LICENSE
60
- - CHANGELOG
61
- executables: []
62
-
63
- extensions: []
64
-
62
+ - spec
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
65
77
  requirements: []
66
78
 
67
- dependencies:
68
- - !ruby/object:Gem::Dependency
69
- name: highline
70
- version_requirement:
71
- version_requirements: !ruby/object:Gem::Version::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: 1.4.0
76
- version:
79
+ rubyforge_project: rawline
80
+ rubygems_version: 1.2.0
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: A library for defining custom key bindings and perform line editing operations
84
+ test_files:
85
+ - spec/rawline_spec.rb
data/CHANGELOG DELETED
@@ -1,13 +0,0 @@
1
- == Version 0.2.0
2
-
3
- * Added /examples and /test directory to gem.
4
- * Escape codes can now be used in prompt.
5
- * It is now possible to use bind(key, &block) with a String as key, even if the corresponding escape sequence is not defined.
6
- * Added Editor#write_line(string) to print a any string (and "hit return").
7
- * Library name changed to "RawLine" to avoid name collision issues (Bug 18879: http://rubyforge.org/tracker/?func=detail&aid=18879&group_id=5622&atid=21788).
8
- * Provided alternative implementation for left and right arrows if terminal
9
- supports escape sequences (on Windows, it requires the Win32Console gem).
10
-
11
- == Version 0.1.0
12
-
13
- First preview release of InLine, implementing some of the functionality provided by the ReadLine library such as basic line editing, history and word completion.
data/test/test_all.rb DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- module RawLine
4
- TEST_HOME = File.dirname(File.expand_path(__FILE__))+'/..' unless const_defined?(:TEST_HOME)
5
- end
6
-
7
- require "test_history_buffer"
8
- require "test_line"
9
- require "test_editor"