mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Add cursor style option (#928)
The default cursor can now be configured through the cursor_style field of the config. Valid options include Block, Underline, and Beam. The default can be restored by sending \e[0q as in VTE terminals. Live config reloading is supported for this parameter.
This commit is contained in:
parent
d552d28418
commit
9bdac6b50a
5 changed files with 51 additions and 10 deletions
|
@ -201,6 +201,14 @@ selection:
|
|||
|
||||
hide_cursor_when_typing: false
|
||||
|
||||
# Style of the cursor
|
||||
#
|
||||
# Values for 'cursor_style':
|
||||
# - Block
|
||||
# - Underline
|
||||
# - Beam
|
||||
cursor_style: Block
|
||||
|
||||
# Live config reload (changes require restart)
|
||||
live_config_reload: true
|
||||
|
||||
|
|
|
@ -182,6 +182,14 @@ selection:
|
|||
|
||||
hide_cursor_when_typing: false
|
||||
|
||||
# Style of the cursor
|
||||
#
|
||||
# Values for 'cursor_style':
|
||||
# - Block
|
||||
# - Underline
|
||||
# - Beam
|
||||
cursor_style: Block
|
||||
|
||||
# Live config reload (changes require restart)
|
||||
live_config_reload: true
|
||||
|
||||
|
|
17
src/ansi.rs
17
src/ansi.rs
|
@ -179,7 +179,7 @@ pub trait Handler {
|
|||
fn set_title(&mut self, &str) {}
|
||||
|
||||
/// Set the cursor style
|
||||
fn set_cursor_style(&mut self, _: CursorStyle) {}
|
||||
fn set_cursor_style(&mut self, _: Option<CursorStyle>) {}
|
||||
|
||||
/// A character to be displayed
|
||||
fn input(&mut self, _c: char) {}
|
||||
|
@ -344,7 +344,7 @@ pub trait Handler {
|
|||
}
|
||||
|
||||
/// Describes shape of cursor
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize)]
|
||||
pub enum CursorStyle {
|
||||
/// Cursor is a block like `▒`
|
||||
Block,
|
||||
|
@ -356,6 +356,12 @@ pub enum CursorStyle {
|
|||
Beam,
|
||||
}
|
||||
|
||||
impl Default for CursorStyle {
|
||||
fn default() -> CursorStyle {
|
||||
CursorStyle::Block
|
||||
}
|
||||
}
|
||||
|
||||
/// Terminal modes
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum Mode {
|
||||
|
@ -1070,9 +1076,10 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
|
|||
'u' => handler.restore_cursor_position(),
|
||||
'q' => {
|
||||
let style = match arg_or_default!(idx: 0, default: 0) {
|
||||
0 ... 2 => CursorStyle::Block,
|
||||
3 | 4 => CursorStyle::Underline,
|
||||
5 | 6 => CursorStyle::Beam,
|
||||
0 => None,
|
||||
1 | 2 => Some(CursorStyle::Block),
|
||||
3 | 4 => Some(CursorStyle::Underline),
|
||||
5 | 6 => Some(CursorStyle::Beam),
|
||||
_ => unhandled!()
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ use glutin::ModifiersState;
|
|||
|
||||
use input::{Action, Binding, MouseBinding, KeyBinding};
|
||||
use index::{Line, Column};
|
||||
use ansi::CursorStyle;
|
||||
|
||||
use util::fmt::Yellow;
|
||||
|
||||
|
@ -275,6 +276,10 @@ pub struct Config {
|
|||
#[serde(default)]
|
||||
hide_cursor_when_typing: bool,
|
||||
|
||||
/// Style of the cursor
|
||||
#[serde(default)]
|
||||
cursor_style: CursorStyle,
|
||||
|
||||
/// Live config reload
|
||||
#[serde(default="true_bool")]
|
||||
live_config_reload: bool,
|
||||
|
@ -329,6 +334,7 @@ impl Default for Config {
|
|||
visual_bell: Default::default(),
|
||||
env: Default::default(),
|
||||
hide_cursor_when_typing: Default::default(),
|
||||
cursor_style: Default::default(),
|
||||
live_config_reload: true,
|
||||
padding: default_padding(),
|
||||
}
|
||||
|
@ -1179,6 +1185,12 @@ impl Config {
|
|||
self.hide_cursor_when_typing
|
||||
}
|
||||
|
||||
/// Style of the cursor
|
||||
#[inline]
|
||||
pub fn cursor_style(&self) -> CursorStyle {
|
||||
self.cursor_style
|
||||
}
|
||||
|
||||
/// Live config reload
|
||||
#[inline]
|
||||
pub fn live_config_reload(&self) -> bool {
|
||||
|
|
|
@ -708,7 +708,11 @@ pub struct Term {
|
|||
/// Original colors from config
|
||||
original_colors: color::List,
|
||||
|
||||
cursor_style: CursorStyle,
|
||||
/// Current style of the cursor
|
||||
cursor_style: Option<CursorStyle>,
|
||||
|
||||
/// Default style for resetting the cursor
|
||||
default_cursor_style: CursorStyle,
|
||||
}
|
||||
|
||||
/// Terminal size info
|
||||
|
@ -810,7 +814,8 @@ impl Term {
|
|||
color_modified: [false; color::COUNT],
|
||||
original_colors: color::List::from(config.colors()),
|
||||
semantic_escape_chars: config.selection().semantic_escape_chars.clone(),
|
||||
cursor_style: CursorStyle::Block,
|
||||
cursor_style: None,
|
||||
default_cursor_style: config.cursor_style(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -835,6 +840,7 @@ impl Term {
|
|||
}
|
||||
}
|
||||
self.visual_bell.update_config(config);
|
||||
self.default_cursor_style = config.cursor_style();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1003,7 +1009,7 @@ impl Term {
|
|||
self.mode,
|
||||
config,
|
||||
selection,
|
||||
self.cursor_style,
|
||||
self.cursor_style.unwrap_or(self.default_cursor_style),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1869,7 +1875,7 @@ impl ansi::Handler for Term {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn set_cursor_style(&mut self, style: CursorStyle) {
|
||||
fn set_cursor_style(&mut self, style: Option<CursorStyle>) {
|
||||
trace!("set_cursor_style {:?}", style);
|
||||
self.cursor_style = style;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue