rubytext 0.1.4 → 0.1.5

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: 1fdecc3c5bfb6c33fbd4a818d2f376f0bde01c416cc4639ccc30d251b656968b
4
- data.tar.gz: 168b787efee37e97b674c4a3cc176245e9d4449db96a31cd875b97ab1dc6c86f
3
+ metadata.gz: 639051dd8b75b79ea2fcd3b2b3c348393221429528c3fee94ba2d477d9021878
4
+ data.tar.gz: 4bcc89047ec533e1b9b517f3cf0cb236f7ed9474d855ec82c5ec8e8310417e68
5
5
  SHA512:
6
- metadata.gz: 2c179cce895108856d7a8aa0d0d52d2a2a3775254452a4c3abd27402a7e62e62ab321a0cb921dbc75614a84ce2303fb0020ca878582d2ccf4aa099fdb1c483df
7
- data.tar.gz: 92d2b5858741a6a22f10dac8d7da62498dee78829e5b6d4c46db164b9e89520e2b39344452def8b28fc8612d2afed4449c2b61250f02c9bdf7f72cac57c69373
6
+ metadata.gz: bde3e200841bb7f2b308c975d8d5553a897cbce44c8d7f47f940e7d5b324e35177701465a76f505eea35fa77b1fd9873e983333d40639b64b8330aee201b2171
7
+ data.tar.gz: 58aa416a667d26001f78346cc0d91194a598ad1521cb1d593a62f203c2a4d5e2eaf46940c703583fc37fc074ca8d68bb5f9241c27c255591f0cb2c460830d9ad
data/bin/rubytext CHANGED
@@ -10,7 +10,7 @@ case cmd
10
10
  when nil
11
11
  STDOUT.puts "Usage: rubytext [demo|slides]"
12
12
  when "demo"
13
- system("ruby #{path}/../examples/demo.rb")
13
+ system("ruby #{path}/../examples/demo.rb #{arg}")
14
14
  when "slides"
15
15
  system("#{path}/../examples/slides")
16
16
  when "tutorial"
data/examples/demo.rb CHANGED
@@ -2,15 +2,15 @@ $LOAD_PATH.unshift "lib"
2
2
 
3
3
  require 'rubytext'
4
4
 
5
- def delay(sec, speed=1.0)
6
- sleep sec/speed
5
+ def delay(sec)
6
+ sleep sec/@speed
7
7
  end
8
8
 
9
9
  speed = ARGV.first || 1.0
10
- speed = speed.to_f
11
- delay(speed)
10
+ @speed = speed.to_f
11
+ delay 1
12
12
 
13
- RubyText.start(log: "mylog.txt", fg: :green, bg: :black)
13
+ RubyText.start(log: "mylog.txt", fg: Blue, bg: Black)
14
14
 
15
15
  print "Here goes... "
16
16
  delay 2
data/examples/ide.rb CHANGED
@@ -15,9 +15,9 @@ def shell(str)
15
15
  system("stty sane") # FIXME - dumb hack
16
16
  STDSCR.puts "\n\n When you exit, you will\n return to the IDE.\n "
17
17
  system(str)
18
- X.noecho # FIXME Shouldn't have to do this stuff
19
- X.stdscr.keypad(true)
20
- X.cbreak # by default
18
+ Curses.noecho # FIXME Shouldn't have to do this stuff
19
+ Curses.stdscr.keypad(true)
20
+ Curses.cbreak # by default
21
21
  end
22
22
 
23
23
  items = ["Edit lib", # 0
@@ -0,0 +1,17 @@
1
+ STDSCR.scrolling(true)
2
+
3
+ puts "We use #scrolling to turn the scrolling feature on or off"
4
+ puts "for any window (including STDSCR). It's off by default."
5
+
6
+ win2 = RubyText.window(6, 50, r: 6, c: 29, fg: Blue, bg: Black)
7
+ win2.puts "\nThis is\njust some more\nrandom text..."
8
+ win2.scrolling(true)
9
+
10
+ puts "\nNote that we can scroll up or down... but there is no \"buffer\" for text."
11
+ sleep 3
12
+ 3.times { win2.scroll(1); sleep 0.2 }; sleep 1
13
+ 3.times { win2.scroll(-1); sleep 0.2 }; sleep 4
14
+
15
+ puts "\nNOTE: If you scroll STDSCR, other windows will disappear! This may be fixed later."
16
+ sleep 3
17
+ 3.times { STDSCR.scroll(-1); sleep 0.2 }
data/examples/slides CHANGED
@@ -36,5 +36,6 @@ showme("no_scroll")
36
36
  showme("window_full")
37
37
  showme("spin")
38
38
  showme("ticker_threads", 11)
39
+ showme("scrolling")
39
40
  showme("simple_menu")
40
41
 
data/lib/color.rb CHANGED
@@ -12,7 +12,7 @@ class RubyText::Color
12
12
  # TODO add color-pair constants
13
13
 
14
14
  def self.sym2const(color) # to curses constant
15
- X.const_get("COLOR_#{color.to_s.upcase}")
15
+ Curses.const_get("COLOR_#{color.to_s.upcase}")
16
16
  end
17
17
 
18
18
  def self.index(color)
@@ -22,7 +22,7 @@ class RubyText::Color
22
22
  def self.pair(fg, bg)
23
23
  nf, nb = index(fg), index(bg)
24
24
  num = 8*nf + nb
25
- X.init_pair(num, sym2const(fg), sym2const(bg))
25
+ Curses.init_pair(num, sym2const(fg), sym2const(bg))
26
26
  num
27
27
  end
28
28
  end
data/lib/effects.rb CHANGED
@@ -6,10 +6,10 @@ def fx(str, *args, bg: nil)
6
6
  end
7
7
 
8
8
  class RubyText::Effects # dumb name?
9
- Modes = {bold: X::A_BOLD,
10
- normal: X::A_NORMAL,
11
- reverse: X::A_REVERSE,
12
- under: X::A_UNDERLINE}
9
+ Modes = {bold: Curses::A_BOLD,
10
+ normal: Curses::A_NORMAL,
11
+ reverse: Curses::A_REVERSE,
12
+ under: Curses::A_UNDERLINE}
13
13
 
14
14
  Others = %[:show, :hide] # show/hide cursor; more later??
15
15
 
data/lib/menu.rb CHANGED
@@ -22,7 +22,7 @@ module RubyText
22
22
  self.print fx("[ #{title} ]", :bold, fg, bg: bg)
23
23
  end
24
24
  end
25
- X.stdscr.keypad(true)
25
+ Curses.stdscr.keypad(true)
26
26
  sel = curr
27
27
  max = items.size - 1
28
28
  loop do
@@ -35,9 +35,9 @@ module RubyText
35
35
  end
36
36
  ch = getch
37
37
  case ch
38
- when X::KEY_UP
38
+ when Curses::KEY_UP
39
39
  sel -= 1 if sel > 0
40
- when X::KEY_DOWN
40
+ when Curses::KEY_DOWN
41
41
  sel += 1 if sel < max
42
42
  when 27
43
43
  self.restback(high, wide, r, c)
@@ -47,7 +47,7 @@ module RubyText
47
47
  self.restback(high, wide, r, c)
48
48
  RubyText.show_cursor
49
49
  return [sel, items[sel]]
50
- else X.beep
50
+ else Curses.beep
51
51
  end
52
52
  RubyText.show_cursor
53
53
  end
@@ -60,9 +60,9 @@ module RubyText
60
60
  win2:, callback:, enter: nil, quit: "q")
61
61
  high = rows
62
62
  wide = cols
63
- mwin = RubyText.indow(high, wide, r: r, c: c, fg: fg, bg: bg)
63
+ mwin = RubyText.window(high, wide, r: r, c: c, fg: fg, bg: bg)
64
64
  handler = callback
65
- X.stdscr.keypad(true)
65
+ Curses.stdscr.keypad(true)
66
66
  RubyText.hide_cursor
67
67
  sel = 0
68
68
  max = items.size - 1
@@ -76,12 +76,12 @@ module RubyText
76
76
  end
77
77
  ch = getch
78
78
  case ch
79
- when X::KEY_UP
79
+ when Curses::KEY_UP
80
80
  if sel > 0
81
81
  sel -= 1
82
82
  handler.call(sel, items[sel], win2)
83
83
  end
84
- when X::KEY_DOWN
84
+ when Curses::KEY_DOWN
85
85
  if sel < max
86
86
  sel += 1
87
87
  handler.call(sel, items[sel], win2)
@@ -95,10 +95,10 @@ module RubyText
95
95
  end
96
96
  end
97
97
  when 9 # tab
98
- X.flash
98
+ Curses.flash
99
99
  when quit # parameter
100
100
  exit
101
- else X.beep # all else is trash
101
+ else Curses.beep # all else is trash
102
102
  end
103
103
  end
104
104
  rescue
data/lib/output.rb CHANGED
@@ -124,7 +124,7 @@ class RubyText::Window
124
124
 
125
125
  def []=(r, c, char)
126
126
  @cwin.setpos(r, c)
127
- @cwin.addch(char[0].ord|X::A_NORMAL)
127
+ @cwin.addch(char[0].ord|Curses::A_NORMAL)
128
128
  @cwin.setpos(r, c)
129
129
  @cwin.refresh
130
130
  end
@@ -239,7 +239,7 @@ class RubyText::Window
239
239
  next if @history.nil? # move this?
240
240
  gs.history_next
241
241
  when Integer
242
- X.beep
242
+ Curses.beep
243
243
  else
244
244
  gs.add(ch)
245
245
  end
@@ -273,7 +273,7 @@ module WindowIO
273
273
  # FIXME These don't/can't honor @started flag...
274
274
 
275
275
  def getch
276
- X.getch
276
+ Curses.getch
277
277
  end
278
278
 
279
279
  def gets # still needs improvement
data/lib/rubytext.rb CHANGED
@@ -2,8 +2,6 @@ $LOAD_PATH << "lib"
2
2
 
3
3
  require 'curses'
4
4
 
5
- X = Curses # shorthand. klunky I know
6
-
7
5
  module RubyText
8
6
  end
9
7
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
data/lib/settings.rb CHANGED
@@ -61,16 +61,16 @@ module RubyText
61
61
  @flags.uniq!
62
62
  flag = arg.to_s
63
63
  if standard.include?(flag.to_sym) || standard.include?(flag.sub(/no/, "_").to_sym)
64
- X.send(flag)
64
+ Curses.send(flag)
65
65
  elsif flag[0] == "_" && standard.include?(flag[1..-1].to_sym)
66
66
  flag.sub!(/^_/, "no")
67
- X.send(flag)
67
+ Curses.send(flag)
68
68
  else
69
69
  case flag.to_sym
70
70
  when :cursor
71
- X.curs_set(1)
71
+ Curses.curs_set(1)
72
72
  when :_cursor, :nocursor
73
- X.curs_set(0)
73
+ Curses.curs_set(0)
74
74
  when :keypad
75
75
  STDSCR.cwin.keypad(true)
76
76
  when :_keypad
@@ -109,7 +109,7 @@ module RubyText
109
109
 
110
110
  def self.stop
111
111
  @started = false
112
- X.close_screen
112
+ Curses.close_screen
113
113
  end
114
114
 
115
115
  # For passing through arbitrary method calls
@@ -118,22 +118,22 @@ module RubyText
118
118
  def self.method_missing(name, *args)
119
119
  debug "method_missing: #{name} #{args.inspect}"
120
120
  if name[0] == '_'
121
- X.send(name[1..-1], *args)
121
+ Curses.send(name[1..-1], *args)
122
122
  else
123
123
  raise "#{name} #{args.inspect}" # NoMethodError
124
124
  end
125
125
  end
126
126
 
127
127
  def self.hide_cursor
128
- X.curs_set(0)
128
+ Curses.curs_set(0)
129
129
  end
130
130
 
131
131
  def self.show_cursor
132
- X.curs_set(1)
132
+ Curses.curs_set(1)
133
133
  end
134
134
 
135
135
  def self.show_cursor!
136
- X.curs_set(2) # Doesn't work? Device-dependent?
136
+ Curses.curs_set(2) # Doesn't work? Device-dependent?
137
137
  end
138
138
  end
139
139
 
data/lib/window.rb CHANGED
@@ -10,7 +10,7 @@ module RubyText
10
10
  end
11
11
 
12
12
  class RubyText::Window
13
- Vert, Horiz = X::A_VERTICAL, X::A_HORIZONTAL
13
+ Vert, Horiz = Curses::A_VERTICAL, Curses::A_HORIZONTAL
14
14
 
15
15
  attr_reader :cwin, :rows, :cols, :width, :height, :scrolling
16
16
  attr_reader :r0, :c0
@@ -22,13 +22,13 @@ class RubyText::Window
22
22
  fg=White, bg=Blue, scroll=false)
23
23
  @wide, @high, @r0, @c0 = wide, high, r0, c0
24
24
  @border, @fg, @bg = border, fg, bg
25
- @cwin = X::Window.new(high, wide, r0, c0)
25
+ @cwin = Curses::Window.new(high, wide, r0, c0)
26
26
  colorize!(fg, bg)
27
27
  if @border
28
28
  @cwin.box(Vert, Horiz)
29
29
  @outer = @cwin
30
30
  @outer.refresh
31
- @cwin = X::Window.new(high-2, wide-2, r0+1, c0+1)
31
+ @cwin = Curses::Window.new(high-2, wide-2, r0+1, c0+1)
32
32
  colorize!(fg, bg)
33
33
  else
34
34
  @outer = @cwin
@@ -42,8 +42,8 @@ class RubyText::Window
42
42
 
43
43
  def self.main(fg: White, bg: Blue, scroll: false)
44
44
  debug "Starting #main..."
45
- main_win = X.init_screen
46
- X.start_color
45
+ main_win = Curses.init_screen
46
+ Curses.start_color
47
47
  self.colorize!(main_win, fg, bg)
48
48
  rows, cols = main_win.maxy, main_win.maxx
49
49
  win = self.make(main_win, rows, cols, 0, 0, border: false,
@@ -77,11 +77,6 @@ class RubyText::Window
77
77
  @cwin.scrollok(flag)
78
78
  end
79
79
 
80
- def noscroll
81
- @scrolling = false
82
- @cwin.scrollok(false)
83
- end
84
-
85
80
  def scroll(n=1)
86
81
  if n < 0
87
82
  @cwin.scrl(n)
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-01 00:00:00.000000000 Z
11
+ date: 2019-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -61,6 +61,7 @@ files:
61
61
  - examples/putch.rb
62
62
  - examples/puts_print.rb
63
63
  - examples/rcprint.rb
64
+ - examples/scrolling.rb
64
65
  - examples/showme.rb
65
66
  - examples/simple_menu.rb
66
67
  - examples/simple_win.rb