From c7b326be047a42f6a58146b0de049d48568e397f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Sun, 20 Feb 2022 14:55:16 +0900 Subject: [PATCH] ui: prompt: Render aliases + border on the doc --- helix-term/src/commands.rs | 7 +++++-- helix-term/src/ui/prompt.rs | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7e8b1d53e..982ae0135 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3384,8 +3384,11 @@ fn command_mode(cx: &mut Context) { prompt.doc_fn = Box::new(|input: &str| { let part = input.split(' ').next().unwrap_or_default(); - if let Some(cmd::TypableCommand { doc, .. }) = cmd::TYPABLE_COMMAND_MAP.get(part) { - return Some(doc); + if let Some(cmd::TypableCommand { doc, aliases, .. }) = cmd::TYPABLE_COMMAND_MAP.get(part) { + if aliases.is_empty() { + return Some((*doc).into()); + } + return Some(format!("{}\nAliases: {}", doc, aliases.join(", ")).into()); } None diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index 7088d6dfe..cd8e14eea 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -5,6 +5,7 @@ use helix_view::input::KeyEvent; use helix_view::keyboard::{KeyCode, KeyModifiers}; use std::{borrow::Cow, ops::RangeFrom}; use tui::buffer::Buffer as Surface; +use tui::widgets::{Block, Borders, Widget}; use helix_core::{ unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position, @@ -26,7 +27,7 @@ pub struct Prompt { history_pos: Option, completion_fn: Box Vec>, callback_fn: Box, - pub doc_fn: Box Option<&'static str>>, + pub doc_fn: Box Option>>, } #[derive(Clone, Copy, PartialEq)] @@ -406,14 +407,18 @@ impl Prompt { let background = theme.get("ui.help"); surface.clear_with(area, background); - text.render( - area.inner(&Margin { - vertical: padding, - horizontal: padding, - }), - surface, - cx, - ); + let block = Block::default() + // .title(self.title.as_str()) + .borders(Borders::ALL) + .border_style(background); + + let inner = block.inner(area).inner(&Margin { + vertical: 0, + horizontal: 1, + }); + + block.render(area, surface); + text.render(inner, surface, cx); } let line = area.height - 1;