Archived
1
0
Fork 0

Add method React::Curses.render

This commit is contained in:
Braiden Vasco 2017-07-31 02:48:49 +00:00
parent 5b4ed276b2
commit 332d13aec0
3 changed files with 14 additions and 12 deletions

View file

@ -4,5 +4,8 @@ require 'react/curses/nodes'
module React
class Curses
def self.render(element)
Nodes.klass_for(element).new(nil, element).draw
end
end
end

View file

@ -25,7 +25,7 @@ require 'widgets/chat/history'
require 'widgets/chat/new_message'
class Screen
attr_reader :window
attr_writer :props
def initialize
Curses.init_screen
@ -34,20 +34,22 @@ class Screen
Curses.curs_set 0 # invisible cursor
Curses.timeout = 0 # non-blocking input
Curses.stdscr.keypad = true
@window ||= Widgets::Main.new nil
end
def close
Curses.close_screen
end
def props=(value)
window.props = value
def draw
React::Curses.render render
end
def draw
window.draw
def render
React::Element.create :window, x: 0, y: 0, width: Curses.stdscr.maxx, height: Curses.stdscr.maxy do
React::Element.create :wrapper do
React::Element.create Widgets::Main, @props
end
end
end
def poll
@ -56,7 +58,8 @@ class Screen
break if ch.nil?
event = create_event ch
next if event.nil?
window.trigger event
elem = render
React::Curses::Nodes.klass_for(elem).new(nil, elem).children[0].children[0].instance.trigger event
end
end

View file

@ -13,10 +13,6 @@ module Widgets
end
end
def draw
node.draw
end
def node
elem = render
React::Curses::Nodes.klass_for(elem).new nil, elem