on master help sign in
ui: prompt: Render aliases + border on the doc
commitc7b326be047a42f6a58146b0de049d48568e397f authorBlaž Hrastnik <blaz@mxxn.io> dateSun 20 Feb 2022, 14:55 (5 years ago) parent2af0432
2 files changed+19−11
helix-term/src/commands.rs+5−2 helix-term/src/ui/prompt.rs+14−9
helix-term/src/commands.rs+5−2
@@ -3384,8 +3384,11 @@ fn command_mode(cx: &mut Context) {
33843384 prompt.doc_fn = Box::new(|input: &str| {
33853385 let part = input.split(' ').next().unwrap_or_default();
33863386
3387− if let Some(cmd::TypableCommand { doc, .. }) = cmd::TYPABLE_COMMAND_MAP.get(part) {
3388− return Some(doc);
3387+ if let Some(cmd::TypableCommand { doc, aliases, .. }) = cmd::TYPABLE_COMMAND_MAP.get(part) {
3388+ if aliases.is_empty() {
3389+ return Some((*doc).into());
3390+ }
3391+ return Some(format!("{}\nAliases: {}", doc, aliases.join(", ")).into());
33893392 }
33903393
33913394 None
helix-term/src/ui/prompt.rs+14−9
@@ -5,6 +5,7 @@ use helix_view::input::KeyEvent;
55use helix_view::keyboard::{KeyCode, KeyModifiers};
66use std::{borrow::Cow, ops::RangeFrom};
77use tui::buffer::Buffer as Surface;
8+use tui::widgets::{Block, Borders, Widget};
89
910use helix_core::{
1011 unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position,
@@ -26,7 +27,7 @@ pub struct Prompt {
2627 history_pos: Option<usize>,
2728 completion_fn: Box<dyn FnMut(&Editor, &str) -> Vec<Completion>>,
2829 callback_fn: Box<dyn FnMut(&mut Context, &str, PromptEvent)>,
29− pub doc_fn: Box<dyn Fn(&str) -> Option<&'static str>>,
30+ pub doc_fn: Box<dyn Fn(&str) -> Option<Cow<str>>>,
3031}
3132
3233#[derive(Clone, Copy, PartialEq)]
@@ -406,14 +407,18 @@ impl Prompt {
406407 let background = theme.get("ui.help");
407408 surface.clear_with(area, background);
408409
409− text.render(
410− area.inner(&Margin {
411− vertical: padding,
412− horizontal: padding,
413− }),
414− surface,
415− cx,
416− );
410+ let block = Block::default()
411+ // .title(self.title.as_str())
412+ .borders(Borders::ALL)
413+ .border_style(background);
414+
415+ let inner = block.inner(area).inner(&Margin {
416+ vertical: 0,
417+ horizontal: 1,
418+ });
419+
420+ block.render(area, surface);
421+ text.render(inner, surface, cx);
417422 }
418423
419424 let line = area.height - 1;