rubytext 0.0.46 → 0.0.47

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: e5bdd350f25e6f839cc14ed02094834b04500fc4d19d0820528c4f7926e6ad06
4
- data.tar.gz: 7b692875289645bfcd7549b55802d3ae71c107d495946577174b3ca90d53cbb2
3
+ metadata.gz: af54fc7aa3e8470885d6f41f4cf9f33ce0dabe1b53a88ee1d1e0750b20ced927
4
+ data.tar.gz: 108611204efed6b3faef383c320625ea5236ba3a591ff798f3e1233cd12870ca
5
5
  SHA512:
6
- metadata.gz: 9c3ed73c4221ead1bfbb6fce563e4b6946e35e5eccda27f3895f24e2c56cd18b49d13987c073b68ddc71b732e054a7423ff3d7cc0a68844091ac912657fb18e3
7
- data.tar.gz: cdd9791ff4789cd234fc8ef7c364913f79ab5fa8b73b81d00dd86b9751b477d3aa8aa5af57a29d16f7984a27b7f6bf0061b75995e6b2cc4a8026dbbd8fb3ef03
6
+ metadata.gz: 1d33192d6f51cac31efc8f0494a4337b276b698a46841e2ae13fe915530dad20ce60fe93d66953e34072bb5ead2d4a5f358215af026cdbaf3f818c81e8bf92f0
7
+ data.tar.gz: e940105ed012605c24cf504a3ffe10d481bcc0f78091c389f77375e14c73b665a3ffb60b354dc65b336b6920eb2cd4ed0c3a1b99146dcb76cb2f539c6886da89
data/lib/rubytext.rb CHANGED
@@ -4,6 +4,8 @@ require 'curses'
4
4
 
5
5
  X = Curses # shorthand
6
6
 
7
+ RTError = StandardError.dup
8
+
7
9
  require 'version'
8
10
 
9
11
  require 'output' # RubyText, RubyText::Window, Kernel
@@ -26,8 +28,23 @@ module RubyText
26
28
  end
27
29
  end
28
30
 
31
+ ##########
32
+
33
+ at_exit { RubyText.stop }
34
+
29
35
  def import(meth, recv)
30
36
  Kernel.module_eval do
31
37
  define_method(meth) {|*args| recv.send(meth, *args) }
32
38
  end
33
39
  end
40
+
41
+ def make_exception(sym, str)
42
+ return if Object.constants.include?(sym)
43
+ Object.const_set(sym, StandardError.dup)
44
+ define_method(sym) do |*args|
45
+ msg = str
46
+ args.each.with_index {|arg, i| msg.sub!("$#{i+1}", arg) }
47
+ Object.class_eval(sym.to_s).new(msg)
48
+ end
49
+ end
50
+
data/lib/settings.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  module RubyText
2
+ # Hmm, all these are module-level.
3
+ def self.flags
4
+ @fstack.last
5
+ end
6
+
2
7
  def self.set(*args) # Allow a block?
3
8
  standard = [:cbreak, :raw, :echo, :keypad]
4
- @defaults = [:cbreak, :echo, :keypad, :cursor]
9
+ @defaults = [:cbreak, :echo, :keypad, :cursor, :_raw]
5
10
  @flags = @defaults.dup
6
11
  save_flags
7
12
  args.each do |arg|
@@ -18,7 +23,9 @@ module RubyText
18
23
  X.show_cursor
19
24
  when :_cursor, :nocursor
20
25
  X.hide_cursor
21
- else puts "wtf is #{arg}?"
26
+ else
27
+ self.stop
28
+ raise RTError
22
29
  end
23
30
  end
24
31
  end
@@ -51,6 +58,12 @@ module RubyText
51
58
  self.set(:_echo, :cbreak, :raw) # defaults
52
59
  # X.stdscr.keypad(true)
53
60
  self.set(*args) # override defaults
61
+ rescue
62
+ raise RTError
63
+ end
64
+
65
+ def self.stop
66
+ X.close_screen
54
67
  end
55
68
 
56
69
  # For passing through arbitrary method calls
@@ -65,7 +78,7 @@ module RubyText
65
78
  end
66
79
  end
67
80
 
68
- def RubyText.window(high, wide, r0, c0, border=false, fg: nil, bg: nil)
81
+ def self.window(high, wide, r0, c0, border=false, fg: nil, bg: nil)
69
82
  RubyText::Window.new(high, wide, r0, c0, border, fg, bg)
70
83
  end
71
84
 
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.0.46"
3
+ VERSION = "0.0.47"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
data/rubytext.gemspec CHANGED
@@ -23,9 +23,9 @@ Gem::Specification.new do |s|
23
23
  ex = Find.find("examples").to_a
24
24
 
25
25
  misc = %w[./README.md ./rubytext.gemspec]
26
- # test = Find.find("test").to_a
26
+ test = Find.find("test").to_a
27
27
 
28
- s.files = main + bin + ex + misc # + test
28
+ s.files = main + bin + ex + misc + test
29
29
  s.homepage = 'https://github.com/Hal9000/rubytext'
30
30
  s.license = "Ruby License"
31
31
  end
data/test/auto.rb ADDED
@@ -0,0 +1,33 @@
1
+ $LOAD_PATH << "."
2
+
3
+ require "minitest/autorun"
4
+
5
+ require 'rubytext'
6
+
7
+ class MyTest < Minitest::Test
8
+
9
+ def show_lines(text)
10
+ lines = text.split("\n")
11
+ str = "#{lines.size} lines\n"
12
+ lines.each {|line| str << " #{line.inspect}\n" }
13
+ str
14
+ end
15
+
16
+ def test_001_start_no_params
17
+ RubyText.start
18
+ # puts RubyText.flags.inspect
19
+ curr = RubyText.flags
20
+ RubyText.stop
21
+ assert curr == [:cbreak, :echo, :keypad, :cursor, :_raw]
22
+ end
23
+
24
+ def test_002_start_bad_param
25
+ assert_raises(RTError) { RubyText.start(:foobar); RubyText.stop }
26
+ end
27
+
28
+ def test_003_start_bad_color
29
+ assert_raises(RTError) { RubyText.start(fg: :chartreuse); RubyText.stop }
30
+ end
31
+
32
+ end
33
+
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.0.46
4
+ version: 0.0.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-23 00:00:00.000000000 Z
11
+ date: 2018-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -77,6 +77,7 @@ files:
77
77
  - lib/settings.rb
78
78
  - lib/version.rb
79
79
  - lib/window.rb
80
+ - test/auto.rb
80
81
  homepage: https://github.com/Hal9000/rubytext
81
82
  licenses:
82
83
  - Ruby License