rpl 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/rpl +24 -13
  3. data/lib/rpl.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 351033e886b47bece3ef9d5c143932c512c484bf92fce4128eb72edbdbdb7da3
4
- data.tar.gz: 92812d157842f269ea72158f3db150ee62489aed54bba6d754ee2b4d6f386989
3
+ metadata.gz: 745f492092d7e5dd03c90ca25ee5de900832730342075295a8f9d190734ed4d4
4
+ data.tar.gz: b7a56161fcf77d5b90b015e4bc67ba3a770605aba261c46f40adfbac1232daa6
5
5
  SHA512:
6
- metadata.gz: a5be657562ddfe9aa9329e3e5dcbf4cd9253428b11d8b2822ae09cd2d6a4a05e11d6864d474135b9275b4b0f338e87ee606fad898c118a274cb72633153a532b
7
- data.tar.gz: ed16880b36a64da41863d07d281f46f0c9db1a3f2b8a2b75ba99ed3ebafb8439fd6c008ef84c39bf1382cd203c8885735d5655077b01da237d4c770d0d1c5514
6
+ metadata.gz: 4df6860f009ab1ae4c957000e98fd7f39be60c2d9370ab0626a60e71a84625b14e9d5bb9142c53d178d602b2654ec95ade37d4bf03825245a318d7da9f5a6296
7
+ data.tar.gz: 19f365a0e10430051ba6ca75cbe55d4504fb3ef2e6d778e4114d335f20c558f7921b9921b949caf11eb3fccb1538f014f3c2a396421648fee0035fa8eac08f67
data/bin/rpl CHANGED
@@ -3,34 +3,42 @@
3
3
 
4
4
  require 'English'
5
5
  require 'optparse'
6
- require 'readline'
6
+ require 'reline'
7
7
 
8
8
  require 'rpl'
9
9
 
10
10
  class RplRepl
11
11
  def initialize( interpreter: Rpl.new )
12
+ begin
13
+ @stty_save = `stty -g`.chomp
14
+ rescue Error => e
15
+ puts "Couldn't get terminal characteristics"
16
+ pp e
17
+ end
18
+
12
19
  @interpreter = interpreter
13
20
  end
14
21
 
15
22
  def run
16
23
  print_stack unless @interpreter.stack.empty?
17
24
 
18
- Readline.completion_proc = proc do |s|
25
+ Reline.completion_proc = proc do |s|
19
26
  ( @interpreter.dictionary.words.keys + @interpreter.dictionary.vars.keys ).grep(/^#{Regexp.escape(s)}/)
20
27
  end
21
- Readline.completion_append_character = ' '
28
+ Reline.completion_append_character = ' '
22
29
 
23
30
  prefill = ''
24
31
  loop do
25
- Readline.pre_input_hook = lambda do
26
- return if prefill.empty?
32
+ unless prefill.empty?
33
+ Reline.pre_input_hook = lambda do
34
+ Reline.insert_text( prefill.to_s )
35
+ Reline.redisplay
27
36
 
28
- Readline.refresh_line
29
- Readline.insert_text( prefill.to_s )
30
- Readline.redisplay
37
+ Reline.pre_input_hook = nil
38
+ end
31
39
  end
32
40
 
33
- input = Readline.readline( ' ', true )
41
+ input = Reline.readline( ' ', true )
34
42
 
35
43
  break if input.nil? || input.strip == 'quit'
36
44
 
@@ -39,12 +47,11 @@ class RplRepl
39
47
  if input.strip == 'edit'
40
48
  prefill = @interpreter.stack.pop.to_s
41
49
  elsif input.strip == 'history'
42
- Readline::HISTORY.each do |line|
43
- pp line
44
- end
50
+ history = Reline::HISTORY.map { |line| "\"#{line}\"" }.join(' ')
51
+ @interpreter.run( "{ #{history} }" )
45
52
  elsif input.empty?
46
53
  # Remove blank lines from history
47
- Readline::HISTORY.pop
54
+ Reline::HISTORY.pop
48
55
  else
49
56
  begin
50
57
  @interpreter.run( input )
@@ -54,6 +61,10 @@ class RplRepl
54
61
  end
55
62
 
56
63
  print_stack
64
+ rescue Interrupt
65
+ puts '^C'
66
+ `stty #{@stty_save}` if @stty_save
67
+ exit 0
57
68
  end
58
69
  end
59
70
 
data/lib/rpl.rb CHANGED
@@ -5,7 +5,7 @@ require 'rpl/types'
5
5
  require 'rpl/words'
6
6
 
7
7
  class Rpl < Interpreter
8
- VERSION = '0.11.0'
8
+ VERSION = '0.12.0'
9
9
 
10
10
  include Types
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gwenhael Le Moine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-05 00:00:00.000000000 Z
11
+ date: 2022-10-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A language inspired by HP's RPL and https://github.com/louisrubet/rpn/
14
14
  email: gwenhael@le-moine.org