rubytext 0.0.47 → 0.0.48
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 +4 -4
- data/lib/settings.rb +26 -6
- data/lib/version.rb +1 -1
- data/test/auto.rb +32 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33b423bc804b45b9a7cf9b322a822551ec748664ae0c01888d193575aeec3792
|
4
|
+
data.tar.gz: 9bbd79f2a7dff3507a5ced5f83df3375a85a8b95ad92bd759e93e7a496867a87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 409ddaf82104c1f4d6c11c72fcf92654bf169ddabdc7ee717b05e1ae2f8e0a0d54e4958b54f33bf526411befb6221b3a05a3a69679267a72728ed4a6a48de534
|
7
|
+
data.tar.gz: e6bec1c738ed8ed503215c402fd40b6f501c56a5d7147518994c52621a90e0fa787d1b7e7b7430e59b9b5ddcea596ec3ac95c5252fc36dc473c4ae9c5fde1a65
|
data/lib/settings.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
module RubyText
|
2
2
|
# Hmm, all these are module-level.
|
3
|
+
|
3
4
|
def self.flags
|
4
|
-
@
|
5
|
+
@flags.uniq!
|
6
|
+
@flags
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.inverse_flag(flag)
|
10
|
+
sflag = flag.to_s
|
11
|
+
if sflag[0] == "_"
|
12
|
+
sflag[1..-1].to_sym
|
13
|
+
else
|
14
|
+
("_" + sflag).to_sym
|
15
|
+
end
|
5
16
|
end
|
6
17
|
|
7
18
|
def self.set(*args) # Allow a block?
|
@@ -10,7 +21,11 @@ module RubyText
|
|
10
21
|
@flags = @defaults.dup
|
11
22
|
save_flags
|
12
23
|
args.each do |arg|
|
13
|
-
|
24
|
+
puts "\n@flags = #{@flags.inspect}... add #{arg}, remove #{inverse_flag(arg)}"
|
25
|
+
@flags += [arg]
|
26
|
+
@flags -= [inverse_flag(arg)]
|
27
|
+
@flags.uniq!
|
28
|
+
puts "@flags = #{@flags.inspect}"
|
14
29
|
flag = arg.to_s
|
15
30
|
if standard.include? flag.to_sym
|
16
31
|
X.send(flag)
|
@@ -20,15 +35,16 @@ module RubyText
|
|
20
35
|
else
|
21
36
|
case arg
|
22
37
|
when :cursor
|
23
|
-
X.
|
38
|
+
X.curs_set(1)
|
24
39
|
when :_cursor, :nocursor
|
25
|
-
X.
|
40
|
+
X.curs_set(0)
|
26
41
|
else
|
27
42
|
self.stop
|
28
43
|
raise RTError
|
29
44
|
end
|
30
45
|
end
|
31
46
|
end
|
47
|
+
|
32
48
|
if block_given?
|
33
49
|
yield
|
34
50
|
rest_flags
|
@@ -36,16 +52,18 @@ module RubyText
|
|
36
52
|
end
|
37
53
|
|
38
54
|
def self.reset
|
39
|
-
|
55
|
+
rest_flags
|
40
56
|
end
|
41
57
|
|
42
58
|
def self.save_flags
|
43
59
|
@fstack ||= []
|
60
|
+
@flags.uniq!
|
44
61
|
@fstack.push @flags
|
45
62
|
end
|
46
63
|
|
47
64
|
def self.rest_flags
|
48
65
|
@flags = @fstack.pop
|
66
|
+
@flags.uniq!
|
49
67
|
rescue
|
50
68
|
@flags = @defaults
|
51
69
|
end
|
@@ -58,7 +76,9 @@ module RubyText
|
|
58
76
|
self.set(:_echo, :cbreak, :raw) # defaults
|
59
77
|
# X.stdscr.keypad(true)
|
60
78
|
self.set(*args) # override defaults
|
61
|
-
rescue
|
79
|
+
rescue => err
|
80
|
+
debug(err.inspect)
|
81
|
+
debug(err.backtrace)
|
62
82
|
raise RTError
|
63
83
|
end
|
64
84
|
|
data/lib/version.rb
CHANGED
data/test/auto.rb
CHANGED
@@ -4,6 +4,8 @@ require "minitest/autorun"
|
|
4
4
|
|
5
5
|
require 'rubytext'
|
6
6
|
|
7
|
+
at_exit { RubyText.stop }
|
8
|
+
|
7
9
|
class MyTest < Minitest::Test
|
8
10
|
|
9
11
|
def show_lines(text)
|
@@ -15,7 +17,6 @@ class MyTest < Minitest::Test
|
|
15
17
|
|
16
18
|
def test_001_start_no_params
|
17
19
|
RubyText.start
|
18
|
-
# puts RubyText.flags.inspect
|
19
20
|
curr = RubyText.flags
|
20
21
|
RubyText.stop
|
21
22
|
assert curr == [:cbreak, :echo, :keypad, :cursor, :_raw]
|
@@ -29,5 +30,35 @@ class MyTest < Minitest::Test
|
|
29
30
|
assert_raises(RTError) { RubyText.start(fg: :chartreuse); RubyText.stop }
|
30
31
|
end
|
31
32
|
|
33
|
+
def test_004_set_reset
|
34
|
+
RubyText.start
|
35
|
+
orig = [:cbreak, :echo, :keypad, :cursor, :_raw]
|
36
|
+
assert RubyText.flags == orig
|
37
|
+
|
38
|
+
used = [:raw, :_cursor, :_echo]
|
39
|
+
RubyText.set(*used)
|
40
|
+
curr = RubyText.flags
|
41
|
+
assert used.all? {|x| curr.include? x }
|
42
|
+
|
43
|
+
RubyText.reset
|
44
|
+
assert RubyText.flags == orig
|
45
|
+
|
46
|
+
RubyText.stop
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_005_set_block
|
50
|
+
RubyText.start
|
51
|
+
orig = RubyText.flags
|
52
|
+
used = [:raw, :_cursor, :_echo]
|
53
|
+
RubyText.set(*used) do
|
54
|
+
curr = RubyText.flags
|
55
|
+
assert used.all? {|x| curr.include? x }
|
56
|
+
end
|
57
|
+
# outside block again...
|
58
|
+
assert RubyText.flags == orig
|
59
|
+
|
60
|
+
RubyText.stop
|
61
|
+
end
|
62
|
+
|
32
63
|
end
|
33
64
|
|