rubytext 0.0.47 → 0.0.48

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/settings.rb +26 -6
  3. data/lib/version.rb +1 -1
  4. data/test/auto.rb +32 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af54fc7aa3e8470885d6f41f4cf9f33ce0dabe1b53a88ee1d1e0750b20ced927
4
- data.tar.gz: 108611204efed6b3faef383c320625ea5236ba3a591ff798f3e1233cd12870ca
3
+ metadata.gz: 33b423bc804b45b9a7cf9b322a822551ec748664ae0c01888d193575aeec3792
4
+ data.tar.gz: 9bbd79f2a7dff3507a5ced5f83df3375a85a8b95ad92bd759e93e7a496867a87
5
5
  SHA512:
6
- metadata.gz: 1d33192d6f51cac31efc8f0494a4337b276b698a46841e2ae13fe915530dad20ce60fe93d66953e34072bb5ead2d4a5f358215af026cdbaf3f818c81e8bf92f0
7
- data.tar.gz: e940105ed012605c24cf504a3ffe10d481bcc0f78091c389f77375e14c73b665a3ffb60b354dc65b336b6920eb2cd4ed0c3a1b99146dcb76cb2f539c6886da89
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
- @fstack.last
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
- @flags << arg
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.show_cursor
38
+ X.curs_set(1)
24
39
  when :_cursor, :nocursor
25
- X.hide_cursor
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
- restflags
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
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.0.47"
3
+ VERSION = "0.0.48"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubytext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.47
4
+ version: 0.0.48
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton