Show unbound bindings as "unbound"

This commit is contained in:
Joscha 2023-04-29 15:07:16 +02:00
parent b6fdc3b7e8
commit dd427b7792

View file

@ -14,6 +14,24 @@ use super::{util, UiError};
type Line = Either2<Text, Join2<Padding<Text>, Text>>; type Line = Either2<Text, Join2<Padding<Text>, Text>>;
type Builder = ListBuilder<'static, Infallible, Line>; type Builder = ListBuilder<'static, Infallible, Line>;
pub fn format_binding(binding: &KeyBinding) -> Styled {
let style = Style::new().cyan();
let mut keys = Styled::default();
for key in binding.keys() {
if !keys.text().is_empty() {
keys = keys.then_plain(", ");
}
keys = keys.then(key.to_string(), style);
}
if keys.text().is_empty() {
keys = keys.then("unbound", style);
}
keys
}
fn render_empty(builder: &mut Builder) { fn render_empty(builder: &mut Builder) {
builder.add_unsel(Text::new("").first2()); builder.add_unsel(Text::new("").first2());
} }
@ -24,15 +42,6 @@ fn render_title(builder: &mut Builder, title: &str) {
} }
fn render_binding(builder: &mut Builder, binding: &KeyBinding, description: &str) { fn render_binding(builder: &mut Builder, binding: &KeyBinding, description: &str) {
let style = Style::new().cyan();
let mut keys = Styled::default();
for key in binding.keys() {
if !keys.text().is_empty() {
keys = keys.then_plain(", ");
}
keys = keys.then(key.to_string(), style);
}
builder.add_unsel( builder.add_unsel(
Join2::horizontal( Join2::horizontal(
Text::new(description) Text::new(description)
@ -41,7 +50,10 @@ fn render_binding(builder: &mut Builder, binding: &KeyBinding, description: &str
.with_right(2) .with_right(2)
.with_stretch(true) .with_stretch(true)
.segment(), .segment(),
Text::new(keys).with_wrap(false).segment().with_fixed(true), Text::new(format_binding(binding))
.with_wrap(false)
.segment()
.with_fixed(true),
) )
.second2(), .second2(),
) )