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"]
3434members = ["power", "id"]
3535
3636[settings.terminal]
37cursor_shape = "default"
3738enable_extended_keys = false
3839enable_title = true
3940
docs/iamb.5 +9
@@ -438,6 +438,15 @@ interacts with your terminal.
438438.Pp
439439The available fields in this subsection are:
440440.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 .
441450.It Sy enable_extended_keys
442451Defines whether to explicitly enable or disable requesting extended keypresses from your terminal.
443452By default, when unset,
src/config.rs +36
@@ -655,6 +655,7 @@ impl SortOverrides {
655655
656656#[derive(Clone, Debug, Default, Deserialize)]
657657pub struct Terminal {
658 pub cursor_shape: Option<CursorShape>,
658659 pub enable_extended_keys: Option<bool>,
659660 pub enable_title: Option<bool>,
660661}
@@ -662,6 +663,7 @@ pub struct Terminal {
662663impl Terminal {
663664 fn merge(profile: Self, global: Self) -> Self {
664665 Self {
666 cursor_shape: profile.cursor_shape.or(global.cursor_shape),
665667 enable_extended_keys: profile.enable_extended_keys.or(global.enable_extended_keys),
666668 enable_title: profile.enable_title.or(global.enable_title),
667669 }
@@ -669,6 +671,7 @@ impl Terminal {
669671
670672 pub fn values(self) -> TerminalValues {
671673 TerminalValues {
674 cursor_shape: self.cursor_shape.unwrap_or_default(),
672675 enable_extended_keys: self.enable_extended_keys,
673676 enable_title: self.enable_title.unwrap_or(DEFAULT_ENABLE_TITLE),
674677 }
@@ -677,6 +680,7 @@ impl Terminal {
677680
678681#[derive(Clone, Debug)]
679682pub struct TerminalValues {
683 pub cursor_shape: CursorShape,
680684 pub enable_extended_keys: Option<bool>,
681685 pub enable_title: bool,
682686}
@@ -830,6 +834,28 @@ impl Tunables {
830834 }
831835}
832836
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
833859#[derive(Clone)]
834860pub struct DirectoryValues {
835861 pub cache: PathBuf,
@@ -1499,6 +1525,16 @@ mod tests {
14991525 assert!(serde_json::from_str::<NotifyVia>(r#""""#).is_err());
15001526 }
15011527
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
15021538 #[test]
15031539 fn test_load_example_config_toml() {
15041540 let path = PathBuf::from("config.example.toml");
src/main.rs +5 −2
@@ -41,7 +41,7 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber};
4141
4242use modalkit::crossterm::{
4343 self,
44 cursor::Show as CursorShow,
44 cursor::{SetCursorStyle, Show as CursorShow},
4545 event::{
4646 poll,
4747 read,
@@ -1006,7 +1006,9 @@ fn setup_tty(settings: &ApplicationSettings, enable_enhanced_keys: bool) -> std:
10061006 crossterm::execute!(stdout(), SetTitle(title))?;
10071007 }
10081008
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)
10101012}
10111013
10121014// 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) {
10231025 stdout(),
10241026 DisableBracketedPaste,
10251027 DisableFocusChange,
1028 SetCursorStyle::DefaultUserShape,
10261029 LeaveAlternateScreen,
10271030 CursorShow,
10281031 );