readline-ng 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/readline-ng.rb +20 -9
  2. metadata +1 -1
@@ -2,7 +2,7 @@ module ReadlineNG
2
2
 
3
3
  VERSION_MAJOR = 0
4
4
  VERSION_MINOR = 0
5
- VERSION_PATCH = 1
5
+ VERSION_PATCH = 2
6
6
  VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
7
7
 
8
8
  CONTROL_BS = "\x08"
@@ -11,11 +11,14 @@ module ReadlineNG
11
11
  CONTROL_CR = "\x0d"
12
12
 
13
13
  KB_BS = "\x7F"
14
+ KB_CR = "\x0d"
14
15
 
15
16
  BLANK = " "
16
17
 
17
18
  class Reader
18
19
 
20
+ @@initialized = false
21
+
19
22
  # TODO Arrange for the terminal to be in raw mode etc.
20
23
  # XXX This probably needs to be a singleton, having more than one doesn't
21
24
  # make a whole lot of sense, although potentially giving out rope is not a
@@ -26,18 +29,26 @@ module ReadlineNG
26
29
  def filter
27
30
  end
28
31
 
29
- def initialize
32
+ def initialize(visible=true)
30
33
  @buf = ""
31
- @visible = true
34
+ @visible = visible
32
35
  @lines = []
36
+ if @@initialized
37
+ STDERR.puts "A ReadlineNG reader is already instanciated, expect weirdness"
38
+ else
39
+ @@initialized = true
40
+ end
41
+
42
+ stty_saved = `stty -g`
43
+ `stty -echo raw`
44
+ at_exit do
45
+ `stty #{stty_saved}`
46
+ end
33
47
  end
34
48
 
35
49
  def puts_above(string)
36
50
  if visible
37
- @buf.length.times do
38
- # Backspace to beginning of line
39
- _print CONTROL_BS
40
- end
51
+ backspace(@buf.length)
41
52
  _print string
42
53
  _puts CONTROL_CR
43
54
  _print @buf
@@ -81,8 +92,8 @@ module ReadlineNG
81
92
  end
82
93
  end
83
94
 
84
- def backspace
85
- print CONTROL_BS,BLANK,CONTROL_BS
95
+ def backspace(n=1)
96
+ print CONTROL_BS*n,BLANK*n,CONTROL_BS*n
86
97
  end
87
98
 
88
99
  def _print(c)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readline-ng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: