class Kaitai::TUI

Constants

CHAR_BL
CHAR_BR
CHAR_H
CHAR_TL
CHAR_TR
CHAR_V
DOUBLE_CHARSET
HEAVY_CHARSET
SINGLE_CHARSET

Attributes

highlight_colors[R]

Public Class Methods

is_windows?() click to toggle source

Detects if current platform is Windows-based.

# File lib/kaitai/tui.rb, line 108
def self.is_windows?
  @@is_windows
end
new() click to toggle source
# 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

Public Instance Methods

draw_button(x, y, w, caption) click to toggle source
# File lib/kaitai/tui.rb, line 98
def draw_button(x, y, w, caption)
  goto(x, y)
  puts "[ #{caption} ]"
end
draw_rectangle(x, y, w, h, charset = DOUBLE_CHARSET) click to toggle source
# File lib/kaitai/tui.rb, line 79
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) click to toggle source
# File lib/kaitai/tui.rb, line 69
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) click to toggle source
# File lib/kaitai/tui.rb, line 55
def message_box(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
  draw_button(@console.cols / 2 - 10, top_y + 8, 10, 'OK')
  loop {
    c = @console.read_char_mapped
    return if c == :enter
  }
end
message_box_exception(e) click to toggle source
# File lib/kaitai/tui.rb, line 40
def message_box_exception(e)
  message_box("Error while parsing", e.message)
end
on_resize=(handler) click to toggle source
# File lib/kaitai/tui.rb, line 36
def on_resize=(handler)
  @console.on_resize = handler
end