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
-
.is_windows? ⇒ Boolean
Detects if 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
Constructor Details
#initialize ⇒ TUI
Returns a new instance of TUI.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kaitai/tui.rb', line 12 def initialize if TUI::is_windows? require 'kaitai/console_windows' @console = ConsoleWindows.new @highlight_colors = [ :white, :aqua, :blue, :green, :white, ] else require 'kaitai/console_ansi' @console = ConsoleANSI.new @highlight_colors = [ :gray14, :gray11, :gray8, :gray5, :gray2, ] 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
.is_windows? ⇒ Boolean
Detects if current platform is Windows-based.
104 105 106 |
# File 'lib/kaitai/tui.rb', line 104 def self.is_windows? @@is_windows end |
Instance Method Details
#draw_button(x, y, w, caption) ⇒ Object
94 95 96 97 |
# File 'lib/kaitai/tui.rb', line 94 def (x, y, w, caption) goto(x, y) puts "[ #{caption} ]" end |
#draw_rectangle(x, y, w, h, charset = DOUBLE_CHARSET) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/kaitai/tui.rb', line 75 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 { |i| goto(x, i) print charset[CHAR_V] print ' ' * (w - 2) print charset[CHAR_V] } goto(x, y + h) print charset[CHAR_BL] print charset[CHAR_H] * (w - 2) print charset[CHAR_BR] end |
#input_str(header, msg) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/kaitai/tui.rb', line 65 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
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/kaitai/tui.rb', line 51 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 { c = @console.read_char_mapped return if c == :enter } end |
#message_box_exception(e) ⇒ Object
36 37 38 |
# File 'lib/kaitai/tui.rb', line 36 def (e) ("Error while parsing", e.) end |