Handle new message putc
This commit is contained in:
parent
7e01c6febd
commit
29e9f0e351
4 changed files with 37 additions and 4 deletions
18
lib/main.rb
18
lib/main.rb
|
@ -69,6 +69,8 @@ private
|
||||||
on_menu_up: method(:on_menu_up),
|
on_menu_up: method(:on_menu_up),
|
||||||
on_menu_down: method(:on_menu_down),
|
on_menu_down: method(:on_menu_down),
|
||||||
|
|
||||||
|
on_new_message_putc: method(:on_new_message_putc),
|
||||||
|
|
||||||
sidebar: {
|
sidebar: {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
@ -175,7 +177,7 @@ private
|
||||||
|
|
||||||
def on_window_right
|
def on_window_right
|
||||||
@state = state.merge(
|
@state = state.merge(
|
||||||
focus: :sidebar,
|
focus: :chat,
|
||||||
|
|
||||||
sidebar: state[:sidebar].merge(
|
sidebar: state[:sidebar].merge(
|
||||||
focused: true,
|
focused: true,
|
||||||
|
@ -245,4 +247,18 @@ private
|
||||||
).freeze,
|
).freeze,
|
||||||
).freeze
|
).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def on_new_message_putc(char)
|
||||||
|
text = state[:chat][:new_message][:text]
|
||||||
|
cursor_pos = state[:chat][:new_message][:cursor_pos]
|
||||||
|
|
||||||
|
@state = state.merge(
|
||||||
|
chat: state[:chat].merge(
|
||||||
|
new_message: state[:chat][:new_message].merge(
|
||||||
|
text: "#{text[0...cursor_pos]}#{char}#{text[cursor_pos..-1]}",
|
||||||
|
cursor_pos: cursor_pos + 1,
|
||||||
|
).freeze,
|
||||||
|
).freeze,
|
||||||
|
).freeze
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,9 +12,17 @@ module Widgets
|
||||||
|
|
||||||
def props=(_value)
|
def props=(_value)
|
||||||
super
|
super
|
||||||
|
|
||||||
@info.props = props[:info]
|
@info.props = props[:info]
|
||||||
@history.props = props[:history]
|
@history.props = props[:history]
|
||||||
@message.props = props[:new_message]
|
|
||||||
|
@message.props = props[:new_message].merge(
|
||||||
|
on_putc: props[:on_new_message_putc],
|
||||||
|
).freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def trigger(event)
|
||||||
|
focus&.trigger event
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -17,7 +17,9 @@ module Widgets
|
||||||
on_menu_down: props[:on_menu_down],
|
on_menu_down: props[:on_menu_down],
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
@chat.props = props[:chat]
|
@chat.props = props[:chat].merge(
|
||||||
|
on_new_message_putc: props[:on_new_message_putc],
|
||||||
|
).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def trigger(event)
|
def trigger(event)
|
||||||
|
@ -27,7 +29,7 @@ module Widgets
|
||||||
when Events::Window::Right
|
when Events::Window::Right
|
||||||
props[:on_window_right].call
|
props[:on_window_right].call
|
||||||
else
|
else
|
||||||
focus.trigger event
|
focus&.trigger event
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
|
|
||||||
module Widgets
|
module Widgets
|
||||||
class Text < Base
|
class Text < Base
|
||||||
|
def trigger(event)
|
||||||
|
case event
|
||||||
|
when Events::Text::Putc
|
||||||
|
props[:on_putc].call event.char
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
|
|
Reference in a new issue