aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-29 07:47:02 +0000
committerBlaž Hrastnik2021-03-29 07:47:02 +0000
commit8098e9bdcd85890d86b45be4e889604f651d7f8c (patch)
tree7d690829b7e0e3d8220b1d9120923263bc919b27
parent742b3a709fd7680d77bcda5ae08f2a9539b6a20e (diff)
Allow setting a status message.
-rw-r--r--helix-term/src/commands.rs12
-rw-r--r--helix-term/src/ui/editor.rs13
2 files changed, 24 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index d2aa481a..fa7a4162 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -35,6 +35,7 @@ pub struct Context<'a> {
pub callback: Option<crate::compositor::Callback>,
pub on_next_key_callback: Option<Box<dyn FnOnce(&mut Context, KeyEvent)>>,
pub callbacks: &'a mut LspCallbacks,
+ pub status_msg: Option<String>,
}
use futures_util::FutureExt;
@@ -87,6 +88,11 @@ impl<'a> Context<'a> {
});
self.callbacks.push(callback);
}
+
+ // TODO: allow &'static str?
+ pub fn set_status(&mut self, msg: String) {
+ self.status_msg = Some(msg);
+ }
}
/// 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) {
pub fn yank(cx: &mut Context) {
// TODO: should selections be made end inclusive?
let doc = cx.doc();
- let values = doc
+ let values: Vec<String> = doc
.selection()
.fragments(doc.text().slice(..))
.map(|cow| cow.into_owned())
@@ -1386,7 +1392,11 @@ pub fn yank(cx: &mut Context) {
// TODO: allow specifying reg
let reg = '"';
+ let msg = format!("yanked {} selection(s) to register {}", values.len(), reg);
+
register::set(reg, values);
+
+ cx.set_status(msg)
}
pub fn paste(cx: &mut Context) {
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index bd0398a2..b02bd981 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -26,6 +26,7 @@ use tui::{
pub struct EditorView {
keymap: Keymaps,
on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
+ status_msg: Option<String>,
}
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
@@ -35,6 +36,7 @@ impl EditorView {
Self {
keymap: keymap::default(),
on_next_key: None,
+ status_msg: None,
}
}
@@ -68,6 +70,12 @@ impl EditorView {
1,
);
self.render_statusline(&doc, area, surface, theme, is_focused);
+
+ // render status
+ if let Some(status_msg) = &self.status_msg {
+ let style = Style::default().fg(Color::Rgb(164, 160, 232)); // lavender
+ surface.set_string(viewport.x, viewport.y + viewport.height, status_msg, style);
+ }
}
pub fn render_buffer(
@@ -441,8 +449,12 @@ impl Component for EditorView {
callback: None,
callbacks: cx.callbacks,
on_next_key_callback: None,
+ status_msg: None,
};
+ // clear status
+ self.status_msg = None;
+
if let Some(on_next_key) = self.on_next_key.take() {
// if there's a command waiting input, do that first
on_next_key(&mut cxt, event);
@@ -486,6 +498,7 @@ impl Component for EditorView {
}
self.on_next_key = cxt.on_next_key_callback.take();
+ self.status_msg = cxt.status_msg.take();
// appease borrowck
let callback = cxt.callback.take();