2017-07-24 08:48:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'curses'
|
2017-07-27 19:47:48 -04:00
|
|
|
require 'curses/react/component'
|
2017-07-24 08:48:22 -04:00
|
|
|
|
|
|
|
# Additional classes
|
2017-07-25 11:05:52 -04:00
|
|
|
require 'events'
|
2017-07-24 08:48:22 -04:00
|
|
|
require 'style'
|
|
|
|
|
|
|
|
# Basic
|
|
|
|
require 'widgets/text'
|
|
|
|
|
|
|
|
# Basic containers
|
|
|
|
require 'widgets/container'
|
|
|
|
require 'widgets/v_panel'
|
|
|
|
|
|
|
|
require 'widgets/main'
|
2017-07-24 16:31:23 -04:00
|
|
|
require 'widgets/sidebar'
|
2017-07-24 08:48:22 -04:00
|
|
|
require 'widgets/logo'
|
2017-07-24 16:34:04 -04:00
|
|
|
require 'widgets/menu'
|
2017-07-24 08:48:22 -04:00
|
|
|
|
|
|
|
require 'widgets/chat'
|
|
|
|
require 'widgets/chat/info'
|
|
|
|
require 'widgets/chat/history'
|
|
|
|
require 'widgets/chat/new_message'
|
|
|
|
|
|
|
|
class Screen
|
2017-07-24 16:23:24 -04:00
|
|
|
attr_reader :window
|
|
|
|
|
2017-07-24 08:48:22 -04:00
|
|
|
def initialize
|
|
|
|
Curses.init_screen
|
|
|
|
Curses.start_color
|
|
|
|
Curses.noecho # do no echo input
|
|
|
|
Curses.curs_set 0 # invisible cursor
|
|
|
|
Curses.timeout = 0 # non-blocking input
|
|
|
|
Curses.stdscr.keypad = true
|
|
|
|
|
2017-07-25 10:29:01 -04:00
|
|
|
@window ||= Widgets::Main.new nil
|
2017-07-24 08:48:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def close
|
|
|
|
Curses.close_screen
|
|
|
|
end
|
|
|
|
|
2017-07-24 18:34:50 -04:00
|
|
|
def props=(value)
|
|
|
|
window.props = value
|
|
|
|
end
|
|
|
|
|
2017-07-24 08:48:22 -04:00
|
|
|
def render
|
2017-07-24 16:23:24 -04:00
|
|
|
window.render
|
2017-07-24 08:48:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def poll
|
|
|
|
loop do
|
|
|
|
ch = Curses.getch
|
|
|
|
break if ch.nil?
|
|
|
|
event = create_event ch
|
|
|
|
next if event.nil?
|
2017-07-24 16:23:24 -04:00
|
|
|
window.trigger event
|
2017-07-24 08:48:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-07-25 11:11:32 -04:00
|
|
|
def create_event(char)
|
|
|
|
case char
|
|
|
|
when Curses::Key::SLEFT
|
|
|
|
Events::Window::Left.new
|
|
|
|
when Curses::Key::SRIGHT
|
|
|
|
Events::Window::Right.new
|
|
|
|
|
2017-07-26 04:07:36 -04:00
|
|
|
when "\n".ord
|
|
|
|
Events::Text::Enter.new
|
|
|
|
|
2017-07-25 11:11:32 -04:00
|
|
|
when Curses::Key::LEFT
|
|
|
|
Events::Text::Left.new
|
|
|
|
when Curses::Key::RIGHT
|
|
|
|
Events::Text::Right.new
|
|
|
|
when Curses::Key::UP
|
|
|
|
Events::Text::Up.new
|
|
|
|
when Curses::Key::DOWN
|
|
|
|
Events::Text::Down.new
|
|
|
|
when Curses::Key::HOME
|
|
|
|
Events::Text::Home.new
|
|
|
|
when Curses::Key::END
|
|
|
|
Events::Text::End.new
|
|
|
|
when Curses::Key::BACKSPACE
|
|
|
|
Events::Text::Backspace.new
|
|
|
|
when Curses::Key::DC
|
|
|
|
Events::Text::Delete.new
|
|
|
|
|
|
|
|
when String
|
|
|
|
Events::Text::Putc.new char
|
|
|
|
end
|
|
|
|
end
|
2017-07-24 08:48:22 -04:00
|
|
|
end
|