Commit 52c909ed5e

52c909ed5e1b534b56bbc53a0357c6e1e92b649e

parent: d1bdb378c1

Unregistered key

vaw <git@nlih.de> · 2026-09-04 01:15 UTC
committer: <noreply@github.com>

Accessibility: Specify position of invisible/custom cursor (#614)

Layout: unified · split

src/main.rs +3
@@ -353,6 +353,9 @@ impl Application {
353 f.set_cursor_position((cx, cy)); 353 f.set_cursor_position((cx, cy));
354 } 354 }
355 })?; 355 })?;
356 if sstate.hide_term_cursor() {
357 term.hide_cursor()?;
358 }
356 359
357 Ok(()) 360 Ok(())
358 } 361 }
src/message/mod.rs +13 −10
@@ -258,17 +258,17 @@ impl MessageTimeStamp {
258 dt1.date_naive() == dt2.date_naive() 258 dt1.date_naive() == dt2.date_naive()
259 } 259 }
260 260
261 fn show_date(self) -> Option<Span<'static>> { 261 fn show_date(self) -> Span<'static> {
262 let time = self.as_datetime().format("%A, %B %d %Y").to_string(); 262 let time = self.as_datetime().format("%A, %B %d %Y").to_string();
263 263
264 Span::styled(time, BOLD_STYLE).into() 264 Span::styled(time, BOLD_STYLE)
265 } 265 }
266 266
267 fn show_time(self) -> Option<Span<'static>> { 267 fn show_time(self) -> Span<'static> {
268 let time = self.as_datetime().format("%T"); 268 let time = self.as_datetime().format("%T");
269 let time = format!(" [{time}]"); 269 let time = format!(" [{time}]");
270 270
271 Span::raw(time).into() 271 Span::raw(time)
272 } 272 }
273} 273}
274 274
@@ -1048,6 +1048,12 @@ impl Message {
1048 return style; 1048 return style;
1049 } 1049 }
1050 1050
1051 pub fn show_date(&self, prev: Option<&Message>) -> bool {
1052 let Some(prev) = prev else { return true };
1053
1054 !prev.timestamp.same_day(self.timestamp)
1055 }
1056
1051 fn get_render_format<'a>( 1057 fn get_render_format<'a>(
1052 &'a self, 1058 &'a self,
1053 prev: Option<&Message>, 1059 prev: Option<&Message>,
@@ -1056,10 +1062,7 @@ impl Message {
1056 settings: &'a ApplicationSettings, 1062 settings: &'a ApplicationSettings,
1057 ) -> MessageFormatter<'a> { 1063 ) -> MessageFormatter<'a> {
1058 let orig = width; 1064 let orig = width;
1059 let date = match &prev { 1065 let date = self.show_date(prev).then(|| self.timestamp.show_date());
1060 Some(prev) if prev.timestamp.same_day(self.timestamp) => None,
1061 _ => self.timestamp.show_date(),
1062 };
1063 let user_gutter = settings.tunables.user_gutter_width; 1066 let user_gutter = settings.tunables.user_gutter_width;
1064 1067
1065 if user_gutter + TIME_GUTTER + READ_GUTTER + MIN_MSG_LEN <= width && 1068 if user_gutter + TIME_GUTTER + READ_GUTTER + MIN_MSG_LEN <= width &&
@@ -1068,7 +1071,7 @@ impl Message {
1068 let cols = MessageColumns::Four; 1071 let cols = MessageColumns::Four;
1069 let fill = width - user_gutter - TIME_GUTTER - READ_GUTTER; 1072 let fill = width - user_gutter - TIME_GUTTER - READ_GUTTER;
1070 let user = self.show_sender(prev, true, info, settings, width); 1073 let user = self.show_sender(prev, true, info, settings, width);
1071 let time = self.timestamp.show_time(); 1074 let time = Some(self.timestamp.show_time());
1072 let read = info 1075 let read = info
1073 .event_receipts 1076 .event_receipts
1074 .values() 1077 .values()
@@ -1082,7 +1085,7 @@ impl Message {
1082 let cols = MessageColumns::Three; 1085 let cols = MessageColumns::Three;
1083 let fill = width - user_gutter - TIME_GUTTER; 1086 let fill = width - user_gutter - TIME_GUTTER;
1084 let user = self.show_sender(prev, true, info, settings, width); 1087 let user = self.show_sender(prev, true, info, settings, width);
1085 let time = self.timestamp.show_time(); 1088 let time = Some(self.timestamp.show_time());
1086 let read = Vec::new(); 1089 let read = Vec::new();
1087 1090
1088 MessageFormatter { settings, cols, orig, fill, user, date, time, read } 1091 MessageFormatter { settings, cols, orig, fill, user, date, time, read }
src/windows/room/scrollback.rs +17 −4
@@ -125,6 +125,9 @@ pub struct ScrollbackState {
125 /// The currently selected message in the scrollback. 125 /// The currently selected message in the scrollback.
126 cursor: MessageCursor, 126 cursor: MessageCursor,
127 127
128 /// The cursor position relative to the terminal viewport.
129 term_cursor: (u16, u16),
130
128 /// Contextual info about the viewport used during rendering. 131 /// Contextual info about the viewport used during rendering.
129 viewctx: ViewportContext<MessageCursor>, 132 viewctx: ViewportContext<MessageCursor>,
130 133
@@ -154,6 +157,7 @@ impl ScrollbackState {
154 viewctx, 157 viewctx,
155 jumped, 158 jumped,
156 show_full_on_redraw, 159 show_full_on_redraw,
160 term_cursor: (0, 0),
157 } 161 }
158 } 162 }
159 163
@@ -607,6 +611,7 @@ impl WindowOps<IambInfo> for ScrollbackState {
607 viewctx: self.viewctx.clone(), 611 viewctx: self.viewctx.clone(),
608 jumped: self.jumped.clone(), 612 jumped: self.jumped.clone(),
609 show_full_on_redraw: false, 613 show_full_on_redraw: false,
614 term_cursor: (0, 0),
610 } 615 }
611 } 616 }
612 617
@@ -1264,7 +1269,7 @@ impl Searchable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
1264 1269
1265impl TerminalCursor for ScrollbackState { 1270impl TerminalCursor for ScrollbackState {
1266 fn get_term_cursor(&self) -> Option<(u16, u16)> { 1271 fn get_term_cursor(&self) -> Option<(u16, u16)> {
1267 None 1272 self.term_cursor.into()
1268 } 1273 }
1269 1274
1270 fn hide_term_cursor(&self) -> bool { 1275 fn hide_term_cursor(&self) -> bool {
@@ -1322,6 +1327,8 @@ impl StatefulWidget for Scrollback<'_> {
1322 type State = ScrollbackState; 1327 type State = ScrollbackState;
1323 1328
1324 fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { 1329 fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
1330 state.term_cursor = (area.left(), area.top());
1331
1325 let info = self.store.application.rooms.get_or_default(state.room_id.clone()); 1332 let info = self.store.application.rooms.get_or_default(state.room_id.clone());
1326 let settings = &self.store.application.settings; 1333 let settings = &self.store.application.settings;
1327 let area = if state.cursor.timestamp.is_some() { 1334 let area = if state.cursor.timestamp.is_some() {
@@ -1412,6 +1419,8 @@ impl StatefulWidget for Scrollback<'_> {
1412 1419
1413 let incomplete_ok = !full || !sel; 1420 let incomplete_ok = !full || !sel;
1414 1421
1422 let includes_date_line = item.show_date(prev);
1423
1415 for (row, line) in txt.lines.into_iter().enumerate() { 1424 for (row, line) in txt.lines.into_iter().enumerate() {
1416 if sawit && lines.len() >= height && incomplete_ok { 1425 if sawit && lines.len() >= height && incomplete_ok {
1417 // Check whether we've seen the first line of the 1426 // Check whether we've seen the first line of the
@@ -1428,7 +1437,7 @@ impl StatefulWidget for Scrollback<'_> {
1428 let line_preview: Vec<_> = 1437 let line_preview: Vec<_> =
1429 msg_previews.extract_if(.., |(_, _, y)| *y as usize == row).collect(); 1438 msg_previews.extract_if(.., |(_, _, y)| *y as usize == row).collect();
1430 1439
1431 lines.push((key, row, line, line_preview)); 1440 lines.push((key, row, line, line_preview, includes_date_line));
1432 sawit |= sel; 1441 sawit |= sel;
1433 } 1442 }
1434 1443
@@ -1440,7 +1449,7 @@ impl StatefulWidget for Scrollback<'_> {
1440 let _ = lines.drain(..n); 1449 let _ = lines.drain(..n);
1441 } 1450 }
1442 1451
1443 if let Some((key, row, _, _)) = lines.first() { 1452 if let Some((key, row, _, _, _)) = lines.first() {
1444 state.viewctx.corner.timestamp = Some((*key).clone()); 1453 state.viewctx.corner.timestamp = Some((*key).clone());
1445 state.viewctx.corner.text_row = *row; 1454 state.viewctx.corner.text_row = *row;
1446 } 1455 }
@@ -1449,12 +1458,16 @@ impl StatefulWidget for Scrollback<'_> {
1449 let x = area.left(); 1458 let x = area.left();
1450 1459
1451 let mut image_previews = vec![]; 1460 let mut image_previews = vec![];
1452 for (_, _, txt, line_preview) in lines.into_iter() { 1461 for (key, row, txt, line_preview, includes_date_line) in lines.into_iter() {
1453 let _ = buf.set_line(x, y, &txt, area.width); 1462 let _ = buf.set_line(x, y, &txt, area.width);
1454 image_previews.extend( 1463 image_previews.extend(
1455 line_preview.into_iter().map(|(backend, msg_x, _)| (x + msg_x, y, backend)), 1464 line_preview.into_iter().map(|(backend, msg_x, _)| (x + msg_x, y, backend)),
1456 ); 1465 );
1457 1466
1467 if key == cursor_key && row == usize::from(includes_date_line) {
1468 state.term_cursor = (x, y);
1469 }
1470
1458 y += 1; 1471 y += 1;
1459 } 1472 }
1460 // Render image previews after all text lines have been drawn, as the render might draw below the current 1473 // Render image previews after all text lines have been drawn, as the render might draw below the current