Commit 4f44e7b02d

4f44e7b02d5d163b284e07f60d8d24289699a2f0

parent: 556bf55c79

Unregistered key

Ulyssa <git@ulyssa.dev> · 2026-09-25 01:08 UTC
committer: <noreply@github.com>

Use `Buffer::set_style` in widgets to get consistent backgrounds (#742)

Layout: unified · split

Cargo.lock +4 −4
@@ -3793,9 +3793,9 @@ dependencies = [
3793 3793
3794[[package]] 3794[[package]]
3795name = "modalkit" 3795name = "modalkit"
3796version = "0.0.28" 3796version = "0.0.29"
3797source = "registry+https://github.com/rust-lang/crates.io-index" 3797source = "registry+https://github.com/rust-lang/crates.io-index"
3798checksum = "b8a62517886d7f5d7b476ac8458805073df47941d99861de81347861f4d03d3e" 3798checksum = "74f52c73943f474277b3151ed970ca26457547d62fafe92d0f2806344ed9a733"
3799dependencies = [ 3799dependencies = [
3800 "anymap2", 3800 "anymap2",
3801 "arboard", 3801 "arboard",
@@ -3817,9 +3817,9 @@ dependencies = [
3817 3817
3818[[package]] 3818[[package]]
3819name = "modalkit-ratatui" 3819name = "modalkit-ratatui"
3820version = "0.0.28" 3820version = "0.0.29"
3821source = "registry+https://github.com/rust-lang/crates.io-index" 3821source = "registry+https://github.com/rust-lang/crates.io-index"
3822checksum = "2fd45bce81ff69f3cb2126b0d59aafe74c3982a2f8be68f49dc14f3c7c180629" 3822checksum = "09874ea261c8c7859483de20f71b9e9e3c71b71f31d1b07d30a207ea633441c6"
3823dependencies = [ 3823dependencies = [
3824 "crossterm 0.29.0", 3824 "crossterm 0.29.0",
3825 "intervaltree", 3825 "intervaltree",
Cargo.toml +4 −4
@@ -81,15 +81,15 @@ version = "4.12"
81optional = true 81optional = true
82 82
83[dependencies.modalkit] 83[dependencies.modalkit]
84version = "0.0.28" 84version = "0.0.29"
85default-features = false 85default-features = false
86#git = "https://github.com/ulyssa/modalkit" 86#git = "https://github.com/ulyssa/modalkit"
87#rev = "9386f6f75f6984a1cdbd7dddbb0c0bb3e7a37c5d" 87#rev = "bdb1c365417234f0c3be297beeffcfe2d1e75a5a"
88 88
89[dependencies.modalkit-ratatui] 89[dependencies.modalkit-ratatui]
90version = "0.0.28" 90version = "0.0.29"
91#git = "https://github.com/ulyssa/modalkit" 91#git = "https://github.com/ulyssa/modalkit"
92#rev = "9386f6f75f6984a1cdbd7dddbb0c0bb3e7a37c5d" 92#rev = "bdb1c365417234f0c3be297beeffcfe2d1e75a5a"
93 93
94[dependencies.matrix-sdk-base] 94[dependencies.matrix-sdk-base]
95version = "0.19.0" 95version = "0.19.0"
docs/iamb.5 +6
@@ -721,6 +721,12 @@ For controlling how the text in the command bar is styled.
721.Bl -tag -width Ds 721.Bl -tag -width Ds
722.It Sy default 722.It Sy default
723Configure the default styling for the command bar. 723Configure the default styling for the command bar.
724.It Sy prompt
725Configure the styling for the prompt in the command bar.
726.It Sy error
727Configure the styling for error messages shown in the command bar.
728.It Sy info
729Configure the styling for info messages shown in the command bar.
724.El 730.El
725.It Sy encryption 731.It Sy encryption
726For controlling how the encryption indicators are styled. 732For controlling how the encryption indicators are styled.
src/config/theme.rs +22 −2
@@ -493,22 +493,42 @@ pub struct ThemeMessageBarValues {
493struct ThemeCommandBar { 493struct ThemeCommandBar {
494 #[serde(default)] 494 #[serde(default)]
495 default: Stylable, 495 default: Stylable,
496
497 #[serde(default)]
498 prompt: Stylable,
499
500 #[serde(default)]
501 info: Stylable,
502
503 #[serde(default)]
504 error: Stylable,
496} 505}
497 506
498impl ThemeCommandBar { 507impl ThemeCommandBar {
499 fn merge(self, other: Self) -> Self { 508 fn merge(self, other: Self) -> Self {
500 Self { default: self.default.merge(other.default) } 509 Self {
510 default: self.default.merge(other.default),
511 prompt: self.prompt.merge(other.prompt),
512 info: self.info.merge(other.info),
513 error: self.error.merge(other.error),
514 }
501 } 515 }
502 516
503 fn values(self, base: Style) -> ThemeCommandBarValues { 517 fn values(self, base: Style) -> ThemeCommandBarValues {
504 let default = base.patch(self.default); 518 let default = base.patch(self.default);
505 ThemeCommandBarValues { default } 519 let prompt = default.patch(self.prompt);
520 let info = default.patch(self.info);
521 let error = default.patch(self.error);
522 ThemeCommandBarValues { default, prompt, info, error }
506 } 523 }
507} 524}
508 525
509#[derive(Clone, Debug, Default)] 526#[derive(Clone, Debug, Default)]
510pub struct ThemeCommandBarValues { 527pub struct ThemeCommandBarValues {
511 pub default: Style, 528 pub default: Style,
529 pub prompt: Style,
530 pub info: Style,
531 pub error: Style,
512} 532}
513 533
514#[derive(Clone, Debug, Default, Deserialize)] 534#[derive(Clone, Debug, Default, Deserialize)]
src/main.rs +15 −4
@@ -257,6 +257,9 @@ struct Application {
257 /// State for the Matrix client, editing, etc. 257 /// State for the Matrix client, editing, etc.
258 store: AsyncProgramStore, 258 store: AsyncProgramStore,
259 259
260 /// Clone of the currently selected theme.
261 theme: Arc<ThemeValues>,
262
260 /// UI state (open tabs, command bar, etc.) to use when rendering. 263 /// UI state (open tabs, command bar, etc.) to use when rendering.
261 screen: ScreenState<IambWindow, IambInfo>, 264 screen: ScreenState<IambWindow, IambInfo>,
262 265
@@ -287,6 +290,7 @@ impl Application {
287 ) -> IambResult<Application> { 290 ) -> IambResult<Application> {
288 let backend = CrosstermBackend::new(stdout()); 291 let backend = CrosstermBackend::new(stdout());
289 let terminal = Terminal::new(backend)?; 292 let terminal = Terminal::new(backend)?;
293 let theme = settings.theme.clone();
290 294
291 let mut bindings = crate::keybindings::setup_keybindings(&settings.tunables); 295 let mut bindings = crate::keybindings::setup_keybindings(&settings.tunables);
292 settings.setup(&mut bindings); 296 settings.setup(&mut bindings);
@@ -305,6 +309,7 @@ impl Application {
305 store, 309 store,
306 worker, 310 worker,
307 terminal, 311 terminal,
312 theme,
308 bindings, 313 bindings,
309 actstack, 314 actstack,
310 screen, 315 screen,
@@ -427,7 +432,8 @@ impl Application {
427 self.handle_info(info); 432 self.handle_info(info);
428 }, 433 },
429 Err(e) => { 434 Err(e) => {
430 self.screen.push_error(e); 435 drop(store);
436 self.handle_error(e);
431 }, 437 },
432 } 438 }
433 }, 439 },
@@ -457,7 +463,8 @@ impl Application {
457 self.handle_info(info); 463 self.handle_info(info);
458 }, 464 },
459 Err(e) => { 465 Err(e) => {
460 self.screen.push_error(e); 466 drop(store);
467 self.handle_error(e);
461 }, 468 },
462 } 469 }
463 }, 470 },
@@ -829,7 +836,7 @@ impl Application {
829 fn handle_info(&mut self, info: InfoMessage) { 836 fn handle_info(&mut self, info: InfoMessage) {
830 match info { 837 match info {
831 InfoMessage::Message(info) => { 838 InfoMessage::Message(info) => {
832 self.screen.push_info(info); 839 self.screen.push_message(info, self.theme.cmdbar.info);
833 }, 840 },
834 InfoMessage::Pager(text) => { 841 InfoMessage::Pager(text) => {
835 let pager = Box::new(Pager::new(text, vec![])); 842 let pager = Box::new(Pager::new(text, vec![]));
@@ -838,6 +845,10 @@ impl Application {
838 } 845 }
839 } 846 }
840 847
848 fn handle_error(&mut self, err: impl ToString) {
849 self.screen.push_message(err, self.theme.cmdbar.error);
850 }
851
841 pub async fn run(&mut self) -> Result<(), std::io::Error> { 852 pub async fn run(&mut self) -> Result<(), std::io::Error> {
842 self.terminal.clear()?; 853 self.terminal.clear()?;
843 854
@@ -871,7 +882,7 @@ impl Application {
871 continue; 882 continue;
872 }, 883 },
873 Err(e) => { 884 Err(e) => {
874 self.screen.push_error(e); 885 self.handle_error(e);
875 886
876 // Skip processing any more keypress Actions until the next key. 887 // Skip processing any more keypress Actions until the next key.
877 keyskip = true; 888 keyskip = true;
src/windows/mod.rs +13
@@ -481,6 +481,9 @@ impl WindowOps<IambInfo> for IambWindow {
481 .. 481 ..
482 } = &mut store.application; 482 } = &mut store.application;
483 483
484 let default_list_style = settings.theme.default;
485 let default_rooms_style = settings.theme.rooms.default;
486
484 match self { 487 match self {
485 IambWindow::Room(state) => state.draw(area, buf, focused, store), 488 IambWindow::Room(state) => state.draw(area, buf, focused, store),
486 IambWindow::DirectList(state) => { 489 IambWindow::DirectList(state) => {
@@ -499,6 +502,7 @@ impl WindowOps<IambInfo> for IambWindow {
499 .empty_message("No direct messages yet!") 502 .empty_message("No direct messages yet!")
500 .empty_alignment(Alignment::Center) 503 .empty_alignment(Alignment::Center)
501 .focus(focused) 504 .focus(focused)
505 .style(default_rooms_style)
502 .render(area, buf, state); 506 .render(area, buf, state);
503 }, 507 },
504 IambWindow::MemberList(state, room_id, last_fetch) => { 508 IambWindow::MemberList(state, room_id, last_fetch) => {
@@ -524,6 +528,7 @@ impl WindowOps<IambInfo> for IambWindow {
524 .empty_message("No users here yet!") 528 .empty_message("No users here yet!")
525 .empty_alignment(Alignment::Center) 529 .empty_alignment(Alignment::Center)
526 .focus(focused) 530 .focus(focused)
531 .style(default_list_style)
527 .render(area, buf, state); 532 .render(area, buf, state);
528 }, 533 },
529 IambWindow::PinnedList(state, room_id, last_fetch) => { 534 IambWindow::PinnedList(state, room_id, last_fetch) => {
@@ -551,6 +556,7 @@ impl WindowOps<IambInfo> for IambWindow {
551 .empty_message("No pinned messages in this room") 556 .empty_message("No pinned messages in this room")
552 .empty_alignment(Alignment::Center) 557 .empty_alignment(Alignment::Center)
553 .focus(focused) 558 .focus(focused)
559 .style(default_list_style)
554 .render(area, buf, state); 560 .render(area, buf, state);
555 }, 561 },
556 IambWindow::RoomList(state) => { 562 IambWindow::RoomList(state) => {
@@ -569,6 +575,7 @@ impl WindowOps<IambInfo> for IambWindow {
569 .empty_message("You haven't joined any rooms yet") 575 .empty_message("You haven't joined any rooms yet")
570 .empty_alignment(Alignment::Center) 576 .empty_alignment(Alignment::Center)
571 .focus(focused) 577 .focus(focused)
578 .style(default_rooms_style)
572 .render(area, buf, state); 579 .render(area, buf, state);
573 }, 580 },
574 IambWindow::ChatList(state) => { 581 IambWindow::ChatList(state) => {
@@ -589,6 +596,7 @@ impl WindowOps<IambInfo> for IambWindow {
589 .empty_message("You do not have rooms or dms yet") 596 .empty_message("You do not have rooms or dms yet")
590 .empty_alignment(Alignment::Center) 597 .empty_alignment(Alignment::Center)
591 .focus(focused) 598 .focus(focused)
599 .style(default_rooms_style)
592 .render(area, buf, state); 600 .render(area, buf, state);
593 }, 601 },
594 IambWindow::UnreadList(state) => { 602 IambWindow::UnreadList(state) => {
@@ -610,6 +618,7 @@ impl WindowOps<IambInfo> for IambWindow {
610 .empty_message("You do not have any unreads yet") 618 .empty_message("You do not have any unreads yet")
611 .empty_alignment(Alignment::Center) 619 .empty_alignment(Alignment::Center)
612 .focus(focused) 620 .focus(focused)
621 .style(default_rooms_style)
613 .render(area, buf, state); 622 .render(area, buf, state);
614 }, 623 },
615 IambWindow::MentionsList(state) => { 624 IambWindow::MentionsList(state) => {
@@ -631,6 +640,7 @@ impl WindowOps<IambInfo> for IambWindow {
631 .empty_message("You do not have any unread mentions yet") 640 .empty_message("You do not have any unread mentions yet")
632 .empty_alignment(Alignment::Center) 641 .empty_alignment(Alignment::Center)
633 .focus(focused) 642 .focus(focused)
643 .style(default_rooms_style)
634 .render(area, buf, state); 644 .render(area, buf, state);
635 }, 645 },
636 IambWindow::InvitesList(state) => { 646 IambWindow::InvitesList(state) => {
@@ -652,6 +662,7 @@ impl WindowOps<IambInfo> for IambWindow {
652 .empty_message("You do not have any open invites") 662 .empty_message("You do not have any open invites")
653 .empty_alignment(Alignment::Center) 663 .empty_alignment(Alignment::Center)
654 .focus(focused) 664 .focus(focused)
665 .style(default_rooms_style)
655 .render(area, buf, state); 666 .render(area, buf, state);
656 }, 667 },
657 IambWindow::SpaceList(state) => { 668 IambWindow::SpaceList(state) => {
@@ -671,6 +682,7 @@ impl WindowOps<IambInfo> for IambWindow {
671 .empty_message("You haven't joined any spaces yet") 682 .empty_message("You haven't joined any spaces yet")
672 .empty_alignment(Alignment::Center) 683 .empty_alignment(Alignment::Center)
673 .focus(focused) 684 .focus(focused)
685 .style(default_rooms_style)
674 .render(area, buf, state); 686 .render(area, buf, state);
675 }, 687 },
676 IambWindow::VerifyList(state) => { 688 IambWindow::VerifyList(state) => {
@@ -693,6 +705,7 @@ impl WindowOps<IambInfo> for IambWindow {
693 .empty_message("No in-progress verifications") 705 .empty_message("No in-progress verifications")
694 .empty_alignment(Alignment::Center) 706 .empty_alignment(Alignment::Center)
695 .focus(focused) 707 .focus(focused)
708 .style(default_list_style)
696 .render(area, buf, state); 709 .render(area, buf, state);
697 }, 710 },
698 IambWindow::Welcome(state) => state.draw(area, buf, focused, store), 711 IambWindow::Welcome(state) => state.draw(area, buf, focused, store),
src/windows/room/chat.rs +2
@@ -1340,8 +1340,10 @@ impl StatefulWidget for Chat<'_> {
1340 tbox.render(textarea, buf, &mut state.tbox); 1340 tbox.render(textarea, buf, &mut state.tbox);
1341 1341
1342 // Render the message scrollback. 1342 // Render the message scrollback.
1343 let scrollback_style = self.store.application.settings.theme.timeline.default;
1343 let scrollback_focused = state.focus.is_scrollback() && self.focused; 1344 let scrollback_focused = state.focus.is_scrollback() && self.focused;
1344 let scrollback = Scrollback::new(self.store) 1345 let scrollback = Scrollback::new(self.store)
1346 .style(scrollback_style)
1345 .focus(scrollback_focused) 1347 .focus(scrollback_focused)
1346 .room_focus(self.focused); 1348 .room_focus(self.focused);
1347 scrollback.render(scrollarea, buf, &mut state.scrollback); 1349 scrollback.render(scrollarea, buf, &mut state.scrollback);
src/windows/room/scrollback.rs +22 −2
@@ -555,7 +555,11 @@ impl ScrollbackState {
555 555
556impl WindowOps<IambInfo> for ScrollbackState { 556impl WindowOps<IambInfo> for ScrollbackState {
557 fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { 557 fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) {
558 Scrollback::new(store).focus(focused).render(area, buf, self) 558 let scrollback_style = store.application.settings.theme.timeline.default;
559 Scrollback::new(store)
560 .style(scrollback_style)
561 .focus(focused)
562 .render(area, buf, self)
559 } 563 }
560 564
561 fn dup(&self, _: &mut ProgramStore) -> Self { 565 fn dup(&self, _: &mut ProgramStore) -> Self {
@@ -1257,13 +1261,25 @@ fn render_jump_to_recent(area: Rect, buf: &mut Buffer, focused: bool) -> Rect {
1257 1261
1258pub struct Scrollback<'a> { 1262pub struct Scrollback<'a> {
1259 room_focused: bool, 1263 room_focused: bool,
1264 style: Style,
1260 focused: bool, 1265 focused: bool,
1261 store: &'a mut ProgramStore, 1266 store: &'a mut ProgramStore,
1262} 1267}
1263 1268
1264impl<'a> Scrollback<'a> { 1269impl<'a> Scrollback<'a> {
1265 pub fn new(store: &'a mut ProgramStore) -> Self { 1270 pub fn new(store: &'a mut ProgramStore) -> Self {
1266 Scrollback { room_focused: false, focused: false, store } 1271 Scrollback {
1272 room_focused: false,
1273 focused: false,
1274 style: Style::default(),
1275 store,
1276 }
1277 }
1278
1279 /// Set the default style for the cells within the room scrollback.
1280 pub fn style(mut self, style: Style) -> Self {
1281 self.style = style;
1282 self
1267 } 1283 }
1268 1284
1269 /// Indicate whether the room window is currently focused, regardless of whether the scrollback 1285 /// Indicate whether the room window is currently focused, regardless of whether the scrollback
@@ -1284,6 +1300,10 @@ impl StatefulWidget for Scrollback<'_> {
1284 type State = ScrollbackState; 1300 type State = ScrollbackState;
1285 1301
1286 fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { 1302 fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) {
1303 // Ensure the whole area gets the style, even where we don't write characters:
1304 buf.set_style(area, self.style);
1305
1306 // Keep track of the upper left corner for setting the cursor location:
1287 state.term_cursor = (area.left(), area.top()); 1307 state.term_cursor = (area.left(), area.top());
1288 1308
1289 let info = self.store.application.rooms.get_or_default(state.room_id.clone()); 1309 let info = self.store.application.rooms.get_or_default(state.room_id.clone());
src/windows/welcome.rs +6 −3
@@ -1,6 +1,6 @@
1//! Welcome Window 1//! Welcome Window
2 2
3use modalkit_ratatui::textbox::TextBoxState; 3use modalkit_ratatui::textbox::{TextBox, TextBoxState};
4 4
5use crate::prelude::*; 5use crate::prelude::*;
6 6
@@ -45,9 +45,12 @@ impl TerminalCursor for WelcomeState {
45} 45}
46 46
47impl WindowOps<IambInfo> for WelcomeState { 47impl WindowOps<IambInfo> for WelcomeState {
48 fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) { 48 fn draw(&mut self, area: Rect, buf: &mut Buffer, _: bool, store: &mut ProgramStore) {
49 self.tbox.set_ignorecase(store.application.settings.tunables.ignorecase); 49 self.tbox.set_ignorecase(store.application.settings.tunables.ignorecase);
50 self.tbox.draw(area, buf, focused, store) 50
51 // Render textbox:
52 let style = store.application.settings.theme.default;
53 TextBox::new().style(style).render(area, buf, &mut self.tbox)
51 } 54 }
52 55
53 fn dup(&self, store: &mut ProgramStore) -> Self { 56 fn dup(&self, store: &mut ProgramStore) -> Self {