Add hide cursor when typing option
This commit is contained in:
parent
418df72a07
commit
7bb49fabfa
|
@ -233,6 +233,8 @@ mouse:
|
||||||
selection:
|
selection:
|
||||||
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
|
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
|
||||||
|
|
||||||
|
hide_cursor_when_typing: false
|
||||||
|
|
||||||
# Shell
|
# Shell
|
||||||
#
|
#
|
||||||
# You can set shell.program to the path of your favorite shell, e.g. /bin/fish.
|
# You can set shell.program to the path of your favorite shell, e.g. /bin/fish.
|
||||||
|
|
|
@ -232,6 +232,8 @@ mouse:
|
||||||
selection:
|
selection:
|
||||||
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
|
semantic_escape_chars: ",│`|:\"' ()[]{}<>"
|
||||||
|
|
||||||
|
hide_cursor_when_typing: false
|
||||||
|
|
||||||
# Shell
|
# Shell
|
||||||
#
|
#
|
||||||
# You can set shell.program to the path of your favorite shell, e.g. /bin/fish.
|
# You can set shell.program to the path of your favorite shell, e.g. /bin/fish.
|
||||||
|
|
|
@ -227,6 +227,10 @@ pub struct Config {
|
||||||
/// Visual bell configuration
|
/// Visual bell configuration
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
visual_bell: VisualBellConfig,
|
visual_bell: VisualBellConfig,
|
||||||
|
|
||||||
|
/// Hide cursor when typing
|
||||||
|
#[serde(default)]
|
||||||
|
hide_cursor_when_typing: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os="macos"))]
|
#[cfg(not(target_os="macos"))]
|
||||||
|
@ -273,6 +277,7 @@ impl Default for Config {
|
||||||
config_path: None,
|
config_path: None,
|
||||||
visual_bell: Default::default(),
|
visual_bell: Default::default(),
|
||||||
env: Default::default(),
|
env: Default::default(),
|
||||||
|
hide_cursor_when_typing: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1008,6 +1013,12 @@ impl Config {
|
||||||
&self.env
|
&self.env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Should hide cursor when typing
|
||||||
|
#[inline]
|
||||||
|
pub fn hide_cursor_when_typing(&self) -> bool {
|
||||||
|
self.hide_cursor_when_typing
|
||||||
|
}
|
||||||
|
|
||||||
fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> {
|
fn load_from<P: Into<PathBuf>>(path: P) -> Result<Config> {
|
||||||
let path = path.into();
|
let path = path.into();
|
||||||
let raw = Config::read_file(path.as_path())?;
|
let raw = Config::read_file(path.as_path())?;
|
||||||
|
|
14
src/event.rs
14
src/event.rs
|
@ -142,6 +142,8 @@ pub struct Processor<N> {
|
||||||
ref_test: bool,
|
ref_test: bool,
|
||||||
size_info: SizeInfo,
|
size_info: SizeInfo,
|
||||||
pub selection: Selection,
|
pub selection: Selection,
|
||||||
|
hide_cursor_when_typing: bool,
|
||||||
|
hide_cursor: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Notify that the terminal was resized
|
/// Notify that the terminal was resized
|
||||||
|
@ -178,6 +180,8 @@ impl<N: Notify> Processor<N> {
|
||||||
mouse: Default::default(),
|
mouse: Default::default(),
|
||||||
selection: Default::default(),
|
selection: Default::default(),
|
||||||
size_info: size_info,
|
size_info: size_info,
|
||||||
|
hide_cursor_when_typing: config.hide_cursor_when_typing(),
|
||||||
|
hide_cursor: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +193,7 @@ impl<N: Notify> Processor<N> {
|
||||||
event: glutin::Event,
|
event: glutin::Event,
|
||||||
ref_test: bool,
|
ref_test: bool,
|
||||||
resize_tx: &mpsc::Sender<(u32, u32)>,
|
resize_tx: &mpsc::Sender<(u32, u32)>,
|
||||||
|
hide_cursor: &mut bool,
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
glutin::Event::Closed => {
|
glutin::Event::Closed => {
|
||||||
|
@ -219,9 +224,11 @@ impl<N: Notify> Processor<N> {
|
||||||
processor.ctx.terminal.dirty = true;
|
processor.ctx.terminal.dirty = true;
|
||||||
},
|
},
|
||||||
glutin::Event::KeyboardInput(state, _code, key, mods, string) => {
|
glutin::Event::KeyboardInput(state, _code, key, mods, string) => {
|
||||||
|
*hide_cursor = true;
|
||||||
processor.process_key(state, key, mods, string);
|
processor.process_key(state, key, mods, string);
|
||||||
},
|
},
|
||||||
glutin::Event::MouseInput(state, button) => {
|
glutin::Event::MouseInput(state, button) => {
|
||||||
|
*hide_cursor = false;
|
||||||
processor.mouse_input(state, button);
|
processor.mouse_input(state, button);
|
||||||
processor.ctx.terminal.dirty = true;
|
processor.ctx.terminal.dirty = true;
|
||||||
},
|
},
|
||||||
|
@ -229,6 +236,7 @@ impl<N: Notify> Processor<N> {
|
||||||
let x = limit(x, 0, processor.ctx.size_info.width as i32);
|
let x = limit(x, 0, processor.ctx.size_info.width as i32);
|
||||||
let y = limit(y, 0, processor.ctx.size_info.height as i32);
|
let y = limit(y, 0, processor.ctx.size_info.height as i32);
|
||||||
|
|
||||||
|
*hide_cursor = false;
|
||||||
processor.mouse_moved(x as u32, y as u32);
|
processor.mouse_moved(x as u32, y as u32);
|
||||||
|
|
||||||
if !processor.ctx.selection.is_empty() {
|
if !processor.ctx.selection.is_empty() {
|
||||||
|
@ -236,6 +244,7 @@ impl<N: Notify> Processor<N> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
glutin::Event::MouseWheel(scroll_delta, touch_phase) => {
|
glutin::Event::MouseWheel(scroll_delta, touch_phase) => {
|
||||||
|
*hide_cursor = false;
|
||||||
processor.on_mouse_wheel(scroll_delta, touch_phase);
|
processor.on_mouse_wheel(scroll_delta, touch_phase);
|
||||||
},
|
},
|
||||||
glutin::Event::Focused(true) |
|
glutin::Event::Focused(true) |
|
||||||
|
@ -275,6 +284,7 @@ impl<N: Notify> Processor<N> {
|
||||||
$event,
|
$event,
|
||||||
self.ref_test,
|
self.ref_test,
|
||||||
&self.resize_tx,
|
&self.resize_tx,
|
||||||
|
&mut self.hide_cursor,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -309,6 +319,10 @@ impl<N: Notify> Processor<N> {
|
||||||
for event in window.poll_events() {
|
for event in window.poll_events() {
|
||||||
process!(event);
|
process!(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.hide_cursor_when_typing {
|
||||||
|
window.set_cursor_visible(!self.hide_cursor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.wait_for_event = !terminal.dirty;
|
self.wait_for_event = !terminal.dirty;
|
||||||
|
|
|
@ -288,6 +288,13 @@ impl Window {
|
||||||
pub fn set_title(&self, title: &str) {
|
pub fn set_title(&self, title: &str) {
|
||||||
self.glutin_window.set_title(title);
|
self.glutin_window.set_title(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set cursor visible
|
||||||
|
#[inline]
|
||||||
|
pub fn set_cursor_visible(&self, show: bool) {
|
||||||
|
self.glutin_window.set_cursor(if show { glutin::MouseCursor::Default }
|
||||||
|
else { glutin::MouseCursor::NoneCursor });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Proxy {
|
impl Proxy {
|
||||||
|
|
Loading…
Reference in New Issue