on master help sign in
Allow setting a status message.
commit8098e9bdcd85890d86b45be4e889604f651d7f8c authorBlaž Hrastnik <blaz@mxxn.io> dateMon 29 Mar 2021, 16:47 (6 years ago) parent742b3a7
2 files changed+24−1
helix-term/src/commands.rs+11−1 helix-term/src/ui/editor.rs+13
helix-term/src/commands.rs+11−1
@@ -35,6 +35,7 @@ pub struct Context<'a> {
3535 pub callback: Option<crate::compositor::Callback>,
3636 pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
3737 pub callbacks: &'a mut LspCallbacks,
38+ pub status_msg: Option<String>,
3839}
3940
4041use futures_util::FutureExt;
@@ -87,6 +88,11 @@ impl<'a> Context<'a> {
8788 });
8889 self.callbacks.push(callback);
8990 }
91+
92+ // TODO: allow &'static str?
93+ pub fn set_status(&mut self, msg: String) {
94+ self.status_msg = Some(msg);
95+ }
9096}
9197
9298/// A command is a function that takes the current state and a count, and does a side-effect on the
@@ -1378,7 +1384,7 @@ pub fn redo(cx: &mut Context) {
13781384pub fn yank(cx: &mut Context) {
13791385 // TODO: should selections be made end inclusive?
13801386 let doc = cx.doc();
1381− let values = doc
1387+ let values: Vec<String> = doc
13821388 .selection()
13831389 .fragments(doc.text().slice(..))
13841390 .map(|cow| cow.into_owned())
@@ -1386,7 +1392,11 @@ pub fn yank(cx: &mut Context) {
13861392
13871393 // TODO: allow specifying reg
13881394 let reg = '"';
1395+ let msg = format!("yanked {} selection(s) to register {}", values.len(), reg);
1396+
13891397 register::set(reg, values);
1398+
1399+ cx.set_status(msg)
13901400}
13911401
13921402pub fn paste(cx: &mut Context) {
helix-term/src/ui/editor.rs+13
@@ -26,6 +26,7 @@ use tui::{
2626pub struct EditorView {
2727 keymap: Keymaps,
2828 on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
29+ status_msg: Option<String>,
2930}
3031
3132const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
@@ -35,6 +36,7 @@ impl EditorView {
3536 Self {
3637 keymap: keymap::default(),
3738 on_next_key: None,
39+ status_msg: None,
3840 }
3941 }
4042
@@ -68,6 +70,12 @@ impl EditorView {
6870 1,
6971 );
7072 self.render_statusline(&doc, area, surface, theme, is_focused);
73+
74+ // render status
75+ if let Some(status_msg) = &self.status_msg {
76+ let style = Style::default().fg(Color::Rgb(164, 160, 232)); // lavender
77+ surface.set_string(viewport.x, viewport.y + viewport.height, status_msg, style);
78+ }
7179 }
7280
7381 pub fn render_buffer(
@@ -441,8 +449,12 @@ impl Component for EditorView {
441449 callback: None,
442450 callbacks: cx.callbacks,
443451 on_next_key_callback: None,
452+ status_msg: None,
444453 };
445454
455+ // clear status
456+ self.status_msg = None;
457+
446458 if let Some(on_next_key) = self.on_next_key.take() {
447459 // if there's a command waiting input, do that first
448460 on_next_key(&mut cxt, event);
@@ -486,6 +498,7 @@ impl Component for EditorView {
486498 }
487499
488500 self.on_next_key = cxt.on_next_key_callback.take();
501+ self.status_msg = cxt.status_msg.take();
489502
490503 // appease borrowck
491504 let callback = cxt.callback.take();