use crate::prelude::*; #[derive(Clone)] pub struct NotJoinedState { pub(super) room: String, err: Option, } impl NotJoinedState { /// Create a window for a room the user hasn't yet joined. pub fn new(room: String) -> Self { Self { room, err: None } } /// Create a window for a room whose `:join` command failed. pub fn failed(room: String, err: &UIError) -> Self { Self { room, err: Some(err.to_string()) } } } impl Editable for NotJoinedState { fn editor_command( &mut self, _: &EditorAction, _: &ProgramContext, _: &mut ProgramStore, ) -> EditResult { Ok(None) } } impl Jumpable for NotJoinedState { fn jump( &mut self, _: PositionList, _: MoveDir1D, count: usize, _: &ProgramContext, ) -> IambResult { Ok(count) } } impl Scrollable for NotJoinedState { fn scroll( &mut self, _: &ScrollStyle, _: &ProgramContext, _: &mut ProgramStore, ) -> EditResult { Ok(None) } } impl Promptable for NotJoinedState { fn prompt( &mut self, _: &PromptAction, _: &ProgramContext, _: &mut ProgramStore, ) -> EditResult, IambInfo> { Ok(vec![]) } } impl TerminalCursor for NotJoinedState { fn get_term_cursor(&self) -> Option { None } fn hide_term_cursor(&self) -> bool { true } } /// [StatefulWidget] for Matrix rooms that haven't been joined. pub struct NotJoined; impl StatefulWidget for NotJoined { type State = NotJoinedState; fn render(self, area: Rect, buffer: &mut Buffer, state: &mut Self::State) { let mut lines = vec![]; lines.push(Line::from(vec![ Span::raw("Use "), Span::styled(format!("`:join {}`", state.room), StyleModifier::BOLD), Span::raw(" to join this room"), ])); if let Some(err) = &state.err { let style = Style::default().fg(Color::Red); lines.push(Line::from(Span::styled(err.as_str(), style))); } Paragraph::new(Text::from(lines)) .alignment(Alignment::Center) .render(area, buffer); } }