mini_readline 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af31e49431ef4c0e691617e54b7a49682f0ff54c
4
- data.tar.gz: 2d8eec7c4e57644c35e8c48eb64f59de7eaa0be7
3
+ metadata.gz: 9f85684d28ccc8db527dfffaa18a44cacc0d895a
4
+ data.tar.gz: 10ab8d5a4e563e544b421348932e9955db9e2ba5
5
5
  SHA512:
6
- metadata.gz: faa8d05392d4f11c966b5a3e803701a4e6830f2e734ce75907563642d3f5985baec7d44db4c3534b04156b2da7091f4bc588074358f287e888f530dc5e3e754a
7
- data.tar.gz: 6473692e2bfa5b592e64dd30afb51ec6314690de7ebeb91dc622a6f23f029027a913a5a7440a1edae0a3d2c11d7272a64a00b8bc6117cecebee7172933b40bde
6
+ metadata.gz: 6066051c11226c1910cffc07230c43c222968f52bd48589b6f2f40688ad88e51e1e51cc42880fe68f6d8a4df4658a71eefe047807ae57a67c8e153121d765515
7
+ data.tar.gz: d8c18d10e928dadb05d629f8a0957b679a78d51642c7312f7667dbd6092728bc8dcb142fa2f5e72dfe26473284921765d4d58332c7c2c38082093c6286548fc5
data/README.md CHANGED
@@ -180,17 +180,21 @@ BASE_OPTIONS = {
180
180
 
181
181
  <br>While most of these options are self explanatory, a few could stand some
182
182
  further description:
183
+ * :prompt is the standard prompt used when text is not scrolled.
183
184
  * :alt_prompt is the prompt used when the text must be scrolled to fit on the
184
185
  screen. If this is set to nil, then the main prompt is always used.
186
+ <br>Both the prompt and alt_prompt may contain ANSI terminal control sequences.
187
+ These are restricted, however, to those commands that do not alter the position
188
+ of the cursor. So basically colors, highlighting, etc.
185
189
  * :auto_complete is disabled by default. Of course there are a number of ways
186
190
  to enable it, or to make auto-complete enabled the default use:
187
191
  ```ruby
188
192
  require 'mini_readline'
189
193
  MiniReadline::BASE_OPTION[:auto_complete] = true
190
194
  ```
191
- * :auto_source is the class of the source for auto-complete data. By default this
192
- is MiniReadline::QuotedFileFolderSource. This option can be changed up to get
193
- auto-complete data other than files and folders. See Auto-Compete below for
195
+ * :auto_source is the class of the source for auto-complete data. By default
196
+ this is MiniReadline::QuotedFileFolderSource. This option can be changed up to
197
+ get auto-complete data other than files and folders. See Auto-Compete below for
194
198
  more details.
195
199
  * :eoi_detect is used to control the end of input detection logic. If disabled,
196
200
  eoi inputs are treated as unmapped. If enabled, they raise a MiniReadlineEOI
@@ -261,7 +265,7 @@ the initialize, rebuild, and next methods.
261
265
 
262
266
  end
263
267
  ```
264
- To enable the use of a custom auto-completer, three things mst be done:
268
+ To enable the use of a custom auto-completer, three things must be done:
265
269
  * The option[:auto_complete] must be set to true
266
270
  * The option[:auto_source] must be set to the class name of the new completer.
267
271
  * Any optional, additional options required by the completer must be set.
@@ -325,7 +329,8 @@ To date this code has been tested under:
325
329
  * Windows 7 with ruby 2.1.6p336 (2015-04-13 revision 50298) [i386-mingw32]
326
330
  * Windows 7+Cygwin with ruby 2.2.3p173 (2015-08-18 revision 51636) [i386-cygwin]
327
331
 
328
- <br>**More testing is clearly called for and suggestions/bug reports are most welcomed!!!**
332
+ <br>**More testing is clearly called for and suggestions/bug reports are most
333
+ welcomed!!!**
329
334
 
330
335
  ## Contributing
331
336
 
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
+ require_relative 'read_line/prompt'
3
4
  require_relative 'read_line/edit'
4
5
  require_relative 'read_line/history'
5
6
  require_relative 'read_line/no_history'
@@ -63,18 +64,18 @@ module MiniReadline
63
64
 
64
65
  #Set up the prompt.
65
66
  def set_prompt(prompt)
66
- @options[:base_prompt] = prompt
67
- @options[:scroll_prompt] = @options[:alt_prompt] || prompt
67
+ @options[:base_prompt] = Prompt.new(prompt)
68
+ @options[:scroll_prompt] = Prompt.new(@options[:alt_prompt] || prompt)
68
69
 
69
70
  verify_prompt(@options[:base_prompt])
70
71
  verify_prompt(@options[:scroll_prompt])
71
72
  end
72
73
 
73
74
  #Verify that the prompt will fit!
74
- def verify_prompt(str)
75
- unless (@options[:window_width] - str.length) >
75
+ def verify_prompt(prompt)
76
+ unless (@options[:window_width] - prompt.length) >
76
77
  (@options[:scroll_step] * 2)
77
- fail "Prompt too long: #{str.inspect}"
78
+ fail "Too long: #{prompt.inspect}"
78
79
  end
79
80
  end
80
81
  end
@@ -16,7 +16,7 @@ module MiniReadline
16
16
  @scroll_width = window_width - @options[:scroll_prompt].length
17
17
  @term = @options[:term]
18
18
 
19
- @left_margin, @window_buffer = 0, ""
19
+ @left_margin, @window_buffer, @show_prompt = 0, "", true
20
20
  end
21
21
 
22
22
  #What is the offset of the window's left margin?
@@ -8,7 +8,11 @@ module MiniReadline
8
8
 
9
9
  #Keep the edit window in sync!
10
10
  def sync_window(edit_buffer, edit_posn)
11
- window_buffer.clear unless check_margins(edit_buffer.length, edit_posn)
11
+ unless check_margins(edit_buffer.length, edit_posn)
12
+ window_buffer.clear
13
+ @show_prompt = true
14
+ end
15
+
12
16
  image = build_screen_image(edit_buffer)
13
17
  update_screen(image)
14
18
  @window_buffer = image
@@ -31,14 +35,19 @@ module MiniReadline
31
35
 
32
36
  #Compute what should be on the screen.
33
37
  def build_screen_image(edit_buffer)
34
- prompt + edit_buffer[left_margin..right_margin].ljust(window_width)
38
+ edit_buffer[left_margin..right_margin].ljust(active_width)
35
39
  end
36
40
 
37
41
  #Bring the screen into agreement with the image.
38
42
  def update_screen(image)
39
- (0...window_width).each do |index|
43
+ if @show_prompt
44
+ @term.put_string("\r#{prompt.text}\r")
45
+ @show_prompt = false
46
+ end
47
+
48
+ (0...active_width).each do |index|
40
49
  if (image_char = image[index]) != window_buffer[index]
41
- @term.set_posn(index)
50
+ @term.set_posn(prompt.length + index)
42
51
  @term.put_string(image_char)
43
52
  end
44
53
  end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+
3
+ #Support for the specialized prompt string class.
4
+ module MiniReadline
5
+
6
+ #A class used to hold prompt strings that may contain ANSI terminal
7
+ #control embellishments.
8
+ class Prompt
9
+
10
+ #Get the text.
11
+ attr_reader :text
12
+
13
+ #Get the length without ANSI sequences.
14
+ attr_reader :length
15
+
16
+ def initialize(text)
17
+ @text = text
18
+ @length = text.gsub(/\x1B\[(\d|;)*[@-~]/, "").length
19
+ end
20
+
21
+ #Inspect the prompt
22
+ def inspect
23
+ "<Prompt: #{@text.inspect}>"
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -1,4 +1,4 @@
1
1
  module MiniReadline
2
2
  #The current version of the mini_readline gem.
3
- VERSION = "0.3.3"
3
+ VERSION = "0.4.0"
4
4
  end
data/sire.rb CHANGED
@@ -105,7 +105,7 @@ class SIRE
105
105
  puts "Use the command 'q' to quit.\n\n"
106
106
 
107
107
  until @_done
108
- exec_line(Readline.readline('SIRE>', true))
108
+ exec_line(Readline.readline("\e[7mSIRE>\e[0m", true))
109
109
  end
110
110
 
111
111
  puts "\n\n"
@@ -85,7 +85,7 @@ class MiniReadlineTester < Minitest::Test
85
85
  auto_source: MiniReadline::ArraySource,
86
86
  array_src: fruit)
87
87
 
88
- result = edit.readline(prompt: "Fruit: ")
88
+ result = edit.readline(prompt: "\e[7mFruit:\e[0m ")
89
89
  assert(fruit.include?(result))
90
90
  end
91
91
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_readline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-18 00:00:00.000000000 Z
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -119,6 +119,7 @@ files:
119
119
  - lib/mini_readline/read_line/edit/word_right.rb
120
120
  - lib/mini_readline/read_line/history.rb
121
121
  - lib/mini_readline/read_line/no_history.rb
122
+ - lib/mini_readline/read_line/prompt.rb
122
123
  - lib/mini_readline/version.rb
123
124
  - mini_readline.gemspec
124
125
  - mini_readline.reek