on master help sign in
idle timer wip
f99bea4Blaž Hrastnik
helix-term/src/application.rs+5
@@ -199,6 +199,11 @@ impl Application {
199 self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
199 self.jobs.handle_callback(&mut self.editor, &mut self.compositor, callback);
200 self.render();
200 self.render();
201 }
201 }
202+ _ = &mut self.editor.idle_timer => {
203+ self.editor.clear_idle_timer();
204+ println!("idle!")
205+ // idle timeout
206+ }
202 }
207 }
203 }
208 }
204 }
209 }
helix-term/src/ui/editor.rs+1
@@ -901,6 +901,7 @@ impl Component for EditorView {
901 EventResult::Consumed(None)
901 EventResult::Consumed(None)
902 }
902 }
903 Event::Key(key) => {
903 Event::Key(key) => {
904+ cxt.editor.reset_idle_timer();
904 let mut key = KeyEvent::from(key);
905 let mut key = KeyEvent::from(key);
905 canonicalize_key(&mut key);
906 canonicalize_key(&mut key);
906 // clear status
907 // clear status
helix-view/src/editor.rs+19−1
@@ -9,10 +9,12 @@ use crate::{
9use futures_util::future;
9use futures_util::future;
10use std::{
10use std::{
11 path::{Path, PathBuf},
11 path::{Path, PathBuf},
12+ pin::Pin,
12 sync::Arc,
13 sync::Arc,
13− time::Duration,
14};
14};
15
15
16+use tokio::time::{sleep, Duration, Instant, Sleep};
17+
16use slotmap::SlotMap;
18use slotmap::SlotMap;
17
19
18use anyhow::Error;
20use anyhow::Error;
@@ -91,6 +93,8 @@ pub struct Editor {
91 pub status_msg: Option<(String, Severity)>,
93 pub status_msg: Option<(String, Severity)>,
92
94
93 pub config: Config,
95 pub config: Config,
96+
97+ pub idle_timer: Pin<Box<Sleep>>,
94}
98}
95
99
96#[derive(Debug, Copy, Clone)]
100#[derive(Debug, Copy, Clone)]
@@ -125,10 +129,24 @@ impl Editor {
125 registers: Registers::default(),
129 registers: Registers::default(),
126 clipboard_provider: get_clipboard_provider(),
130 clipboard_provider: get_clipboard_provider(),
127 status_msg: None,
131 status_msg: None,
132+ idle_timer: Box::pin(sleep(Duration::from_millis(500))),
128 config,
133 config,
129 }
134 }
130 }
135 }
131
136
137+ pub fn clear_idle_timer(&mut self) {
138+ // equivalent to internal Instant::far_future() (30 years)
139+ self.idle_timer
140+ .as_mut()
141+ .reset(Instant::now() + Duration::from_secs(86400 * 365 * 30));
142+ }
143+
144+ pub fn reset_idle_timer(&mut self) {
145+ self.idle_timer
146+ .as_mut()
147+ .reset(Instant::now() + Duration::from_millis(500));
148+ }
149+
132 pub fn clear_status(&mut self) {
150 pub fn clear_status(&mut self) {
133 self.status_msg = None;
151 self.status_msg = None;
134 }
152 }