Commit 1799941957
17999419570a0d3b4650c05c0bc0d01efcde92f8
parent: 0cd0155f9a
Unregistered key
vaw <git@nlih.de> · 2026-09-12 00:18 UTC
committer: <noreply@github.com>
Add `CursorShape::Auto` (#665)
Layout: unified · split
docs/iamb.5
+11 −1
| @@ -583,11 +583,21 @@ The available fields in this subsection are: |
| 583 | 583 | Control the terminal cursor shape used by iamb. |
| 584 | 584 | Possible values are: |
| 585 | 585 | .Dq Sy default , |
| 586 | .Dq Sy auto , |
| 586 | 587 | .Dq Sy block , |
| 587 | 588 | .Dq Sy line , and |
| 588 | 589 | .Dq Sy underline . |
| 590 | The mode |
| 591 | .Dq Sy auto |
| 592 | switches between |
| 593 | .Dq Sy block |
| 594 | in normal mode, |
| 595 | .Dq Sy line |
| 596 | in insert mode, and |
| 597 | .Dq Sy underline |
| 598 | in replace mode. |
| 589 | 599 | Defaults to |
| 590 | | .Dq Sy default . |
| 600 | .Dq Sy auto . |
| 591 | 601 | .It Sy enable_extended_keys |
| 592 | 602 | Defines whether to explicitly enable or disable requesting extended keypresses from your terminal. |
| 593 | 603 | By default, when unset, |
src/config.rs
+7 −2
| @@ -1009,11 +1009,12 @@ impl Tunables { |
| 1009 | 1009 | #[serde(rename_all = "kebab-case")] |
| 1010 | 1010 | #[repr(u8)] |
| 1011 | 1011 | pub enum CursorShape { |
| 1012 | | #[default] |
| 1013 | 1012 | Default, |
| 1014 | 1013 | Block, |
| 1015 | 1014 | Line, |
| 1016 | 1015 | Underline, |
| 1016 | #[default] |
| 1017 | Auto, |
| 1017 | 1018 | } |
| 1018 | 1019 | |
| 1019 | 1020 | impl From<CursorShape> for modalkit::crossterm::cursor::SetCursorStyle { |
| @@ -1023,6 +1024,9 @@ impl From<CursorShape> for modalkit::crossterm::cursor::SetCursorStyle { |
| 1023 | 1024 | CursorShape::Block => Self::SteadyBlock, |
| 1024 | 1025 | CursorShape::Line => Self::SteadyBar, |
| 1025 | 1026 | CursorShape::Underline => Self::SteadyUnderScore, |
| 1027 | |
| 1028 | // use steady block at startup and switch to the correct value on first render |
| 1029 | CursorShape::Auto => Self::SteadyBlock, |
| 1026 | 1030 | } |
| 1027 | 1031 | } |
| 1028 | 1032 | } |
| @@ -1792,7 +1796,8 @@ mod tests { |
| 1792 | 1796 | |
| 1793 | 1797 | #[test] |
| 1794 | 1798 | fn test_parse_cursor_shape() { |
| 1795 | | assert_eq!(CursorShape::Default, CursorShape::default()); |
| 1799 | assert_eq!(CursorShape::Auto, CursorShape::default()); |
| 1800 | assert_eq!(CursorShape::Auto, serde_json::from_str(r#""auto""#).unwrap()); |
| 1796 | 1801 | assert_eq!(CursorShape::Default, serde_json::from_str(r#""default""#).unwrap()); |
| 1797 | 1802 | assert_eq!(CursorShape::Block, serde_json::from_str(r#""block""#).unwrap()); |
| 1798 | 1803 | assert_eq!(CursorShape::Line, serde_json::from_str(r#""line""#).unwrap()); |
src/main.rs
+10 −1
| @@ -66,7 +66,7 @@ use tracing_subscriber::{EnvFilter, FmtSubscriber}; |
| 66 | 66 | |
| 67 | 67 | use crate::base::{HomeserverAction, KeysAction}; |
| 68 | 68 | use crate::completions::IambCompleter; |
| 69 | | use crate::config::Iamb; |
| 69 | use crate::config::{CursorShape, Iamb}; |
| 70 | 70 | use crate::prelude::*; |
| 71 | 71 | use crate::windows::IambWindow; |
| 72 | 72 | use crate::worker::{ClientWorker, LoginStyle, create_room}; |
| @@ -295,6 +295,15 @@ impl Application { |
| 295 | 295 | let inner = Rect::new(cx, cy, 1, 1); |
| 296 | 296 | f.render_widget(para, inner) |
| 297 | 297 | } |
| 298 | if store.application.settings.tunables.terminal.cursor_shape == CursorShape::Auto { |
| 299 | let shape = match cursor.get_insert_style() { |
| 300 | Some(InsertStyle::Insert) => CursorShape::Line, |
| 301 | Some(InsertStyle::Replace) => CursorShape::Underline, |
| 302 | None => CursorShape::Block, |
| 303 | }; |
| 304 | let _ = crossterm::execute!(stdout(), SetCursorStyle::from(shape)); |
| 305 | } |
| 306 | |
| 298 | 307 | f.set_cursor_position((cx, cy)); |
| 299 | 308 | } |
| 300 | 309 | })?; |