rubytext 0.0.60 → 0.0.61

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed8fcf2a8a7d86a9bf6638f1cd79c5c17c3529098a38a068bb13ed46e5593064
4
- data.tar.gz: 15151447c9e3d9cc3f512e3633587a619c9964243145fbbd351725f0513caedf
3
+ metadata.gz: 0001d23647ee6db8889ba9022e93b4d7335c5186448f3574cc87df0b4524e478
4
+ data.tar.gz: 07f657f4e4718a0e89a596db1d00e5577e7a41931a647506212ef21a831fef31
5
5
  SHA512:
6
- metadata.gz: 2b568b4c93804d87ed8b2a594ea384fbe055d7b0fdee9eecaa242f3991b8f764f907d2024a6669b89bed4a7122a25dc0f2fcbed9b1b586f95300267a239caa30
7
- data.tar.gz: 19dc65ee79dc0bf985a98631f0eef878c02c263be11664f2c94f75b43bc784a51bad9f59d7ec78dbb3401e0d1d5a65562eda7f12200d2ab4ef1451a471c68eca
6
+ metadata.gz: 3c0dd0a9f005c53df842d658188fff9832cc47e20d483ad7ae23c0f1ef68e88eef024cb4fdce23e15e3792bff562b5a05b22ec1326242619f55ca833d0f8de9f
7
+ data.tar.gz: a19b18a988750dfc52010c41787c08ffc2f92ba6b33c6cc2ab11dfd7bc45b1956a1c29a938a1697112ae2411a6da87ce51c1b7e658bb8c0803c4b695133af022
data/examples/demo.rb CHANGED
@@ -6,6 +6,10 @@ def delay(sec, speed=1.0)
6
6
  sleep sec/speed
7
7
  end
8
8
 
9
+ speed = ARGV.first || 1.0
10
+ speed = speed.to_f
11
+ delay(speed)
12
+
9
13
  RubyText.start(:_cbreak, log: "mylog.txt", fg: :green, bg: :black)
10
14
 
11
15
  print "Here goes... "
@@ -46,7 +50,7 @@ delay 3
46
50
 
47
51
  puts "\n\nNow watch as I create a window:"
48
52
 
49
- mywin = RubyText.window(16, 40, 8, 14, true, fg: :blue, bg: :yellow)
53
+ mywin = RubyText.window(16, 40, 8, 14, fg: :blue, bg: :yellow)
50
54
 
51
55
  delay 3
52
56
  mywin.puts "\nNow I'm writing in a window."
@@ -94,7 +98,7 @@ mywin.output do
94
98
  c = rand(mywin.cols)
95
99
  mywin[r, c] = "*"
96
100
  end
97
- mywin.win.refresh
101
+ mywin.cwin.refresh
98
102
  end
99
103
 
100
104
  delay 5
data/lib/color.rb CHANGED
@@ -39,6 +39,6 @@ class RubyText::Window
39
39
  end
40
40
 
41
41
  def fg=(sym)
42
- self.colors(@win, fg, @bg)
42
+ self.colors(@cwin, fg, @bg)
43
43
  end
44
44
  end
data/lib/navigation.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class RubyText::Window
2
2
  def go(r, c)
3
3
  save = self.rc
4
- @win.setpos(r, c)
4
+ @cwin.setpos(r, c)
5
5
  if block_given?
6
6
  yield
7
7
  go(*save) # No block here!
@@ -68,6 +68,6 @@ class RubyText::Window
68
68
  end
69
69
 
70
70
  def rc
71
- [@win.cury, @win.curx]
71
+ [@cwin.cury, @cwin.curx]
72
72
  end
73
73
  end
data/lib/output.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  $LOAD_PATH << "lib"
2
2
 
3
+ require 'global' # FIXME later
4
+
3
5
  def debug(*args)
4
6
  return unless $debug
5
7
  $debug.puts *args
@@ -8,7 +10,7 @@ end
8
10
  class RubyText::Window
9
11
  def center(str)
10
12
  r, c = self.rc
11
- n = @win.maxx - str.length
13
+ n = @cwin.maxx - str.length
12
14
  go r, n/2
13
15
  puts str
14
16
  end
@@ -25,7 +27,7 @@ class RubyText::Window
25
27
 
26
28
  def delegate_output(sym, *args)
27
29
  args = [""] if args.empty?
28
- RubyText::Window.colors(@win, @fg, @bg) # FIXME?
30
+ RubyText::Window.colors(@cwin, @fg, @bg) # FIXME?
29
31
  if sym == :p
30
32
  args.map!(&:inspect)
31
33
  else
@@ -42,16 +44,16 @@ class RubyText::Window
42
44
  # Limitation: Can't print color symbols!
43
45
  args.each do |arg|
44
46
  if arg.is_a? Symbol # must be a color
45
- RubyText::Window.colors(@win, arg, @bg) # FIXME?
47
+ RubyText::Window.colors(@cwin, arg, @bg) # FIXME?
46
48
  elsif arg.is_a? RubyText::Effects
47
49
  X.attrset(arg.value)
48
50
  else
49
- arg.each_char {|ch| ch == "\n" ? crlf : @win.addch(ch) }
51
+ arg.each_char {|ch| ch == "\n" ? crlf : @cwin.addch(ch) }
50
52
  end
51
53
  end
52
54
  crlf if flag
53
- RubyText::Window.colors(@win, @fg, @bg) # FIXME?
54
- @win.refresh
55
+ RubyText::Window.colors(@cwin, @fg, @bg) # FIXME?
56
+ @cwin.refresh
55
57
  end
56
58
 
57
59
  def puts(*args)
@@ -71,14 +73,18 @@ class RubyText::Window
71
73
  end
72
74
 
73
75
  def rcprint!(r, c, *args)
74
- @win.setpos(r, c) # Cursor isn't restored
76
+ @cwin.setpos(r, c) # Cursor isn't restored
75
77
  self.print *args
76
78
  end
77
79
 
78
80
  def crlf
79
81
  # Technically not output...
80
82
  r, c = rc
81
- go r+1, 0
83
+ if r < @rows - 1 && !@scrolling
84
+ go r+1, 0
85
+ else
86
+ scroll
87
+ end
82
88
  end
83
89
 
84
90
  def self.clear(win)
@@ -90,7 +96,7 @@ class RubyText::Window
90
96
  end
91
97
 
92
98
  def clear
93
- win = @win
99
+ win = @cwin
94
100
  num = win.maxx * win.maxy
95
101
  win.setpos(0, 0)
96
102
  win.addstr(' '*num)
@@ -106,17 +112,17 @@ class RubyText::Window
106
112
 
107
113
  def [](r, c)
108
114
  save = self.rc
109
- @win.setpos r, c
110
- ch = @win.inch
111
- @win.setpos *save
115
+ @cwin.setpos r, c
116
+ ch = @cwin.inch
117
+ @cwin.setpos *save
112
118
  ch.chr
113
- # go(r, c) { ch = @win.inch }
119
+ # go(r, c) { ch = @cwin.inch }
114
120
  end
115
121
 
116
122
  def []=(r, c, char)
117
- @win.setpos(r, c)
118
- @win.addch(char[0])
119
- @win.refresh
123
+ @cwin.setpos(r, c)
124
+ @cwin.addch(char[0])
125
+ @cwin.refresh
120
126
  end
121
127
 
122
128
  def boxme
@@ -125,7 +131,7 @@ class RubyText::Window
125
131
  end
126
132
 
127
133
  def refresh
128
- @win.refresh
134
+ @cwin.refresh
129
135
  end
130
136
  end
131
137
 
data/lib/rubytext.rb CHANGED
@@ -8,6 +8,9 @@ X = Curses # shorthand
8
8
  Black, Blue, Cyan, Green, Magenta, Red, White, Yellow =
9
9
  :black, :blue, :cyan, :green, :magenta, :red, :white, :yellow
10
10
 
11
+ module RubyText
12
+ end
13
+
11
14
  require 'version'
12
15
  require 'output' # RubyText, RubyText::Window, Kernel
13
16
  require 'keys' # RubyText::Keys
data/lib/settings.rb CHANGED
@@ -70,9 +70,9 @@ module RubyText
70
70
  @flags = @defaults
71
71
  end
72
72
 
73
- def self.start(*args, log: nil, fg: nil, bg: nil)
73
+ def self.start(*args, log: nil, fg: nil, bg: nil, scroll: false)
74
74
  $debug = File.new(log, "w") if log
75
- Object.const_set(:STDSCR, RubyText::Window.main(fg: fg, bg: bg))
75
+ Object.const_set(:STDSCR, RubyText::Window.main(fg: fg, bg: bg, scroll: scroll))
76
76
  $stdscr = STDSCR
77
77
  fg, bg, cp = fb2cp(fg, bg)
78
78
  self.set(:_echo, :cbreak, :raw) # defaults
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.0.60"
3
+ VERSION = "0.0.61"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
data/lib/window.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class RubyText::Window
2
2
  Vert, Horiz = X::A_VERTICAL, X::A_HORIZONTAL
3
3
 
4
- attr_reader :win, :rows, :cols, :width, :height
4
+ attr_reader :cwin, :rows, :cols, :width, :height
5
5
  attr_writer :fg, :bg
6
6
 
7
7
  # Better to use Window.window IRL
@@ -10,82 +10,87 @@ class RubyText::Window
10
10
  debug "RT::Win.init: #{[high, wide, r0, c0, border]}"
11
11
  @wide, @high, @r0, @c0 = wide, high, r0, c0
12
12
  @border, @fg, @bg = border, fg, bg
13
- @win = X::Window.new(high, wide, r0, c0)
14
- debug "outer = #{@win.inspect}"
13
+ @cwin = X::Window.new(high, wide, r0, c0)
14
+ debug "outer = #{@cwin.inspect}"
15
15
  debug "@border = #@border"
16
- debug "Calling 'colors': #{[@win, fg, bg]}"
17
- RubyText::Window.colors!(@win, fg, bg)
16
+ debug "Calling 'colors': #{[@cwin, fg, bg]}"
17
+ RubyText::Window.colors!(@cwin, fg, bg)
18
18
  if @border
19
- @win.box(Vert, Horiz)
20
- @outer = @win
19
+ @cwin.box(Vert, Horiz)
20
+ @outer = @cwin
21
21
  @outer.refresh
22
22
  debug "About to call again: params = #{[high-2, wide-2, r0+1, c0+1]}"
23
- @win = X::Window.new(high-2, wide-2, r0+1, c0+1)
24
- RubyText::Window.colors!(@win, fg, bg)
23
+ @cwin = X::Window.new(high-2, wide-2, r0+1, c0+1)
24
+ RubyText::Window.colors!(@cwin, fg, bg)
25
25
  else
26
- @outer = @win
26
+ @outer = @cwin
27
27
  end
28
- @rows, @cols = @win.maxy, @win.maxx # unnecessary really...
28
+ @rows, @cols = @cwin.maxy, @cwin.maxx # unnecessary really...
29
29
  @width, @height = @cols + 2, @rows + 2 if @border
30
- @win.scrollok(true) if scroll
31
- @win.refresh
30
+ @scrolling = scroll
31
+ @cwin.scrollok(scroll)
32
+ @cwin.refresh
32
33
  end
33
34
 
34
35
  def self.main(fg: nil, bg: nil, scroll: false)
35
36
  @main_win = X.init_screen
36
37
  X.start_color
37
38
  colors!(@main_win, fg, bg)
39
+ @cwin = @main_win # FIXME?
38
40
  rows, cols = @main_win.maxy, @main_win.maxx
39
- @screen = self.make(@main_win, rows, cols, 0, 0, false,
41
+ @screen = self.make(@main_win, rows, cols, 0, 0, border: false,
40
42
  fg: fg, bg: bg, scroll: scroll)
41
43
  # FIXME Why is this hard to inline?
42
- # @win = @main_win
44
+ ## Must be params...?
45
+ ## def self.make(cwin, high, wide, r0, c0, border, fg: White, bg: Black, scroll: false)
43
46
  # obj = self.allocate
44
47
  # obj.instance_eval do
45
- # @outer = @win = @main_win
48
+ # @outer = @cwin = @main_win
46
49
  # @wide, @high, @r0, @c0 = cols, rows, 0, 0
47
50
  # @fg, @bg = fg, bg
48
51
  # @border = false
49
52
  # @rows, @cols = @high, @wide
50
53
  # @width, @height = @cols + 2, @rows + 2 if @border
51
54
  # end
52
- # @win = @main_win # FIXME?
55
+ # obj.scrolling(scroll)
53
56
  # obj
54
- @screen
55
57
  end
56
58
 
57
- def self.make(cwin, high, wide, r0, c0, border, fg: White, bg: Black, scroll: false)
59
+ def self.make(cwin, high, wide, r0, c0, border: true, fg: White, bg: Black, scroll: false)
58
60
  obj = self.allocate
59
61
  obj.instance_eval do
60
62
  # debug " Inside instance_eval..."
61
- @outer = @win = cwin
63
+ @outer = @cwin = cwin
62
64
  @wide, @high, @r0, @c0 = wide, high, r0, c0
63
65
  @fg, @bg = fg, bg
64
66
  @border = border
65
67
  @rows, @cols = high, wide
66
68
  @width, @height = @cols + 2, @rows + 2 if @border
67
69
  end
70
+ obj.scrolling(scroll)
68
71
  obj
69
72
  end
70
73
 
71
- def scrolling
72
- @win.scrollok(true)
74
+ # FIXME refactor bad code
75
+
76
+ def scrolling(flag=true)
77
+ @cwin.scrollok(flag)
73
78
  end
74
79
 
75
80
  def noscroll
76
- @win.scrollok(false)
81
+ @cwin.scrollok(false)
77
82
  end
78
83
 
79
84
  def scroll(n=1)
80
85
  n.times do |i|
81
- @win.scroll
86
+ @cwin.scroll
82
87
  go(@rows-1, 0)
83
88
  noscroll
84
89
  print(' '*@cols)
85
90
  scrolling
86
91
  left!
87
92
  end
88
- @win.refresh
93
+ @cwin.refresh
89
94
  end
90
95
 
91
96
  def screen_text(file = nil)
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.60
4
+ version: 0.0.61
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton