cmdr 0.4.2 → 0.4.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91aeb5ecb528814ed1c1f8b154d41fd1d4387191
4
- data.tar.gz: 9f469020f47db5ba33253627d7881f4fbe9ed1ca
3
+ metadata.gz: b8d936d529e3698ab46c5f4c586278accd5ca9f6
4
+ data.tar.gz: 92554aa271785174ce0c2413ef00ece23b6f735f
5
5
  SHA512:
6
- metadata.gz: '095fef013837823dc91e1f556832bdb74eb5eb1b7a3ccd9d9dbd1fe89b2e1f5a005cddc4c715bd67564c0c9c8fb2aaf96546a802a73d5e3a856653e9131828d9'
7
- data.tar.gz: 7baa77e22f677e417eaf7ecdf9fa16973260d522850a0a0fd4ec4ef078f5ce69ff299350ee177b025e01b8337c03e091e17ba366d5ec272e7f0d47c79a63ab53
6
+ metadata.gz: d2f15fdc7dc5a2675e7ec82dfcdb67d6c81088c6cd657b5486939ca2ca4385bb282fa9c9ca9edf22eb9d2855704026e6be992802da342f617323bf8a0832fcad
7
+ data.tar.gz: c0e3a14842e8769e71a42df9ebdb24a40c2cb6db881241e669cf9786047dffae2563add15118d153dc676b2e46e4168d5fd3622e070e91b8ba095ed0030f295f
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -5,15 +5,17 @@
5
5
 
6
6
  class Cmdr
7
7
 
8
+
8
9
  def initialize()
9
10
 
10
11
  @linebuffer = ''
11
12
  @history = []
13
+ @history_index = -1
12
14
 
13
15
  end
14
16
 
15
17
  def input(c, enter: "\r", backspace: "\u007F", arrowup: :arrow_up, arrowdown: :arrow_down)
16
-
18
+
17
19
  key = c
18
20
  #return 'var r="e";'
19
21
  reveal(c)
@@ -23,7 +25,7 @@ class Cmdr
23
25
 
24
26
  command = @linebuffer
25
27
 
26
- @history << command
28
+ @history << command unless @history.last == command or command.empty?
27
29
 
28
30
  if @linebuffer.length < 1 then
29
31
  return clear_cli()
@@ -42,16 +44,32 @@ class Cmdr
42
44
 
43
45
  @linebuffer = ''
44
46
  clear_cli()
47
+ @history_index = -1
45
48
 
46
49
  when backspace
47
50
  @linebuffer.chop!
48
51
  cli_update()
49
52
  when arrowup
50
- old_command = @history.last
51
- @linebuffer = old_command
52
- cli_update old_command
53
+
54
+ return if @history.empty?
55
+
56
+
57
+ clear_cli()
58
+ command = @history[@history_index]
59
+ @linebuffer = command
60
+ @history_index -= 1 if @history_index > -(@history.length)
61
+ cli_update command
62
+
53
63
  when arrowdown
54
- #puts 'arrowdown'
64
+
65
+ return if @history.empty? or @history_index == -1
66
+
67
+ clear_cli()
68
+ @history_index += 1
69
+ command = @history[@history_index]
70
+ @linebuffer = command
71
+ cli_update command
72
+
55
73
  else
56
74
 
57
75
  if key.length < 2 then
@@ -71,16 +89,21 @@ class Cmdr
71
89
  def cli_banner()
72
90
  print "> "
73
91
  end
92
+
93
+ def history()
94
+ cli_update @history.map.with_index {|x,i| " %s %s" % [i, x]}.join("\n")
95
+ end
74
96
 
75
97
  protected
76
98
 
77
99
  # display the current input
78
100
  #
79
- def cli_update(s='')
101
+ def cli_update(s='')
80
102
  print s
81
103
  end
82
104
 
83
- alias clear_cli cli_update
105
+ def clear_cli()
106
+ end
84
107
 
85
108
  # display the output
86
109
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmdr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  aQuuxN6Drf3pdfalETmFyPgJ7gU+AcENcNa4wGuZKF786/ki4mt++AhKIiQI+Tbn
32
32
  fduXC3tBaNX+gQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-12-02 00:00:00.000000000 Z
34
+ date: 2016-12-13 00:00:00.000000000 Z
35
35
  dependencies: []
36
36
  description:
37
37
  email: james@r0bertson.co.uk
metadata.gz.sig CHANGED
Binary file