Use actual key binding for empty room list hint

This commit is contained in:
Joscha 2023-04-29 15:41:25 +02:00
parent 1b831f1b29
commit 01c2934fd5

View file

@ -18,7 +18,7 @@ use crate::vault::Vault;
use super::euph::room::EuphRoom; use super::euph::room::EuphRoom;
use super::widgets::{ListBuilder, ListState, Popup}; use super::widgets::{ListBuilder, ListState, Popup};
use super::{util, UiError, UiEvent}; use super::{key_bindings, util, UiError, UiEvent};
enum State { enum State {
ShowList, ShowList,
@ -170,10 +170,12 @@ impl Rooms {
} }
match &mut self.state { match &mut self.state {
State::ShowList => Self::rooms_widget(&mut self.list, &self.euph_rooms, self.order) State::ShowList => {
.await Self::rooms_widget(self.config, &mut self.list, self.order, &self.euph_rooms)
.desync() .await
.boxed_async(), .desync()
.boxed_async()
}
State::ShowRoom(name) => { State::ShowRoom(name) => {
self.euph_rooms self.euph_rooms
@ -184,7 +186,7 @@ impl Rooms {
} }
State::Connect(editor) => { State::Connect(editor) => {
Self::rooms_widget(&mut self.list, &self.euph_rooms, self.order) Self::rooms_widget(self.config, &mut self.list, self.order, &self.euph_rooms)
.await .await
.below(Self::new_room_widget(editor)) .below(Self::new_room_widget(editor))
.desync() .desync()
@ -192,7 +194,7 @@ impl Rooms {
} }
State::Delete(name, editor) => { State::Delete(name, editor) => {
Self::rooms_widget(&mut self.list, &self.euph_rooms, self.order) Self::rooms_widget(self.config, &mut self.list, self.order, &self.euph_rooms)
.await .await
.below(Self::delete_room_widget(name, editor)) .below(Self::delete_room_widget(name, editor))
.desync() .desync()
@ -351,16 +353,18 @@ impl Rooms {
} }
async fn render_rows( async fn render_rows(
config: &Config,
list_builder: &mut ListBuilder<'_, String, Text>, list_builder: &mut ListBuilder<'_, String, Text>,
euph_rooms: &HashMap<String, EuphRoom>,
order: Order, order: Order,
euph_rooms: &HashMap<String, EuphRoom>,
) { ) {
if euph_rooms.is_empty() { if euph_rooms.is_empty() {
// TODO Use configured key binding let style = Style::new().grey().italic();
list_builder.add_unsel(Text::new(( list_builder.add_unsel(Text::new(
"Press F1 for key bindings", Styled::new("Press ", style)
Style::new().grey().italic(), .and_then(key_bindings::format_binding(&config.keys.general.help))
))) .then(" for key bindings", style),
));
} }
let mut rooms = vec![]; let mut rooms = vec![];
@ -388,16 +392,17 @@ impl Rooms {
} }
async fn rooms_widget<'a>( async fn rooms_widget<'a>(
config: &Config,
list: &'a mut ListState<String>, list: &'a mut ListState<String>,
euph_rooms: &HashMap<String, EuphRoom>,
order: Order, order: Order,
euph_rooms: &HashMap<String, EuphRoom>,
) -> impl Widget<UiError> + 'a { ) -> impl Widget<UiError> + 'a {
let heading_style = Style::new().bold(); let heading_style = Style::new().bold();
let heading_text = let heading_text =
Styled::new("Rooms", heading_style).then_plain(format!(" ({})", euph_rooms.len())); Styled::new("Rooms", heading_style).then_plain(format!(" ({})", euph_rooms.len()));
let mut list_builder = ListBuilder::new(); let mut list_builder = ListBuilder::new();
Self::render_rows(&mut list_builder, euph_rooms, order).await; Self::render_rows(config, &mut list_builder, order, euph_rooms).await;
Join2::vertical( Join2::vertical(
Text::new(heading_text).segment().with_fixed(true), Text::new(heading_text).segment().with_fixed(true),