Class: Kaitai::TUI
Constant Summary collapse
- SINGLE_CHARSET =
'┌┐└┘─│'- HEAVY_CHARSET =
'┏┓┗┛━┃'- DOUBLE_CHARSET =
'╔╗╚╝═║'- CHAR_TL =
0- CHAR_TR =
1- CHAR_BL =
2- CHAR_BR =
3- CHAR_H =
4- CHAR_V =
5- @@is_windows =
(RUBY_PLATFORM =~ /cygwin|mswin|mingw|bccwin|wince|emx/) ? true : false
Instance Attribute Summary collapse
-
#highlight_colors ⇒ Object
readonly
Returns the value of attribute highlight_colors.
Class Method Summary collapse
-
.windows? ⇒ Boolean
Detects whether the current platform is Windows-based.
Instance Method Summary collapse
- #draw_button(x, y, _w, caption) ⇒ Object
- #draw_rectangle(x, y, w, h, charset = DOUBLE_CHARSET) ⇒ Object
-
#initialize ⇒ TUI
constructor
A new instance of TUI.
- #input_str(header, _msg) ⇒ Object
- #message_box(header, msg) ⇒ Object
- #message_box_exception(e) ⇒ Object
- #on_resize=(handler) ⇒ Object
Constructor Details
#initialize ⇒ TUI
Returns a new instance of TUI.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kaitai/tui.rb', line 12 def initialize if TUI.windows? require 'kaitai/console_windows' @console = ConsoleWindows.new @highlight_colors = %i[bright_white bright_cyan cyan gray] else require 'kaitai/console_ansi' @console = ConsoleANSI.new @highlight_colors = %i[bright_white bright_cyan cyan gray] end end |
Instance Attribute Details
#highlight_colors ⇒ Object (readonly)
Returns the value of attribute highlight_colors.
10 11 12 |
# File 'lib/kaitai/tui.rb', line 10 def highlight_colors @highlight_colors end |
Class Method Details
.windows? ⇒ Boolean
Detects whether the current platform is Windows-based.
96 97 98 |
# File 'lib/kaitai/tui.rb', line 96 def self.windows? @@is_windows end |
Instance Method Details
#draw_button(x, y, _w, caption) ⇒ Object
86 87 88 89 |
# File 'lib/kaitai/tui.rb', line 86 def (x, y, _w, caption) goto(x, y) puts "[ #{caption} ]" end |
#draw_rectangle(x, y, w, h, charset = DOUBLE_CHARSET) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kaitai/tui.rb', line 67 def draw_rectangle(x, y, w, h, charset = DOUBLE_CHARSET) goto(x, y) print charset[CHAR_TL] print charset[CHAR_H] * (w - 2) print charset[CHAR_TR] ((y + 1)..(y + h - 1)).each do |i| goto(x, i) print charset[CHAR_V] print ' ' * (w - 2) print charset[CHAR_V] end goto(x, y + h) print charset[CHAR_BL] print charset[CHAR_H] * (w - 2) print charset[CHAR_BR] end |
#input_str(header, _msg) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/kaitai/tui.rb', line 57 def input_str(header, _msg) top_y = @console.rows / 2 - 5 draw_rectangle(10, top_y, @console.cols - 20, 10) goto(@console.cols / 2 - (header.length / 2) - 1, top_y) print ' ', header, ' ' goto(11, top_y + 1) Readline.readline('', false) end |
#message_box(header, msg) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kaitai/tui.rb', line 43 def (header, msg) top_y = @console.rows / 2 - 5 draw_rectangle(10, top_y, @console.cols - 20, 10) @console.goto(@console.cols / 2 - (header.length / 2) - 1, top_y) print ' ', header, ' ' @console.goto(11, top_y + 1) puts msg (@console.cols / 2 - 10, top_y + 8, 10, 'OK') loop do c = @console.read_char_mapped return if c == :enter end end |
#message_box_exception(e) ⇒ Object
28 29 30 |
# File 'lib/kaitai/tui.rb', line 28 def (e) ('Error while parsing', e.) end |
#on_resize=(handler) ⇒ Object
24 25 26 |
# File 'lib/kaitai/tui.rb', line 24 def on_resize=(handler) @console.on_resize = handler end |