ui: prompt: Render aliases + border on the doc

pull/1618/head
Blaž Hrastnik 3 years ago
parent 2af04325d8
commit c7b326be04
No known key found for this signature in database
GPG Key ID: 1238B9C4AD889640

@ -3384,8 +3384,11 @@ fn command_mode(cx: &mut Context) {
prompt.doc_fn = Box::new(|input: &str| { prompt.doc_fn = Box::new(|input: &str| {
let part = input.split(' ').next().unwrap_or_default(); let part = input.split(' ').next().unwrap_or_default();
if let Some(cmd::TypableCommand { doc, .. }) = cmd::TYPABLE_COMMAND_MAP.get(part) { if let Some(cmd::TypableCommand { doc, aliases, .. }) = cmd::TYPABLE_COMMAND_MAP.get(part) {
return Some(doc); if aliases.is_empty() {
return Some((*doc).into());
}
return Some(format!("{}\nAliases: {}", doc, aliases.join(", ")).into());
} }
None None

@ -5,6 +5,7 @@ use helix_view::input::KeyEvent;
use helix_view::keyboard::{KeyCode, KeyModifiers}; use helix_view::keyboard::{KeyCode, KeyModifiers};
use std::{borrow::Cow, ops::RangeFrom}; use std::{borrow::Cow, ops::RangeFrom};
use tui::buffer::Buffer as Surface; use tui::buffer::Buffer as Surface;
use tui::widgets::{Block, Borders, Widget};
use helix_core::{ use helix_core::{
unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position, unicode::segmentation::GraphemeCursor, unicode::width::UnicodeWidthStr, Position,
@ -26,7 +27,7 @@ pub struct Prompt {
history_pos: Option<usize>, history_pos: Option<usize>,
completion_fn: Box<dyn FnMut(&Editor, &str) -> Vec<Completion>>, completion_fn: Box<dyn FnMut(&Editor, &str) -> Vec<Completion>>,
callback_fn: Box<dyn FnMut(&mut Context, &str, PromptEvent)>, callback_fn: Box<dyn FnMut(&mut Context, &str, PromptEvent)>,
pub doc_fn: Box<dyn Fn(&str) -> Option<&'static str>>, pub doc_fn: Box<dyn Fn(&str) -> Option<Cow<str>>>,
} }
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq)]
@ -406,14 +407,18 @@ impl Prompt {
let background = theme.get("ui.help"); let background = theme.get("ui.help");
surface.clear_with(area, background); surface.clear_with(area, background);
text.render( let block = Block::default()
area.inner(&Margin { // .title(self.title.as_str())
vertical: padding, .borders(Borders::ALL)
horizontal: padding, .border_style(background);
}),
surface, let inner = block.inner(area).inner(&Margin {
cx, vertical: 0,
); horizontal: 1,
});
block.render(area, surface);
text.render(inner, surface, cx);
} }
let line = area.height - 1; let line = area.height - 1;

Loading…
Cancel
Save