rubytext 0.0.20 → 0.0.21

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.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/lib/rubytext.rb +41 -17
  3. data/lib/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 01d2a45364981d0139df502a40e86e0b3cbd1186bae314e1f987dc704ba0c5cc
4
- data.tar.gz: bab37c6c328abe1d33fd75c8a8f2c0e2a691a211f6f272d334802b5e4a219486
2
+ SHA1:
3
+ metadata.gz: a05b2ae8802e7304f0787f3a8823738d43ff6ee8
4
+ data.tar.gz: 2232e7b343f4b9410bf4b7e00df24b854b63d7e4
5
5
  SHA512:
6
- metadata.gz: 6cb6a7992dfc787cceffcef1036ec5678fddde72ea2ec22cbeef9e00e1fc01bb36ac9ae81c17102bb31ca948a5b7f0fe5d00e433dcf10faf9d18850c65d1160c
7
- data.tar.gz: 39f142d6bc3136ff4bfefa80926753ffdec548a522b4a6d0ac363de83ca2417425ee53d7416e53a9ae3748b6247529acff52dc09663205b83dec74b3739026ee
6
+ metadata.gz: 9528eaf48304325b79286e892c6516f15730d46ab0aafe6368f4d1b3db43c8032ad07a2c2fcbc8d708138b66f3f9997d2b051970dbf6bd104c4a31265b151518
7
+ data.tar.gz: 3d33beb960f317a38e1de21c4f0eda0b90d49ca83d307b38eefc8ed2a60f91981854a9b7af258165711ed319b3ab184f841985d1ccf0dd8244f5dcd0bbf451a7
data/lib/rubytext.rb CHANGED
@@ -12,6 +12,8 @@ def debug(*args)
12
12
  end
13
13
 
14
14
  def fb2cp(fg, bg)
15
+ fg ||= :blue
16
+ bg ||= :white
15
17
  debug "Colors are: #{fg} on #{bg}"
16
18
  fg = X.const_get("COLOR_#{fg.upcase}")
17
19
  bg = X.const_get("COLOR_#{bg.upcase}")
@@ -56,16 +58,24 @@ module RubyText
56
58
  end
57
59
 
58
60
  class Window
61
+
62
+ def self.colors(win, fg, bg)
63
+ cfg, cbg, cp = fb2cp(fg, bg)
64
+ X.init_pair(cp, cfg, cbg)
65
+ win.color_set(cp|X::A_NORMAL)
66
+ num = win.maxx * win.maxy
67
+ win.addstr(' '*num)
68
+ win.setpos(0, 0)
69
+ win.refresh
70
+ end
71
+
59
72
  def self.main(fg: nil, bg: nil)
60
73
  debug "Entering Window.main (#{fg}, #{bg}) => "
61
- fg, bg, cp = fb2cp(fg, bg)
62
- debug " computed #{fg}, #{bg}, #{cp}"
63
- debug " cp|A_NORMAL = #{cp|X::A_NORMAL}"
64
74
  @main_win = X.init_screen
65
75
  X.start_color
66
- X.stdscr.bkgd(cp|X::A_NORMAL)
67
- rows, cols = @main_win.maxy, @main_win.maxx
76
+ colors(@main_win, fg, bg)
68
77
  debug "About to call .make"
78
+ rows, cols = @main_win.maxy, @main_win.maxx
69
79
  @screen = self.make(@main_win, rows, cols, 0, 0, false)
70
80
  @screen
71
81
  end
@@ -85,8 +95,10 @@ module RubyText
85
95
  obj
86
96
  end
87
97
  end
98
+
88
99
  end
89
100
 
101
+
90
102
  # debug "Setting STDSCR to Window.main"
91
103
 
92
104
  # STDSCR = RubyText::Window.main
@@ -112,13 +124,9 @@ module RubyText
112
124
  Object.const_set(:STDSCR, RubyText::Window.main(fg: fg, bg: bg))
113
125
  $stdscr = STDSCR
114
126
 
115
- fg ||= :white
116
- bg ||= :black
117
127
  debug "fg = #{fg} is not a valid color" unless Colors.include?(fg.to_s)
118
128
  debug "bg = #{bg} is not a valid color" unless Colors.include?(bg.to_s)
119
129
  fg, bg, cp = fb2cp(fg, bg)
120
- # X.bkgd(cp|X::A_NORMAL)
121
- # X.clear
122
130
  X.noecho
123
131
  X.stdscr.keypad(true)
124
132
  X.cbreak # by default
@@ -149,7 +157,7 @@ module RubyText
149
157
  end
150
158
  end
151
159
 
152
- def RubyText.window(high, wide, r0, c0, border=false, fg=nil, bg=nil)
160
+ def RubyText.window(high, wide, r0, c0, border=false, fg: nil, bg: nil)
153
161
  RubyText::Window.new(high, wide, r0, c0, border, fg, bg)
154
162
  end
155
163
 
@@ -168,24 +176,26 @@ module RubyText
168
176
  end
169
177
 
170
178
  class RubyText::Window
171
- Vert, Horiz = X::A_VERTICAL, X::A_HORIZONTAL # ?|, ?- # "\u2502", "\u2500"
179
+ Vert, Horiz = X::A_VERTICAL, X::A_HORIZONTAL
172
180
 
173
181
  attr_reader :win, :rows, :cols, :width, :height, :fg, :bg
174
182
 
175
- def initialize(high=nil, wide=nil, r0=1, c0=1, border=false, fg=:white, bg=:black)
183
+ def initialize(high=nil, wide=nil, r0=1, c0=1, border=false, fg=nil, bg=nil)
176
184
  debug "RT::Win.init: #{[high, wide, r0, c0, border]}"
177
185
  @wide, @high, @r0, @c0 = wide, high, r0, c0
178
- @border = border
179
- @fg, @bg = fg, bg
186
+ @border, @fg, @bg = border, fg, bg
180
187
  @win = X::Window.new(high, wide, r0, c0)
181
188
  debug "outer = #{@win.inspect}"
182
189
  debug "@border = #@border"
190
+ debug "Calling 'colors': #{[@win, fg, bg]}"
191
+ RubyText::Window.colors(@win, fg, bg)
183
192
  if @border
184
193
  @win.box(Vert, Horiz)
185
194
  @outer = @win
186
195
  @outer.refresh
187
196
  debug "About to call again: params = #{[high-2, wide-2, r0+1, c0+1]}"
188
197
  @win = X::Window.new(high-2, wide-2, r0+1, c0+1) # , false, fg, bg) # relative now??
198
+ RubyText::Window.colors(@win, fg, bg)
189
199
  else
190
200
  @outer = @win
191
201
  end
@@ -203,9 +213,13 @@ class RubyText::Window
203
213
  args.map!(&:to_s)
204
214
  end
205
215
  str = sprintf(*args)
206
- str << "\n" if sym != :print && str[-1] != "\n"
216
+ flag = true if sym != :print && str[-1] != "\n"
207
217
  # color-handling code here
208
- @win.addstr(str)
218
+ str.each_char do |ch|
219
+ ch == "\n" ? crlf : @win.addch(ch)
220
+ end
221
+ # @win.addstr(str)
222
+ crlf if flag
209
223
  @win.refresh
210
224
  end
211
225
 
@@ -244,12 +258,22 @@ class RubyText::Window
244
258
  go r+1, c
245
259
  end
246
260
 
261
+ def crlf
262
+ r, c = rc
263
+ go r+1, 0
264
+ end
265
+
247
266
  def rc
248
267
  [@win.cury, @win.curx]
249
268
  end
250
269
 
251
270
  def clear
252
- @win.clear
271
+ win = @win
272
+ num = win.maxx * win.maxy
273
+ win.setpos(0, 0)
274
+ win.addstr(' '*num)
275
+ win.setpos(0, 0)
276
+ win.refresh
253
277
  end
254
278
 
255
279
  def output(&block)
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.0.20"
3
+ VERSION = "0.0.21"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
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.20
4
+ version: 0.0.21
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-15 00:00:00.000000000 Z
11
+ date: 2018-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  requirements: []
56
56
  rubyforge_project:
57
- rubygems_version: 2.7.7
57
+ rubygems_version: 2.2.2
58
58
  signing_key:
59
59
  specification_version: 4
60
60
  summary: A thick wrapper for Curses