Migrate nick popup to AsyncWidget
This commit is contained in:
parent
c7cbd9856b
commit
e358e2184e
2 changed files with 17 additions and 23 deletions
|
|
@ -1,26 +1,22 @@
|
||||||
use euphoxide::conn::Joined;
|
use euphoxide::conn::Joined;
|
||||||
use toss::{Style, Terminal};
|
use toss::widgets::{BoxedAsync, EditorState};
|
||||||
|
use toss::{Style, Terminal, WidgetExt};
|
||||||
|
|
||||||
use crate::euph::{self, Room};
|
use crate::euph::{self, Room};
|
||||||
use crate::ui::input::{key, InputEvent, KeyBindingsList};
|
use crate::ui::input::{key, InputEvent, KeyBindingsList};
|
||||||
use crate::ui::util;
|
use crate::ui::widgets2::Popup;
|
||||||
use crate::ui::widgets::editor::EditorState;
|
use crate::ui::{util2, UiError};
|
||||||
use crate::ui::widgets::padding::Padding;
|
|
||||||
use crate::ui::widgets::popup::Popup;
|
|
||||||
use crate::ui::widgets::BoxedWidget;
|
|
||||||
|
|
||||||
pub fn new(joined: Joined) -> EditorState {
|
pub fn new(joined: Joined) -> EditorState {
|
||||||
EditorState::with_initial_text(joined.session.name)
|
EditorState::with_initial_text(joined.session.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn widget(editor: &EditorState) -> BoxedWidget {
|
pub fn widget(editor: &mut EditorState) -> BoxedAsync<'_, UiError> {
|
||||||
let editor = editor
|
let inner = editor
|
||||||
.widget()
|
.widget()
|
||||||
.highlight(|s| euph::style_nick_exact(s, Style::new()));
|
.with_highlight(|s| euph::style_nick_exact(s, Style::new()));
|
||||||
Popup::new(Padding::new(editor).left(1))
|
|
||||||
.title("Choose nick")
|
Popup::new(inner, "Choose nick").boxed_async()
|
||||||
.inner_padding(false)
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nick_char(c: char) -> bool {
|
fn nick_char(c: char) -> bool {
|
||||||
|
|
@ -30,7 +26,7 @@ fn nick_char(c: char) -> bool {
|
||||||
pub fn list_key_bindings(bindings: &mut KeyBindingsList) {
|
pub fn list_key_bindings(bindings: &mut KeyBindingsList) {
|
||||||
bindings.binding("esc", "abort");
|
bindings.binding("esc", "abort");
|
||||||
bindings.binding("enter", "set nick");
|
bindings.binding("enter", "set nick");
|
||||||
util::list_editor_key_bindings(bindings, nick_char);
|
util2::list_editor_key_bindings(bindings, nick_char);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum EventResult {
|
pub enum EventResult {
|
||||||
|
|
@ -43,18 +39,18 @@ pub fn handle_input_event(
|
||||||
terminal: &mut Terminal,
|
terminal: &mut Terminal,
|
||||||
event: &InputEvent,
|
event: &InputEvent,
|
||||||
room: &Option<Room>,
|
room: &Option<Room>,
|
||||||
editor: &EditorState,
|
editor: &mut EditorState,
|
||||||
) -> EventResult {
|
) -> EventResult {
|
||||||
match event {
|
match event {
|
||||||
key!(Esc) => EventResult::ResetState,
|
key!(Esc) => EventResult::ResetState,
|
||||||
key!(Enter) => {
|
key!(Enter) => {
|
||||||
if let Some(room) = &room {
|
if let Some(room) = &room {
|
||||||
let _ = room.nick(editor.text());
|
let _ = room.nick(editor.text().to_string());
|
||||||
}
|
}
|
||||||
EventResult::ResetState
|
EventResult::ResetState
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if util::handle_editor_input_event(editor, terminal, event, nick_char) {
|
if util2::handle_editor_input_event(editor, terminal, event, nick_char) {
|
||||||
EventResult::Handled
|
EventResult::Handled
|
||||||
} else {
|
} else {
|
||||||
EventResult::NotHandled
|
EventResult::NotHandled
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use euphoxide::conn::{self, Joined, Joining, SessionInfo};
|
||||||
use parking_lot::FairMutex;
|
use parking_lot::FairMutex;
|
||||||
use tokio::sync::oneshot::error::TryRecvError;
|
use tokio::sync::oneshot::error::TryRecvError;
|
||||||
use tokio::sync::{mpsc, oneshot};
|
use tokio::sync::{mpsc, oneshot};
|
||||||
use toss::widgets::{BoxedAsync, Join2, Layer, Text};
|
use toss::widgets::{BoxedAsync, EditorState, Join2, Layer, Text};
|
||||||
use toss::{AsyncWidget, Style, Styled, Terminal, WidgetExt};
|
use toss::{AsyncWidget, Style, Styled, Terminal, WidgetExt};
|
||||||
|
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
|
@ -37,7 +37,7 @@ enum Focus {
|
||||||
enum State {
|
enum State {
|
||||||
Normal,
|
Normal,
|
||||||
Auth(OldEditorState),
|
Auth(OldEditorState),
|
||||||
Nick(OldEditorState),
|
Nick(EditorState),
|
||||||
Account(AccountUiState),
|
Account(AccountUiState),
|
||||||
Links(LinksState),
|
Links(LinksState),
|
||||||
InspectMessage(Message),
|
InspectMessage(Message),
|
||||||
|
|
@ -223,14 +223,12 @@ impl EuphRoom {
|
||||||
|
|
||||||
let mut layers = vec![chat];
|
let mut layers = vec![chat];
|
||||||
|
|
||||||
match &self.state {
|
match &mut self.state {
|
||||||
State::Normal => {}
|
State::Normal => {}
|
||||||
State::Auth(editor) => {
|
State::Auth(editor) => {
|
||||||
layers.push(WidgetWrapper::new(auth::widget(editor)).boxed_async())
|
layers.push(WidgetWrapper::new(auth::widget(editor)).boxed_async())
|
||||||
}
|
}
|
||||||
State::Nick(editor) => {
|
State::Nick(editor) => layers.push(nick::widget(editor)),
|
||||||
layers.push(WidgetWrapper::new(nick::widget(editor)).boxed_async())
|
|
||||||
}
|
|
||||||
State::Account(account) => {
|
State::Account(account) => {
|
||||||
layers.push(WidgetWrapper::new(account.widget()).boxed_async())
|
layers.push(WidgetWrapper::new(account.widget()).boxed_async())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue