Archived
1
0
Fork 0

Add class Curses::React::Nodes::TextLine

This commit is contained in:
Braiden Vasco 2017-07-28 11:20:29 +00:00
parent 046d6f9368
commit e0c9bb0b69
5 changed files with 73 additions and 3 deletions

View file

@ -6,6 +6,7 @@ require 'curses'
require 'curses/react/component'
require 'curses/react/element'
require 'curses/react/nodes'
module Curses
module React

View file

@ -48,6 +48,13 @@ module Curses
children.freeze
end
def all_props
@all_props ||= props.merge(
key: key,
children: children,
).freeze
end
private
def children

10
lib/curses/react/nodes.rb Normal file
View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
require 'curses/react/nodes/text_line'
module Curses
module React
module Nodes
end
end
end

View file

@ -0,0 +1,34 @@
# frozen_string_literal: true
module Curses
using Helpers
module React
module Nodes
class TextLine
def initialize(element, window)
@element = element
@window = window
end
def props
@element.all_props
end
def draw
return if props[:text].nil?
setpos props[:x], props[:y]
addstr props[:text].ljustetc props[:width]
end
def setpos(x, y)
@window.setpos y, x
end
def addstr(s)
@window.addstr s
end
end
end
end
end

View file

@ -43,9 +43,27 @@ module Widgets
end
def render_public_key
setpos 0, 1
addstr PUBLIC_KEY_LABEL
addstr props[:public_key].ljustetc props[:width] - PUBLIC_KEY_LABEL.length if props[:public_key]
Curses::React::Nodes::TextLine.new(
Curses::React::Element.create(
:text_line,
x: 0,
y: 1,
width: PUBLIC_KEY_LABEL.length,
text: PUBLIC_KEY_LABEL,
),
window,
).draw
Curses::React::Nodes::TextLine.new(
Curses::React::Element.create(
:text_line,
x: PUBLIC_KEY_LABEL.length,
y: 1,
width: props[:width] - PUBLIC_KEY_LABEL.length,
text: props[:public_key],
),
window,
).draw
end
end
end