class TicTacToe::TUI

Public Class Methods

new() click to toggle source
# File lib/tic_tac_toe/tui.rb, line 10
def initialize
  TUI::Setup.call
end

Public Instance Methods

board!(*args) click to toggle source
# File lib/tic_tac_toe/tui.rb, line 22
def board!(*args)
  @board ||= TUI::Board.new(*args)
  @board.update(*args)
end
clear() click to toggle source
# File lib/tic_tac_toe/tui.rb, line 37
def clear
  @board.window.close
  Curses.clear
  Curses.refresh

  @board = @cursor = @status = nil
end
cursor!(*args) click to toggle source
# File lib/tic_tac_toe/tui.rb, line 27
def cursor!(*args)
  @cursor ||= TUI::Cursor.new(@board.window)
  @cursor.update(*args)
end
listen() { |key| ... } click to toggle source
# File lib/tic_tac_toe/tui.rb, line 14
def listen
  loop do
    key = getch
    yield key
  end
rescue Interrupt
end
status!(*args) click to toggle source
# File lib/tic_tac_toe/tui.rb, line 32
def status!(*args)
  @status ||= TUI::Status.new(@board.window)
  @status.update(*args)
end

Private Instance Methods

getch() click to toggle source
# File lib/tic_tac_toe/tui.rb, line 47
def getch
  case key = @board.window.getch
  when String  # printable character
    key
  when Integer # special key
    Curses::Key.constants
      .find { |name| Curses::Key.const_get(name) == key }
  end
end