rubytext 0.1.11 → 0.1.12

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
  SHA256:
3
- metadata.gz: ef493cd27a795e722bc61332718af2332c38f6530e74ee3b00289e2507f2ddc6
4
- data.tar.gz: e88ba1983fea2d0b1aa5b88f57197a50d571fd55ab35bf8556f53da532b2b8fe
3
+ metadata.gz: b6036e0b122b120c698646243dd7679e7a6b0991687d958a01e66be56119ad1a
4
+ data.tar.gz: ede2e0e43159005799fe9de6679858037cc3e1b6d3883583611ff87e2dfbed36
5
5
  SHA512:
6
- metadata.gz: 72f0c62756d9cbf4f19c75319be3707f7337010d73dbee57cdcd73bc099ee15c5ee918116d3cc3014c92ebdbc72ddad121f629712c3eadc790c16051f9271a22
7
- data.tar.gz: 1279205bdddfbff8a017a1e6b07dc82631738ac6dae99a607b146784aecfc67834af5bddc2e6a4d3a3e1ef7119ad193b2d549aa97e8c31bbf69d0785d8ef3b83
6
+ metadata.gz: 28124389eeef71e3cad064680fc1347649fba40cbf61a06ed0bea1d67fc2aaedd6679cc6c2db3196e03677596f3c7f7fc1172c6e17cc84852b730165db6ef166
7
+ data.tar.gz: 1fda7e185b9d33a85629fd6eb9d3c84e4a651001d5f002b4e504bd81682f1aba8aa273d3f00bc2ac0ee46a6593c2c83d5ad3c05f31d96ad530e8a36976d96246
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.1.11"
3
+ VERSION = "0.1.12"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
data/lib/settings.rb CHANGED
@@ -1,12 +1,9 @@
1
1
  module RubyText
2
2
  # Hmm, all these are module-level...?
3
3
 
4
- ValidArgs = [:raw, :_raw, :echo, :_echo, :cbreak, :_cbreak,
5
- :keypad, :_keypad, :cursor, :_cursor]
6
-
7
-
8
4
  class Settings
9
- # raw echo cbreak keypad cursor
5
+ ValidArgs = [:raw, :_raw, :echo, :_echo, :cbreak, :_cbreak,
6
+ :keypad, :_keypad, :cursor, :_cursor]
10
7
  def initialize
11
8
  @defaults = {raw: false, echo: false, cbreak: true, keypad: true, cursor: true}
12
9
  @current = @defaults.dup
@@ -26,8 +23,8 @@ module RubyText
26
23
  when [:raw, false]; Curses.noraw
27
24
  when [:echo, true]; Curses.echo
28
25
  when [:echo, false]; Curses.noecho
29
- when [:keypad, true]; STDSCR.cwin.keypad(true)
30
- when [:keypad, false]; STDSCR.cwin.keypad(false)
26
+ when [:keypad, true]; Curses.stdscr.keypad(true)
27
+ when [:keypad, false]; Curses.stdscr.keypad(false)
31
28
  when [:cursor, true]; Curses.curs_set(1)
32
29
  when [:cursor, false]; Curses.curs_set(0)
33
30
  end
@@ -50,8 +47,16 @@ module RubyText
50
47
  set_curses(@current)
51
48
  end
52
49
 
53
- def set(syms)
50
+ def set(*syms)
51
+ raise ArgumentError unless syms - ValidArgs == []
54
52
  # FIXME - call set_boolean
53
+ list = {}
54
+ syms.each do |sym|
55
+ str = sym.to_s
56
+ val = str[0] != "_"
57
+ list[sym] = val
58
+ end
59
+ set_boolean(list)
55
60
  # allow a block here?
56
61
  end
57
62
 
@@ -82,18 +87,19 @@ module RubyText
82
87
 
83
88
  def self.start(*args, log: "/tmp/rubytext.log",
84
89
  fg: White, bg: Blue, scroll: false)
85
- $debug ||= File.new(log, "w") if log # FIXME remove global
90
+ # $debug ||= File.new(log, "w") if log # FIXME remove global
86
91
 
87
- args.each {|arg| raise "#{arg} is not valid" unless ValidArgs.include?(arg) }
92
+ args.each {|arg| raise "#{arg} is not valid" unless Settings::ValidArgs.include?(arg) }
88
93
  raise "#{fg} is not a color" unless ::Colors.include? fg
89
94
  raise "#{bg} is not a color" unless ::Colors.include? bg
90
95
 
96
+ @settings = Settings.new
97
+ @settings.set(*args) # override defaults
98
+
91
99
  main = RubyText::Window.main(fg: fg, bg: bg, scroll: scroll)
92
100
  Object.const_set(:STDSCR, main) unless defined? STDSCR
93
101
  $stdscr = STDSCR # FIXME global needed?
94
102
  Object.include(WindowIO)
95
- self.set(:_echo, :cbreak, :keypad) # defaults
96
- self.set(*args) # override defaults
97
103
  @started = true
98
104
  rescue => err
99
105
  debug(err.inspect)
@@ -101,87 +107,19 @@ module RubyText
101
107
  raise RTError("#{err}")
102
108
  end
103
109
 
104
- def self.flags
105
- @flags.uniq!
106
- @flags
107
- end
108
-
109
- # FIXME Refactor the Hal out of this...
110
-
111
- def self.inverse_flag(flag)
112
- sflag = flag.to_s
113
- if sflag[0] == "_"
114
- sflag[1..-1].to_sym
115
- else
116
- ("_" + sflag).to_sym
117
- end
118
- end
119
-
120
- def self.set(*args) # Allow a block?
121
- standard = [:cbreak, :raw, :echo]
122
- @defaults = [:cbreak, :_echo, :keypad]
123
- @flags = @defaults.dup
124
- save_flags
125
- args.each do |arg|
126
- @flags += [arg]
127
- inv = inverse_flag(arg)
128
- @flags -= [inv]
129
- @flags.uniq!
130
- flag = arg.to_s
131
- if standard.include?(flag.to_sym) || standard.include?(flag.sub(/no/, "_").to_sym)
132
- Curses.send(flag)
133
- elsif flag[0] == "_" && standard.include?(flag[1..-1].to_sym)
134
- flag.sub!(/^_/, "no")
135
- Curses.send(flag)
136
- else
137
- case flag.to_sym
138
- when :cursor
139
- Curses.curs_set(1)
140
- when :_cursor, :nocursor
141
- Curses.curs_set(0)
142
- when :keypad
143
- STDSCR.cwin.keypad(true)
144
- when :_keypad
145
- STDSCR.cwin.keypad(false)
146
- else
147
- # self.stop
148
- rest_flags # prevent propagating error in test
149
- raise RTError("flag = #{flag.inspect}")
150
- end
151
- end
152
- end
153
-
154
- if block_given?
155
- yield
156
- rest_flags
157
- end
158
- end
159
-
160
- def self.reset
161
- rest_flags
162
- end
163
-
164
- def self.save_flags
165
- @fstack ||= []
166
- @flags.uniq!
167
- @fstack.push @flags
168
- end
169
-
170
- def self.rest_flags
171
- @flags = @fstack.pop
172
- @flags.uniq!
173
- self.set(*@flags)
174
- rescue
175
- @flags = @defaults
176
- end
177
-
178
- # ... end of ugly settings weirdness
179
-
180
110
  def self.stop
181
111
  @started = false
182
112
  Curses.close_screen
183
113
  end
184
114
 
115
+ def set(*args)
116
+ @settings.set(*args)
117
+ end
118
+
119
+ def reset
120
+ @settings.reset
121
+ end
122
+
185
123
  # For passing through arbitrary method calls
186
124
  # to the lower level...
187
125
 
data/test/auto.rb CHANGED
@@ -8,6 +8,10 @@ at_exit { RubyText.stop }
8
8
 
9
9
  class MyTest < Minitest::Test
10
10
 
11
+ def setup
12
+ load "rubytext.rb"
13
+ end
14
+
11
15
  def show_lines(text)
12
16
  lines = text.split("\n")
13
17
  str = "#{lines.size} lines\n"
@@ -20,14 +24,20 @@ class MyTest < Minitest::Test
20
24
  curr = RubyText.flags
21
25
  RubyText.stop
22
26
  assert curr == [:cbreak, :_echo, :keypad], "Got #{curr.inspect}"
27
+ rescue
28
+ RubyText.stop
23
29
  end
24
30
 
25
31
  def test_002_start_bad_param
26
32
  assert_raises(RTError) { RubyText.start(:foobar); RubyText.stop }
33
+ rescue
34
+ RubyText.stop
27
35
  end
28
36
 
29
37
  def test_003_start_bad_color
30
38
  assert_raises(RTError) { RubyText.start(fg: :chartreuse); RubyText.stop }
39
+ rescue
40
+ RubyText.stop
31
41
  end
32
42
 
33
43
  def test_004_set_reset
@@ -43,6 +53,8 @@ class MyTest < Minitest::Test
43
53
  RubyText.reset
44
54
  assert RubyText.flags == orig
45
55
 
56
+ RubyText.stop
57
+ rescue
46
58
  RubyText.stop
47
59
  end
48
60
 
@@ -57,6 +69,8 @@ class MyTest < Minitest::Test
57
69
  # outside block again...
58
70
  assert RubyText.flags == orig
59
71
 
72
+ RubyText.stop
73
+ rescue
60
74
  RubyText.stop
61
75
  end
62
76
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubytext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-11 00:00:00.000000000 Z
11
+ date: 2019-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses