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 = [
37933793
37943794[[package]]
37953795name = "modalkit"
3796version = "0.0.28"
3796version = "0.0.29"
37973797source = "registry+https://github.com/rust-lang/crates.io-index"
3798checksum = "b8a62517886d7f5d7b476ac8458805073df47941d99861de81347861f4d03d3e"
3798checksum = "74f52c73943f474277b3151ed970ca26457547d62fafe92d0f2806344ed9a733"
37993799dependencies = [
38003800 "anymap2",
38013801 "arboard",
@@ -3817,9 +3817,9 @@ dependencies = [
38173817
38183818[[package]]
38193819name = "modalkit-ratatui"
3820version = "0.0.28"
3820version = "0.0.29"
38213821source = "registry+https://github.com/rust-lang/crates.io-index"
3822checksum = "2fd45bce81ff69f3cb2126b0d59aafe74c3982a2f8be68f49dc14f3c7c180629"
3822checksum = "09874ea261c8c7859483de20f71b9e9e3c71b71f31d1b07d30a207ea633441c6"
38233823dependencies = [
38243824 "crossterm 0.29.0",
38253825 "intervaltree",
Cargo.toml +4 −4
@@ -81,15 +81,15 @@ version = "4.12"
8181optional = true
8282
8383[dependencies.modalkit]
84version = "0.0.28"
84version = "0.0.29"
8585default-features = false
8686#git = "https://github.com/ulyssa/modalkit"
87#rev = "9386f6f75f6984a1cdbd7dddbb0c0bb3e7a37c5d"
87#rev = "bdb1c365417234f0c3be297beeffcfe2d1e75a5a"
8888
8989[dependencies.modalkit-ratatui]
90version = "0.0.28"
90version = "0.0.29"
9191#git = "https://github.com/ulyssa/modalkit"
92#rev = "9386f6f75f6984a1cdbd7dddbb0c0bb3e7a37c5d"
92#rev = "bdb1c365417234f0c3be297beeffcfe2d1e75a5a"
9393
9494[dependencies.matrix-sdk-base]
9595version = "0.19.0"
docs/iamb.5 +6
@@ -721,6 +721,12 @@ For controlling how the text in the command bar is styled.
721721.Bl -tag -width Ds
722722.It Sy default
723723Configure 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.
724730.El
725731.It Sy encryption
726732For controlling how the encryption indicators are styled.
src/config/theme.rs +22 −2
@@ -493,22 +493,42 @@ pub struct ThemeMessageBarValues {
493493struct ThemeCommandBar {
494494 #[serde(default)]
495495 default: Stylable,
496
497 #[serde(default)]
498 prompt: Stylable,
499
500 #[serde(default)]
501 info: Stylable,
502
503 #[serde(default)]
504 error: Stylable,
496505}
497506
498507impl ThemeCommandBar {
499508 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 }
501515 }
502516
503517 fn values(self, base: Style) -> ThemeCommandBarValues {
504518 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 }
506523 }
507524}
508525
509526#[derive(Clone, Debug, Default)]
510527pub struct ThemeCommandBarValues {
511528 pub default: Style,
529 pub prompt: Style,
530 pub info: Style,
531 pub error: Style,
512532}
513533
514534#[derive(Clone, Debug, Default, Deserialize)]
src/main.rs +15 −4
@@ -257,6 +257,9 @@ struct Application {
257257 /// State for the Matrix client, editing, etc.
258258 store: AsyncProgramStore,
259259
260 /// Clone of the currently selected theme.
261 theme: Arc<ThemeValues>,
262
260263 /// UI state (open tabs, command bar, etc.) to use when rendering.
261264 screen: ScreenState<IambWindow, IambInfo>,
262265
@@ -287,6 +290,7 @@ impl Application {
287290 ) -> IambResult<Application> {
288291 let backend = CrosstermBackend::new(stdout());
289292 let terminal = Terminal::new(backend)?;
293 let theme = settings.theme.clone();
290294
291295 let mut bindings = crate::keybindings::setup_keybindings(&settings.tunables);
292296 settings.setup(&mut bindings);
@@ -305,6 +309,7 @@ impl Application {
305309 store,
306310 worker,
307311 terminal,
312 theme,
308313 bindings,
309314 actstack,
310315 screen,
@@ -427,7 +432,8 @@ impl Application {
427432 self.handle_info(info);
428433 },
429434 Err(e) => {
430 self.screen.push_error(e);
435 drop(store);
436 self.handle_error(e);
431437 },
432438 }
433439 },
@@ -457,7 +463,8 @@ impl Application {
457463 self.handle_info(info);
458464 },
459465 Err(e) => {
460 self.screen.push_error(e);
466 drop(store);
467 self.handle_error(e);
461468 },
462469 }
463470 },
@@ -829,7 +836,7 @@ impl Application {
829836 fn handle_info(&mut self, info: InfoMessage) {
830837 match info {
831838 InfoMessage::Message(info) => {
832 self.screen.push_info(info);
839 self.screen.push_message(info, self.theme.cmdbar.info);
833840 },
834841 InfoMessage::Pager(text) => {
835842 let pager = Box::new(Pager::new(text, vec![]));
@@ -838,6 +845,10 @@ impl Application {
838845 }
839846 }
840847
848 fn handle_error(&mut self, err: impl ToString) {
849 self.screen.push_message(err, self.theme.cmdbar.error);
850 }
851
841852 pub async fn run(&mut self) -> Result<(), std::io::Error> {
842853 self.terminal.clear()?;
843854
@@ -871,7 +882,7 @@ impl Application {
871882 continue;
872883 },
873884 Err(e) => {
874 self.screen.push_error(e);
885 self.handle_error(e);
875886
876887 // Skip processing any more keypress Actions until the next key.
877888 keyskip = true;
src/windows/mod.rs +13
@@ -481,6 +481,9 @@ impl WindowOps<IambInfo> for IambWindow {
481481 ..
482482 } = &mut store.application;
483483
484 let default_list_style = settings.theme.default;
485 let default_rooms_style = settings.theme.rooms.default;
486
484487 match self {
485488 IambWindow::Room(state) => state.draw(area, buf, focused, store),
486489 IambWindow::DirectList(state) => {
@@ -499,6 +502,7 @@ impl WindowOps<IambInfo> for IambWindow {
499502 .empty_message("No direct messages yet!")
500503 .empty_alignment(Alignment::Center)
501504 .focus(focused)
505 .style(default_rooms_style)
502506 .render(area, buf, state);
503507 },
504508 IambWindow::MemberList(state, room_id, last_fetch) => {
@@ -524,6 +528,7 @@ impl WindowOps<IambInfo> for IambWindow {
524528 .empty_message("No users here yet!")
525529 .empty_alignment(Alignment::Center)
526530 .focus(focused)
531 .style(default_list_style)
527532 .render(area, buf, state);
528533 },
529534 IambWindow::PinnedList(state, room_id, last_fetch) => {
@@ -551,6 +556,7 @@ impl WindowOps<IambInfo> for IambWindow {
551556 .empty_message("No pinned messages in this room")
552557 .empty_alignment(Alignment::Center)
553558 .focus(focused)
559 .style(default_list_style)
554560 .render(area, buf, state);
555561 },
556562 IambWindow::RoomList(state) => {
@@ -569,6 +575,7 @@ impl WindowOps<IambInfo> for IambWindow {
569575 .empty_message("You haven't joined any rooms yet")
570576 .empty_alignment(Alignment::Center)
571577 .focus(focused)
578 .style(default_rooms_style)
572579 .render(area, buf, state);
573580 },
574581 IambWindow::ChatList(state) => {
@@ -589,6 +596,7 @@ impl WindowOps<IambInfo> for IambWindow {
589596 .empty_message("You do not have rooms or dms yet")
590597 .empty_alignment(Alignment::Center)
591598 .focus(focused)
599 .style(default_rooms_style)
592600 .render(area, buf, state);
593601 },
594602 IambWindow::UnreadList(state) => {
@@ -610,6 +618,7 @@ impl WindowOps<IambInfo> for IambWindow {
610618 .empty_message("You do not have any unreads yet")
611619 .empty_alignment(Alignment::Center)
612620 .focus(focused)
621 .style(default_rooms_style)
613622 .render(area, buf, state);
614623 },
615624 IambWindow::MentionsList(state) => {
@@ -631,6 +640,7 @@ impl WindowOps<IambInfo> for IambWindow {
631640 .empty_message("You do not have any unread mentions yet")
632641 .empty_alignment(Alignment::Center)
633642 .focus(focused)
643 .style(default_rooms_style)
634644 .render(area, buf, state);
635645 },
636646 IambWindow::InvitesList(state) => {
@@ -652,6 +662,7 @@ impl WindowOps<IambInfo> for IambWindow {
652662 .empty_message("You do not have any open invites")
653663 .empty_alignment(Alignment::Center)
654664 .focus(focused)
665 .style(default_rooms_style)
655666 .render(area, buf, state);
656667 },
657668 IambWindow::SpaceList(state) => {
@@ -671,6 +682,7 @@ impl WindowOps<IambInfo> for IambWindow {
671682 .empty_message("You haven't joined any spaces yet")
672683 .empty_alignment(Alignment::Center)
673684 .focus(focused)
685 .style(default_rooms_style)
674686 .render(area, buf, state);
675687 },
676688 IambWindow::VerifyList(state) => {
@@ -693,6 +705,7 @@ impl WindowOps<IambInfo> for IambWindow {
693705 .empty_message("No in-progress verifications")
694706 .empty_alignment(Alignment::Center)
695707 .focus(focused)
708 .style(default_list_style)
696709 .render(area, buf, state);
697710 },
698711 IambWindow::Welcome(state) => state.draw(area, buf, focused, store),
src/windows/room/chat.rs +2
@@ -1340,8 +1340,10 @@ impl StatefulWidget for Chat<'_> {
13401340 tbox.render(textarea, buf, &mut state.tbox);
13411341
13421342 // Render the message scrollback.
1343 let scrollback_style = self.store.application.settings.theme.timeline.default;
13431344 let scrollback_focused = state.focus.is_scrollback() && self.focused;
13441345 let scrollback = Scrollback::new(self.store)
1346 .style(scrollback_style)
13451347 .focus(scrollback_focused)
13461348 .room_focus(self.focused);
13471349 scrollback.render(scrollarea, buf, &mut state.scrollback);
src/windows/room/scrollback.rs +22 −2
@@ -555,7 +555,11 @@ impl ScrollbackState {
555555
556556impl WindowOps<IambInfo> for ScrollbackState {
557557 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)
559563 }
560564
561565 fn dup(&self, _: &mut ProgramStore) -> Self {
@@ -1257,13 +1261,25 @@ fn render_jump_to_recent(area: Rect, buf: &mut Buffer, focused: bool) -> Rect {
12571261
12581262pub struct Scrollback<'a> {
12591263 room_focused: bool,
1264 style: Style,
12601265 focused: bool,
12611266 store: &'a mut ProgramStore,
12621267}
12631268
12641269impl<'a> Scrollback<'a> {
12651270 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
12671283 }
12681284
12691285 /// Indicate whether the room window is currently focused, regardless of whether the scrollback
@@ -1284,6 +1300,10 @@ impl StatefulWidget for Scrollback<'_> {
12841300 type State = ScrollbackState;
12851301
12861302 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:
12871307 state.term_cursor = (area.left(), area.top());
12881308
12891309 let info = self.store.application.rooms.get_or_default(state.room_id.clone());
src/windows/welcome.rs +6 −3
@@ -1,6 +1,6 @@
11//! Welcome Window
22
3use modalkit_ratatui::textbox::TextBoxState;
3use modalkit_ratatui::textbox::{TextBox, TextBoxState};
44
55use crate::prelude::*;
66
@@ -45,9 +45,12 @@ impl TerminalCursor for WelcomeState {
4545}
4646
4747impl 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) {
4949 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)
5154 }
5255
5356 fn dup(&self, store: &mut ProgramStore) -> Self {