Archived
1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
cli-old/lib/screen.rb

96 lines
1.7 KiB
Ruby
Raw Normal View History

2017-07-24 08:48:22 -04:00
# frozen_string_literal: true
2017-07-27 19:56:17 -04:00
require 'curses/react'
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'
require 'widgets/sidebar'
2017-07-24 08:48:22 -04:00
require 'widgets/logo'
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
def draw
window.draw
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