class TheFox::TermKit::CursesApp

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/termkit/app/app_curses.rb, line 13
def initialize
    @curses_timeout = CURSES_TIMEOUT
    
    @ui_inited = false
    @ui_closed = false
    
    super()
    
    #puts 'CursesApp->initialize'
end

Public Instance Methods

curses_timeout=(curses_timeout) click to toggle source
# File lib/termkit/app/app_curses.rb, line 24
def curses_timeout=(curses_timeout)
    @curses_timeout = curses_timeout
    Curses.timeout = @curses_timeout
end
draw_point(point, content) click to toggle source

See UIApp draw_point() method.

# File lib/termkit/app/app_curses.rb, line 41
def draw_point(point, content)
    # @logger.debug("draw_point #{point} #{content.inspect}")
    
    content_s = content
    foreground_color = nil
    background_color = nil
    if content.is_a?(ViewContent)
        # @logger.debug("draw_point #{point} content is ViewContent")
        
        content_s = content.char
        
        # @logger.debug("draw_point #{point} #{content.foreground_color} #{content.background_color}")
        
        foreground_color = CursesColor::COLORS[content.foreground_color]
        background_color = CursesColor::COLORS[content.background_color]
    end
    
    c_attr = Curses::A_NORMAL
    
    if !foreground_color.nil? && !background_color.nil?
        Curses.init_pair(1, foreground_color, background_color)
        c_attr = Curses.color_pair(1)
    end
    
    # @logger.debug("draw_point #{point} '#{content_s}' #{foreground_color.inspect} #{background_color.inspect}")
    
    begin
        Curses.setpos(point.y, point.x)
        Curses.attron(c_attr) do
            Curses.addstr(content_s)
        end
    rescue Exception => e
        @logger.error("draw_point: #{e}")
    end
    
    # @logger.debug("draw_point #{point} #{content.inspect} DONE")
end
run_cycle() click to toggle source

See UIApp run_cycle() method.

Calls superclass method
# File lib/termkit/app/app_curses.rb, line 31
def run_cycle
    super()
    
    #puts 'CursesApp->run_cycle'
    
    handle_user_input
end
ui_max_x() click to toggle source

See UIApp ui_max_x() method.

# File lib/termkit/app/app_curses.rb, line 87
def ui_max_x
    Curses.cols
end
ui_max_y() click to toggle source

See UIApp ui_max_y() method.

# File lib/termkit/app/app_curses.rb, line 93
def ui_max_y
    Curses.rows
end
ui_refresh() click to toggle source

See UIApp ui_refresh() method.

# File lib/termkit/app/app_curses.rb, line 81
def ui_refresh
    Curses.refresh
end

Protected Instance Methods

ui_close() click to toggle source

See UIApp ui_close() method.

# File lib/termkit/app/app_curses.rb, line 131
def ui_close
    #puts "CursesApp->ui_close"
    
    raise 'ui already closed' if @ui_closed
    @ui_closed = true
    
    # Curses.setpos(10, 0)
    # Curses.addstr('CLOSE   ')
    # Curses.refresh
    # sleep(2)
    
    Curses.refresh
    Curses.stdscr.clear
    Curses.stdscr.refresh
    Curses.stdscr.close
    Curses.close_screen
end
ui_init() click to toggle source

See UIApp ui_init() method.

Calls superclass method
# File lib/termkit/app/app_curses.rb, line 101
def ui_init
    #puts "CursesApp->ui_init '#{@curses_timeout}'"
    
    raise 'ui already initialized' if @ui_inited
    @ui_inited = true
    
    super()
    
    # @logger.debug("init Curses")
    
    Curses.noecho
    Curses.timeout = @curses_timeout
    Curses.curs_set(0)
    Curses.init_screen
    Curses.start_color
    Curses.use_default_colors
    Curses.crmode
    Curses.stdscr.keypad(true)
    
    # @logger.debug("color_pairs: #{Curses.color_pairs}")
    
    # Curses.init_pair(1, Curses::COLOR_BLACK, Curses::COLOR_GREEN)
    
    # Curses.setpos(0, 0)
    # Curses.addstr('INIT OK')
    # Curses.refresh
end