rubytext 0.0.73 → 0.0.74

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: 8aab3de408243095abccb5ccd7096708f0aff51e5aa27d04fd2e27e8fa1b870c
4
- data.tar.gz: f3a0c894e21d5e498287942c078b730cc18431d7455e1f8cf1267691419927fc
3
+ metadata.gz: a79401a742e0dee3f3fe1e2a75c477ea819b4cb00aa76deba471de0a26fdb0fb
4
+ data.tar.gz: 67f72468b5ca76116d45f872a8d6626e768c9d66301c20a18bd0a62b497836a0
5
5
  SHA512:
6
- metadata.gz: 59fdd86f11a6532e19a976b587a163fab2f75b4830e2f37469ec2c48ee621e8f03829198201084d565096bd786581761bc5b59cf36c85d7e12bc07047449093e
7
- data.tar.gz: 389232176c392a98f8b2a961d3cb9a21496b154f1be949e615720cb8551a8ae132e09e54bb2f4b34872fcf7ad499064e9a1ee1cc716b354fc1dbdd3a2b0096a7
6
+ metadata.gz: d28d84e40b096a6e71dc9461ba41d55b97246d8ffd90f2dcc1a090c2d69cb7928380ebca87d50695a7a6ee556162f59be7761dd058cfbba5d257c3bc5faa525b
7
+ data.tar.gz: 1ee6a3d4fcae0e801b7d5dfd2c2891bace25bc0cbfad4e2489de66fb50c73fb44f8f90137c1aec071d379691e23c73eb438d86a866d7b0c71d9763770f210f32
data/examples/prog10.rb CHANGED
@@ -1,15 +1,15 @@
1
- win = RubyText.window(6, 30, 4, 13, fg: Yellow, bg: Blue)
1
+ win = RubyText.window(6, 30, 3, 13, fg: Yellow, bg: Blue)
2
2
 
3
3
  win.puts "You can write to a window..."
4
4
 
5
5
  sleep 2
6
- 9.times { STDSCR.puts }
6
+ 11.times { STDSCR.puts }
7
7
  STDSCR.puts "...or you can write to STDSCR (standard screen)"
8
8
 
9
9
  sleep 1
10
10
  puts "STDSCR is the default receiver."
11
11
 
12
12
  sleep 2
13
- STDSCR.go 5, 0
13
+ STDSCR.go 6, 0
14
14
  puts "Nothing stops you from overwriting a window."
15
15
 
data/examples/prog20.rb CHANGED
@@ -8,11 +8,11 @@ win = RubyText.window(9, 65, 2, 26, fg: fg, bg: bg)
8
8
  win.puts "This is EXPERIMENTAL (and BUGGY)."
9
9
  win.puts "Use an \"effect\" to change the text color or \"look\":"
10
10
 
11
- win.puts "This is", effect(win, Yellow), " another color ",
12
- effect(win, White), "and yet another."
13
- win.puts "We can ", effect(win, :bold), "boldface ",
14
- "and ", effect(win, :reverse), "reverse ",
15
- "and ", effect(win, :under), "underline ",
16
- effect(win, :normal), "text at will.\n "
17
- win.puts "This is ", effect(win, :bold, Red), "bold red ",
18
- effect(win, :normal, fg), "and this is normal again.\n "
11
+ win.puts "This is", effect(Yellow), " another color ",
12
+ effect(White), "and yet another."
13
+ win.puts "We can ", effect(:bold), "boldface ",
14
+ "and ", effect(:reverse), "reverse ",
15
+ "and ", effect(:under), "underline ",
16
+ effect(:normal), "text at will.\n "
17
+ win.puts "This is ", effect(:bold, Red), "bold red ",
18
+ effect(:normal, fg), "and this is normal again.\n "
@@ -0,0 +1,18 @@
1
+ def effect(*args) # find better way
2
+ RubyText::Effects.new(*args)
3
+ end
4
+
5
+ fg, bg = White, Blue
6
+ win = RubyText.window(9, 65, 2, 26, fg: fg, bg: bg)
7
+
8
+ win.puts "This is EXPERIMENTAL (and BUGGY)."
9
+ win.puts "Use an \"effect\" to change the text color or \"look\":"
10
+
11
+ win.puts "This is", fx(" another color ", Yellow),
12
+ effect(White), "and yet another."
13
+ win.puts "We can ", effect(:bold), "boldface ",
14
+ "and ", effect(:reverse), "reverse ",
15
+ "and ", effect(:under), "underline ",
16
+ effect(:normal), "text at will.\n "
17
+ win.puts "This is ", effect(:bold, Red), "bold red ",
18
+ effect(:normal, fg), "and this is normal again.\n "
data/lib/effects.rb CHANGED
@@ -1,15 +1,22 @@
1
+
2
+
3
+ def fx(str, *args)
4
+ eff = RubyText::Effects.new(*args)
5
+ str.define_singleton_method(:effect) { eff }
6
+ str # must return str
7
+ end
8
+
1
9
  class RubyText::Effects # dumb name?
2
10
  Modes = {bold: X::A_BOLD,
3
11
  normal: X::A_NORMAL,
4
12
  reverse: X::A_REVERSE,
5
13
  under: X::A_UNDERLINE}
6
14
 
7
-
8
15
  Others = %[:show, :hide] # show/hide cursor; more later??
9
16
 
10
17
  attr_reader :value, :fg
11
18
 
12
- def initialize(win, *args)
19
+ def initialize(*args)
13
20
  bits = 0
14
21
  @list = args
15
22
  args.each do |arg|
@@ -22,5 +29,11 @@ class RubyText::Effects # dumb name?
22
29
  end
23
30
  @value = bits
24
31
  end
32
+
33
+ def set(win)
34
+ attr, fg = self.value, self.fg
35
+ win.cwin.attron(attr)
36
+ win.set_colors(fg, win.bg) if fg
37
+ end
25
38
  end
26
39
 
data/lib/menu.rb CHANGED
@@ -31,8 +31,8 @@ module RubyText
31
31
  RubyText.hide_cursor
32
32
  sel = curr
33
33
  max = items.size - 1
34
- norm = RubyText::Effects.new(win, :normal)
35
- rev = RubyText::Effects.new(win, :reverse)
34
+ norm = RubyText::Effects.new(:normal)
35
+ rev = RubyText::Effects.new(:reverse)
36
36
  loop do
37
37
  items.each.with_index do |item, row|
38
38
  win.go row, 0
@@ -67,8 +67,8 @@ module RubyText
67
67
  # RubyText.set(:raw)
68
68
  X.stdscr.keypad(true)
69
69
  RubyText.hide_cursor
70
- norm = RubyText::Effects.new(menu_win, :normal)
71
- rev = RubyText::Effects.new(menu_win, :reverse)
70
+ norm = RubyText::Effects.new(:normal)
71
+ rev = RubyText::Effects.new(:reverse)
72
72
  sel = 0
73
73
  max = items.size - 1
74
74
  send(handler, sel, items[sel], win2)
data/lib/output.rb CHANGED
@@ -8,7 +8,7 @@ class RubyText::Window
8
8
  self.puts str
9
9
  end
10
10
 
11
- def putch(ch)
11
+ def putch(ch) # move to WindowIO?
12
12
  r, c = self.rc
13
13
  self[r, c] = ch[0]
14
14
  end
@@ -32,13 +32,11 @@ class RubyText::Window
32
32
  end
33
33
  args.each do |arg|
34
34
  if arg.is_a?(RubyText::Effects)
35
- attr, fg = arg.value, arg.fg
36
- self.cwin.attron(attr)
37
- self.set_colors(fg, @bg) if fg
35
+ arg.set(self)
38
36
  elsif arg.respond_to? :effect
39
- attr, fg = arg.effect.value, arg.effect.fg
40
- self.cwin.attron(attr)
41
- self.set_colors(fg, @bg) if fg
37
+ arg.effect.set(self)
38
+ arg.each_char {|ch| ch == "\n" ? crlf : @cwin.addch(ch) }
39
+ @cwin.refresh
42
40
  else
43
41
  arg.each_char {|ch| ch == "\n" ? crlf : @cwin.addch(ch) }
44
42
  @cwin.refresh
@@ -155,5 +153,19 @@ module WindowIO
155
153
  def getch
156
154
  X.getch
157
155
  end
156
+
157
+ def gets # still needs improvement
158
+ str = ""
159
+ loop do
160
+ ch = ::STDSCR.getch
161
+ if ch == 10
162
+ ::STDSCR.crlf
163
+ break
164
+ end
165
+ str << ch
166
+ end
167
+ str
168
+ end
169
+
158
170
  end
159
171
 
data/lib/settings.rb CHANGED
@@ -1,14 +1,15 @@
1
1
  module RubyText
2
2
  # Hmm, all these are module-level.
3
3
 
4
- def self.start(*args, log: nil, fg: White, bg: Blue, scroll: false)
5
- $debug ||= File.new(log, "w") if log
4
+ def self.start(*args, log: "/tmp/rubytext.log",
5
+ fg: White, bg: Blue, scroll: false)
6
+ $debug ||= File.new(log, "w") if log # FIXME remove global
6
7
  main = RubyText::Window.main(fg: fg, bg: bg, scroll: scroll)
7
8
  Object.const_set(:STDSCR, main) unless defined? STDSCR
8
- $stdscr = STDSCR
9
+ $stdscr = STDSCR # FIXME global needed?
9
10
  Object.include(WindowIO)
10
- self.set(:_echo, :cbreak) # defaults
11
- self.set(*args) # override defaults
11
+ self.set(:_echo, :cbreak) # defaults (:keypad?)
12
+ self.set(*args) # override defaults
12
13
  rescue => err
13
14
  debug(err.inspect)
14
15
  debug(err.backtrace)
@@ -33,7 +34,7 @@ module RubyText
33
34
 
34
35
  def self.set(*args) # Allow a block?
35
36
  standard = [:cbreak, :raw, :echo, :keypad]
36
- @defaults = [:cbreak, :echo, :keypad, :cursor, :_raw]
37
+ @defaults = [:cbreak, :_echo, :keypad]
37
38
  @flags = @defaults.dup
38
39
  save_flags
39
40
  args.each do |arg|
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.0.73"
3
+ VERSION = "0.0.74"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
data/lib/window.rb CHANGED
@@ -2,7 +2,7 @@ class RubyText::Window
2
2
  Vert, Horiz = X::A_VERTICAL, X::A_HORIZONTAL
3
3
 
4
4
  attr_reader :cwin, :rows, :cols, :width, :height, :scrolling
5
- attr_writer :fg, :bg
5
+ attr_accessor :fg, :bg
6
6
 
7
7
  # Better to use Window.window IRL
8
8
 
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.73
4
+ version: 0.0.74
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
@@ -65,6 +65,7 @@ files:
65
65
  - examples/prog18.rb
66
66
  - examples/prog19.rb
67
67
  - examples/prog20.rb
68
+ - examples/prog20a.rb
68
69
  - examples/prog21.rb
69
70
  - examples/prog22.rb
70
71
  - examples/showme.rb