on master help sign in
Allow setting a status message.
8098e9bBlaž Hrastnik
helix-term/src/commands.rs+11−1
@@ -35,6 +35,7 @@ pub struct Context<'a> {
35 pub callback: Option<crate::compositor::Callback>,
35 pub callback: Option<crate::compositor::Callback>,
36 pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
36 pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
37 pub callbacks: &'a mut LspCallbacks,
37 pub callbacks: &'a mut LspCallbacks,
38+ pub status_msg: Option<String>,
38}
39}
39
40
40use futures_util::FutureExt;
41use futures_util::FutureExt;
@@ -87,6 +88,11 @@ impl<'a> Context<'a> {
87 });
88 });
88 self.callbacks.push(callback);
89 self.callbacks.push(callback);
89 }
90 }
91+
92+ // TODO: allow &'static str?
93+ pub fn set_status(&mut self, msg: String) {
94+ self.status_msg = Some(msg);
95+ }
90}
96}
91
97
92/// A command is a function that takes the current state and a count, and does a side-effect on the
98/// 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) {
1378pub fn yank(cx: &mut Context) {
1384pub fn yank(cx: &mut Context) {
1379 // TODO: should selections be made end inclusive?
1385 // TODO: should selections be made end inclusive?
1380 let doc = cx.doc();
1386 let doc = cx.doc();
1381− let values = doc
1387+ let values: Vec<String> = doc
1382 .selection()
1388 .selection()
1383 .fragments(doc.text().slice(..))
1389 .fragments(doc.text().slice(..))
1384 .map(|cow| cow.into_owned())
1390 .map(|cow| cow.into_owned())
@@ -1386,7 +1392,11 @@ pub fn yank(cx: &mut Context) {
1386
1392
1387 // TODO: allow specifying reg
1393 // TODO: allow specifying reg
1388 let reg = '"';
1394 let reg = '"';
1395+ let msg = format!("yanked {} selection(s) to register {}", values.len(), reg);
1396+
1389 register::set(reg, values);
1397 register::set(reg, values);
1398+
1399+ cx.set_status(msg)
1390}
1400}
1391
1401
1392pub fn paste(cx: &mut Context) {
1402pub fn paste(cx: &mut Context) {
helix-term/src/ui/editor.rs+13
@@ -26,6 +26,7 @@ use tui::{
26pub struct EditorView {
26pub struct EditorView {
27 keymap: Keymaps,
27 keymap: Keymaps,
28 on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
28 on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
29+ status_msg: Option<String>,
29}
30}
30
31
31const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
32const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
@@ -35,6 +36,7 @@ impl EditorView {
35 Self {
36 Self {
36 keymap: keymap::default(),
37 keymap: keymap::default(),
37 on_next_key: None,
38 on_next_key: None,
39+ status_msg: None,
38 }
40 }
39 }
41 }
40
42
@@ -68,6 +70,12 @@ impl EditorView {
68 1,
70 1,
69 );
71 );
70 self.render_statusline(&doc, area, surface, theme, is_focused);
72 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+ }
71 }
79 }
72
80
73 pub fn render_buffer(
81 pub fn render_buffer(
@@ -441,8 +449,12 @@ impl Component for EditorView {
441 callback: None,
449 callback: None,
442 callbacks: cx.callbacks,
450 callbacks: cx.callbacks,
443 on_next_key_callback: None,
451 on_next_key_callback: None,
452+ status_msg: None,
444 };
453 };
445
454
455+ // clear status
456+ self.status_msg = None;
457+
446 if let Some(on_next_key) = self.on_next_key.take() {
458 if let Some(on_next_key) = self.on_next_key.take() {
447 // if there's a command waiting input, do that first
459 // if there's a command waiting input, do that first
448 on_next_key(&mut cxt, event);
460 on_next_key(&mut cxt, event);
@@ -486,6 +498,7 @@ impl Component for EditorView {
486 }
498 }
487
499
488 self.on_next_key = cxt.on_next_key_callback.take();
500 self.on_next_key = cxt.on_next_key_callback.take();
501+ self.status_msg = cxt.status_msg.take();
489
502
490 // appease borrowck
503 // appease borrowck
491 let callback = cxt.callback.take();
504 let callback = cxt.callback.take();