Commit d6aca862ec

d6aca862ec82ace70e7ba9b7e1a966595f2edf01

parent: 02a7fa695b

Unregistered key

Alxy Savin <saleksey67@gmail.com> · 2026-07-26 22:20 UTC
committer: <noreply@github.com>

Add configurable cursor shape via `settings.terminal.cursor_shape` (#587)

Co-authored-by: Ulyssa <git@ulyssa.dev>

Layout: unified · split

config.example.toml +1
@@ -34,6 +34,7 @@ rooms = ["favorite", "lowpriority", "unread", "name"]
34members = ["power", "id"] 34members = ["power", "id"]
35 35
36[settings.terminal] 36[settings.terminal]
37cursor_shape = "default"
37enable_extended_keys = false 38enable_extended_keys = false
38enable_title = true 39enable_title = true
39 40
docs/iamb.5 +9
@@ -438,6 +438,15 @@ interacts with your terminal.
438.Pp 438.Pp
439The available fields in this subsection are: 439The available fields in this subsection are:
440.Bl -tag -width Ds 440.Bl -tag -width Ds
441.It Sy cursor_shape
442Control the terminal cursor shape used by iamb.
443Possible values are:
444.Dq Sy default ,
445.Dq Sy block ,
446.Dq Sy line , and
447.Dq Sy underline .
448Defaults to
449.Dq Sy default .
441.It Sy enable_extended_keys 450.It Sy enable_extended_keys
442Defines whether to explicitly enable or disable requesting extended keypresses from your terminal. 451Defines whether to explicitly enable or disable requesting extended keypresses from your terminal.
443By default, when unset, 452By default, when unset,
src/config.rs +36
@@ -655,6 +655,7 @@ impl SortOverrides {
655 655
656#[derive(Clone, Debug, Default, Deserialize)] 656#[derive(Clone, Debug, Default, Deserialize)]
657pub struct Terminal { 657pub struct Terminal {
658 pub cursor_shape: Option<CursorShape>,
658 pub enable_extended_keys: Option<bool>, 659 pub enable_extended_keys: Option<bool>,
659 pub enable_title: Option<bool>, 660 pub enable_title: Option<bool>,
660} 661}
@@ -662,6 +663,7 @@ pub struct Terminal {
662impl Terminal { 663impl Terminal {
663 fn merge(profile: Self, global: Self) -> Self { 664 fn merge(profile: Self, global: Self) -> Self {
664 Self { 665 Self {
666 cursor_shape: profile.cursor_shape.or(global.cursor_shape),
665 enable_extended_keys: profile.enable_extended_keys.or(global.enable_extended_keys), 667 enable_extended_keys: profile.enable_extended_keys.or(global.enable_extended_keys),
666 enable_title: profile.enable_title.or(global.enable_title), 668 enable_title: profile.enable_title.or(global.enable_title),
667 } 669 }
@@ -669,6 +671,7 @@ impl Terminal {
669 671
670 pub fn values(self) -> TerminalValues { 672 pub fn values(self) -> TerminalValues {
671 TerminalValues { 673 TerminalValues {
674 cursor_shape: self.cursor_shape.unwrap_or_default(),
672 enable_extended_keys: self.enable_extended_keys, 675 enable_extended_keys: self.enable_extended_keys,
673 enable_title: self.enable_title.unwrap_or(DEFAULT_ENABLE_TITLE), 676 enable_title: self.enable_title.unwrap_or(DEFAULT_ENABLE_TITLE),
674 } 677 }
@@ -677,6 +680,7 @@ impl Terminal {
677 680
678#[derive(Clone, Debug)] 681#[derive(Clone, Debug)]
679pub struct TerminalValues { 682pub struct TerminalValues {
683 pub cursor_shape: CursorShape,
680 pub enable_extended_keys: Option<bool>, 684 pub enable_extended_keys: Option<bool>,
681 pub enable_title: bool, 685 pub enable_title: bool,
682} 686}
@@ -830,6 +834,28 @@ impl Tunables {
830 } 834 }
831} 835}
832 836
837#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, PartialEq)]
838#[serde(rename_all = "kebab-case")]
839#[repr(u8)]
840pub enum CursorShape {
841 #[default]
842 Default,
843 Block,
844 Line,
845 Underline,
846}
847
848impl From<CursorShape> for modalkit::crossterm::cursor::SetCursorStyle {
849 fn from(shape: CursorShape) -> Self {
850 match shape {
851 CursorShape::Default => Self::DefaultUserShape,
852 CursorShape::Block => Self::SteadyBlock,
853 CursorShape::Line => Self::SteadyBar,
854 CursorShape::Underline => Self::SteadyUnderScore,
855 }
856 }
857}
858
833#[derive(Clone)] 859#[derive(Clone)]
834pub struct DirectoryValues { 860pub struct DirectoryValues {
835 pub cache: PathBuf, 861 pub cache: PathBuf,
@@ -1499,6 +1525,16 @@ mod tests {
1499 assert!(serde_json::from_str::<NotifyVia>(r#""""#).is_err()); 1525 assert!(serde_json::from_str::<NotifyVia>(r#""""#).is_err());
1500 } 1526 }
1501 1527
1528 #[test]
1529 fn test_parse_cursor_shape() {
1530 assert_eq!(CursorShape::Default, CursorShape::default());
1531 assert_eq!(CursorShape::Default, serde_json::from_str(r#""default""#).unwrap());
1532 assert_eq!(CursorShape::Block, serde_json::from_str(r#""block""#).unwrap());
1533 assert_eq!(CursorShape::Line, serde_json::from_str(r#""line""#).unwrap());
1534 assert_eq!(CursorShape::Underline, serde_json::from_str(r#""underline""#).unwrap());
1535 assert!(serde_json::from_str::<CursorShape>(r#""beam""#).is_err());
1536 }
1537
1502 #[test] 1538 #[test]
1503 fn test_load_example_config_toml() { 1539 fn test_load_example_config_toml() {
1504 let path = PathBuf::from("config.example.toml"); 1540 let path = PathBuf::from("config.example.toml");
src/main.rs +5 −2
@@ -41,7 +41,7 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber};
41 41
42use modalkit::crossterm::{ 42use modalkit::crossterm::{
43 self, 43 self,
44 cursor::Show as CursorShow, 44 cursor::{SetCursorStyle, Show as CursorShow},
45 event::{ 45 event::{
46 poll, 46 poll,
47 read, 47 read,
@@ -1006,7 +1006,9 @@ fn setup_tty(settings: &ApplicationSettings, enable_enhanced_keys: bool) -> std:
1006 crossterm::execute!(stdout(), SetTitle(title))?; 1006 crossterm::execute!(stdout(), SetTitle(title))?;
1007 } 1007 }
1008 1008
1009 crossterm::execute!(stdout(), EnableBracketedPaste, EnableFocusChange) 1009 let cursor_shape = SetCursorStyle::from(settings.tunables.terminal.cursor_shape);
1010
1011 crossterm::execute!(stdout(), EnableBracketedPaste, EnableFocusChange, cursor_shape)
1010} 1012}
1011 1013
1012// Do our best to reverse what we did in setup_tty() when we exit or crash. 1014// Do our best to reverse what we did in setup_tty() when we exit or crash.
@@ -1023,6 +1025,7 @@ fn restore_tty(enable_enhanced_keys: bool, enable_mouse: bool) {
1023 stdout(), 1025 stdout(),
1024 DisableBracketedPaste, 1026 DisableBracketedPaste,
1025 DisableFocusChange, 1027 DisableFocusChange,
1028 SetCursorStyle::DefaultUserShape,
1026 LeaveAlternateScreen, 1029 LeaveAlternateScreen,
1027 CursorShow, 1030 CursorShow,
1028 ); 1031 );