Commit ff4d92e890
Unregistered key
Layout: unified · split
config.example.toml +6
| @@ -88,3 +88,9 @@ split = [ | ||
| 88 | 88 | cache = "/home/user/.cache/iamb/" |
| 89 | 89 | logs = "/home/user/.local/share/iamb/logs/" |
| 90 | 90 | downloads = "/home/user/Downloads/" |
| 91 | ||
| 92 | [theme] | |
| 93 | timeline.state.color = "cyan" | |
| 94 | timeline.redacted.color = "245" # light gray | |
| 95 | # How to use truecolor for terminals that support it: | |
| 96 | # rooms.unread.color = "#ff55bb" # pink | |
docs/iamb.5 +133 −19
| @@ -374,6 +374,38 @@ and | ||
| 374 | 374 | Both can be used via |
| 375 | 375 | .Dq Sy title|prompt . |
| 376 | 376 | .El |
| 377 | .Sh COLORS | |
| 378 | The | |
| 379 | .Sy settings.users | |
| 380 | and | |
| 381 | .Sy theme | |
| 382 | subsections allows configuring the appearance of many elements. | |
| 383 | For settings that take a color value, you can use either a named color, an 8-bit color value or a hex value. | |
| 384 | .Pp | |
| 385 | The named colors are: | |
| 386 | .Dq Sy black , | |
| 387 | .Dq Sy red , | |
| 388 | .Dq Sy green , | |
| 389 | .Dq Sy yellow , | |
| 390 | .Dq Sy blue , | |
| 391 | .Dq Sy magenta , | |
| 392 | .Dq Sy cyan , | |
| 393 | .Dq Sy gray , | |
| 394 | .Dq Sy dark-gray , | |
| 395 | .Dq Sy light-red , | |
| 396 | .Dq Sy light-green , | |
| 397 | .Dq Sy light-yellow , | |
| 398 | .Dq Sy light-blue , | |
| 399 | .Dq Sy light-magenta , | |
| 400 | .Dq Sy light-cyan , | |
| 401 | .Dq Sy white , | |
| 402 | and | |
| 403 | .Dq Sy reset , | |
| 404 | The 8-bit ANSI color must in the range of 0 to 255 where the first 16 colors correspond to the named colors. | |
| 405 | The hex value is given as | |
| 406 | .Dq Sy #RRGGBB . | |
| 407 | If the terminal does not support truecolor, all hex colors will fall back to the default text color. | |
| 408 | All values must be given as a string. | |
| 377 | 409 | .Sh IMAGE PREVIEWS |
| 378 | 410 | The |
| 379 | 411 | .Sy settings.image_preview |
| @@ -639,6 +671,104 @@ Whether to set the title of the terminal window to | ||
| 639 | 671 | .Dq Sy iamb (<user_id>) . |
| 640 | 672 | Defaults to true. |
| 641 | 673 | .El |
| 674 | .Sh "THEME OVERRIDES" | |
| 675 | The | |
| 676 | .Sy theme | |
| 677 | subsection allows you to override the colors used for different parts of the user interface. | |
| 678 | Individual, stylable UI elements have the following properties: | |
| 679 | .Bl -tag -width Ds | |
| 680 | .It Sy color | |
| 681 | Configure the foreground color for text. | |
| 682 | See the | |
| 683 | .Sx "COLORS" | |
| 684 | section for the supported color format. | |
| 685 | .It Sy background | |
| 686 | Configure the background color for text. | |
| 687 | See the | |
| 688 | .Sx "COLORS" | |
| 689 | section for the supported color format. | |
| 690 | .El | |
| 691 | Within | |
| 692 | .Sy theme , | |
| 693 | there are several subsections for specific UI areas: | |
| 694 | .Bl -tag -width Ds | |
| 695 | .It Sy messages | |
| 696 | For controlling how the bodies of messages are styled. | |
| 697 | UI elements you can set within this subsection are: | |
| 698 | .Bl -tag -width Ds | |
| 699 | .It Sy default | |
| 700 | Configure the default styling for messages. | |
| 701 | .It Sy code | |
| 702 | Configure the styling for | |
| 703 | .Sy "<code>" | |
| 704 | elements in formatted message bodies. | |
| 705 | .It Sy "code_block" | |
| 706 | Configure the styling for | |
| 707 | .Sy "<pre>" | |
| 708 | elements in formatted message bodies. | |
| 709 | .El | |
| 710 | .It Sy timeline | |
| 711 | For controlling how other elements within the timeline are styled. | |
| 712 | UI elements you can set within this subsection are: | |
| 713 | .Bl -tag -width Ds | |
| 714 | .It Sy default | |
| 715 | Configure the default styling for text in the timeline. | |
| 716 | .It Sy date | |
| 717 | Configure the how the dates for messages are styled. | |
| 718 | .It Sy time | |
| 719 | Configure the how the time a message was sent is styled. | |
| 720 | .It Sy state | |
| 721 | Configure how the text shown for state events is styled. | |
| 722 | .It Sy sticker | |
| 723 | Configure how any text shown for stickers is styled. | |
| 724 | .It Sy poll | |
| 725 | Configure how the text in polls is styled. | |
| 726 | .It Sy notice | |
| 727 | Configure how server notices is styled. | |
| 728 | .It Sy redacted | |
| 729 | Configure how redacted events in the timeline is styled. | |
| 730 | .El | |
| 731 | .It Sy windows | |
| 732 | For controlling how the windows are styled. | |
| 733 | .Bl -tag -width Ds | |
| 734 | .It Sy border | |
| 735 | Configure how the border characters are styled. | |
| 736 | .It Sy border_focused | |
| 737 | Configure how the border characters for focused window are styled. | |
| 738 | .It Sy title | |
| 739 | Configure how the window titles are styled. | |
| 740 | .El | |
| 741 | .It Sy tabs | |
| 742 | For controlling how tabs are styled. | |
| 743 | UI elements you can set within this subsection are: | |
| 744 | .Bl -tag -width Ds | |
| 745 | .It Sy title | |
| 746 | Configure how tab titles are styled. | |
| 747 | .It Sy title_focused | |
| 748 | Configure how the title of the focused tab is styled. | |
| 749 | .El | |
| 750 | .It Sy rooms | |
| 751 | For controlling how lists of rooms like | |
| 752 | .Sy :unreads | |
| 753 | or | |
| 754 | .Sy :chats | |
| 755 | are styled. | |
| 756 | UI elements you can set within this subsection are: | |
| 757 | .Bl -tag -width Ds | |
| 758 | .It Sy default | |
| 759 | Configure the default style for text in room lists. | |
| 760 | .It Sy unread | |
| 761 | Configure the text for unread rooms in lists is styled. | |
| 762 | .El | |
| 763 | .El | |
| 764 | .Ss Example: Make code blocks a lighter gray background and state events red | |
| 765 | .Bd -literal -offset indent | |
| 766 | [theme.messages] | |
| 767 | code_block.background = "245" | |
| 768 | ||
| 769 | [theme.timeline] | |
| 770 | state.color = "cyan" | |
| 771 | .Ed | |
| 642 | 772 | .Sh "USER OVERRIDES" |
| 643 | 773 | The |
| 644 | 774 | .Sy settings.users |
| @@ -651,25 +781,9 @@ and are typically written as inline tables containing the following keys: | ||
| 651 | 781 | Change the display name of the user. |
| 652 | 782 | .It Sy color |
| 653 | 783 | Change the color the user is shown as. |
| 654 | Possible values are: | |
| 655 | .Dq Sy black , | |
| 656 | .Dq Sy blue , | |
| 657 | .Dq Sy cyan , | |
| 658 | .Dq Sy dark-gray , | |
| 659 | .Dq Sy gray , | |
| 660 | .Dq Sy green , | |
| 661 | .Dq Sy light-blue , | |
| 662 | .Dq Sy light-cyan , | |
| 663 | .Dq Sy light-green , | |
| 664 | .Dq Sy light-magenta , | |
| 665 | .Dq Sy light-red , | |
| 666 | .Dq Sy light-yellow , | |
| 667 | .Dq Sy magenta , | |
| 668 | .Dq Sy none , | |
| 669 | .Dq Sy red , | |
| 670 | .Dq Sy white , | |
| 671 | and | |
| 672 | .Dq Sy yellow . | |
| 784 | See the | |
| 785 | .Sx "COLORS" | |
| 786 | section for the supported color format. | |
| 673 | 787 | .El |
| 674 | 788 | .Ss Example 1: Override how @ada:example.com appears in chat |
| 675 | 789 | .Bd -literal -offset indent |
src/config.rs → src/config/mod.rs renamed +59 −54
| @@ -6,6 +6,7 @@ use std::fs::File; | ||
| 6 | 6 | use std::hash::{Hash, Hasher}; |
| 7 | 7 | use std::io::{BufReader, BufWriter, Write as _}; |
| 8 | 8 | use std::process; |
| 9 | use std::sync::Arc; | |
| 9 | 10 | |
| 10 | 11 | use clap::Parser; |
| 11 | 12 | use indexmap::IndexMap; |
| @@ -27,6 +28,8 @@ use serde::{Deserialize, Deserializer, Serialize}; | ||
| 27 | 28 | use crate::base::{SortColumn, SortFieldRoom, SortFieldUser, SortOrder}; |
| 28 | 29 | use crate::prelude::*; |
| 29 | 30 | |
| 31 | pub mod theme; | |
| 32 | ||
| 30 | 33 | pub type Aliases = IndexMap<String, String>; |
| 31 | 34 | type Macros = HashMap<VimModes, HashMap<Keys, Keys>>; |
| 32 | 35 | |
| @@ -228,7 +231,6 @@ macro_rules! deserialize_str_with_visitor { | ||
| 228 | 231 | |
| 229 | 232 | deserialize_str_with_visitor!(Keys, KeysVisitor); |
| 230 | 233 | deserialize_str_with_visitor!(VimModes, VimModesVisitor); |
| 231 | deserialize_str_with_visitor!(UserColor, UserColorVisitor); | |
| 232 | 234 | deserialize_str_with_visitor!(EncryptionIndicatorLocation, EncryptionIndicatorLocationVisitor); |
| 233 | 235 | deserialize_str_with_visitor!(NotifyVia, NotifyViaVisitor); |
| 234 | 236 | deserialize_str_with_visitor!(ProxyUrl, ProxyUrlVisitor); |
| @@ -290,44 +292,6 @@ impl Visitor<'_> for VimModesVisitor { | ||
| 290 | 292 | } |
| 291 | 293 | } |
| 292 | 294 | |
| 293 | #[derive(Clone, Debug, Eq, PartialEq)] | |
| 294 | pub struct UserColor(pub Color); | |
| 295 | pub struct UserColorVisitor; | |
| 296 | ||
| 297 | impl Visitor<'_> for UserColorVisitor { | |
| 298 | type Value = UserColor; | |
| 299 | ||
| 300 | fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | |
| 301 | formatter.write_str("a valid color") | |
| 302 | } | |
| 303 | ||
| 304 | fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> | |
| 305 | where | |
| 306 | E: SerdeError, | |
| 307 | { | |
| 308 | match value { | |
| 309 | "none" => Ok(UserColor(Color::Reset)), | |
| 310 | "red" => Ok(UserColor(Color::Red)), | |
| 311 | "black" => Ok(UserColor(Color::Black)), | |
| 312 | "green" => Ok(UserColor(Color::Green)), | |
| 313 | "yellow" => Ok(UserColor(Color::Yellow)), | |
| 314 | "blue" => Ok(UserColor(Color::Blue)), | |
| 315 | "magenta" => Ok(UserColor(Color::Magenta)), | |
| 316 | "cyan" => Ok(UserColor(Color::Cyan)), | |
| 317 | "gray" => Ok(UserColor(Color::Gray)), | |
| 318 | "dark-gray" => Ok(UserColor(Color::DarkGray)), | |
| 319 | "light-red" => Ok(UserColor(Color::LightRed)), | |
| 320 | "light-green" => Ok(UserColor(Color::LightGreen)), | |
| 321 | "light-yellow" => Ok(UserColor(Color::LightYellow)), | |
| 322 | "light-blue" => Ok(UserColor(Color::LightBlue)), | |
| 323 | "light-magenta" => Ok(UserColor(Color::LightMagenta)), | |
| 324 | "light-cyan" => Ok(UserColor(Color::LightCyan)), | |
| 325 | "white" => Ok(UserColor(Color::White)), | |
| 326 | _ => Err(E::custom("Could not parse color")), | |
| 327 | } | |
| 328 | } | |
| 329 | } | |
| 330 | ||
| 331 | 295 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 332 | 296 | pub struct Session { |
| 333 | 297 | access_token: String, |
| @@ -364,7 +328,7 @@ impl From<MatrixSession> for Session { | ||
| 364 | 328 | |
| 365 | 329 | #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] |
| 366 | 330 | pub struct UserDisplayTunables { |
| 367 | pub color: Option<UserColor>, | |
| 331 | pub color: Option<Color>, | |
| 368 | 332 | pub name: Option<String>, |
| 369 | 333 | } |
| 370 | 334 | |
| @@ -1207,6 +1171,7 @@ pub struct ProfileConfig { | ||
| 1207 | 1171 | pub password_file: Option<PathBuf>, |
| 1208 | 1172 | pub url: Option<Url>, |
| 1209 | 1173 | pub settings: Option<Tunables>, |
| 1174 | pub theme: Option<theme::Theme>, | |
| 1210 | 1175 | pub dirs: Option<Directories>, |
| 1211 | 1176 | pub layout: Option<Layout>, |
| 1212 | 1177 | pub macros: Option<Macros>, |
| @@ -1222,6 +1187,7 @@ pub struct IambConfig { | ||
| 1222 | 1187 | pub layout: Option<Layout>, |
| 1223 | 1188 | pub macros: Option<Macros>, |
| 1224 | 1189 | pub aliases: Option<Aliases>, |
| 1190 | pub theme: Option<theme::Theme>, | |
| 1225 | 1191 | } |
| 1226 | 1192 | |
| 1227 | 1193 | impl IambConfig { |
| @@ -1250,6 +1216,7 @@ pub struct ApplicationSettings { | ||
| 1250 | 1216 | pub sqlite_cache_dir: PathBuf, |
| 1251 | 1217 | pub profile_name: String, |
| 1252 | 1218 | pub profile: ProfileConfig, |
| 1219 | pub theme: Arc<theme::ThemeValues>, | |
| 1253 | 1220 | pub tunables: TunableValues, |
| 1254 | 1221 | pub dirs: DirectoryValues, |
| 1255 | 1222 | pub layout: Layout, |
| @@ -1304,6 +1271,7 @@ impl ApplicationSettings { | ||
| 1304 | 1271 | layout, |
| 1305 | 1272 | macros, |
| 1306 | 1273 | aliases, |
| 1274 | theme, | |
| 1307 | 1275 | } = config; |
| 1308 | 1276 | |
| 1309 | 1277 | validate_profile_names(&profiles); |
| @@ -1357,6 +1325,10 @@ impl ApplicationSettings { | ||
| 1357 | 1325 | let dirs = profile.dirs.take().unwrap_or_default().merge(dirs); |
| 1358 | 1326 | let dirs = dirs.values(); |
| 1359 | 1327 | |
| 1328 | let theme = theme.unwrap_or_default().merge(theme::default_theme()); | |
| 1329 | let theme = profile.theme.take().unwrap_or_default().merge(theme); | |
| 1330 | let theme = Arc::new(theme.values()); | |
| 1331 | ||
| 1360 | 1332 | // Create directories |
| 1361 | 1333 | dirs.create_dir_all()?; |
| 1362 | 1334 | |
| @@ -1401,6 +1373,7 @@ impl ApplicationSettings { | ||
| 1401 | 1373 | sqlite_cache_dir, |
| 1402 | 1374 | profile_name, |
| 1403 | 1375 | profile, |
| 1376 | theme, | |
| 1404 | 1377 | tunables, |
| 1405 | 1378 | dirs, |
| 1406 | 1379 | layout, |
| @@ -1451,12 +1424,7 @@ impl ApplicationSettings { | ||
| 1451 | 1424 | .tunables |
| 1452 | 1425 | .users |
| 1453 | 1426 | .get(user_id) |
| 1454 | .map(|user| { | |
| 1455 | ( | |
| 1456 | user.color.as_ref().map(|c| c.0), | |
| 1457 | user.name.as_ref().and_then(|s| s.chars().next()), | |
| 1458 | ) | |
| 1459 | }) | |
| 1427 | .map(|user| (user.color, user.name.as_ref().and_then(|s| s.chars().next()))) | |
| 1460 | 1428 | .unwrap_or_default(); |
| 1461 | 1429 | |
| 1462 | 1430 | let color = color.unwrap_or_else(|| user_color(user_id.as_str())); |
| @@ -1474,7 +1442,7 @@ impl ApplicationSettings { | ||
| 1474 | 1442 | self.tunables |
| 1475 | 1443 | .users |
| 1476 | 1444 | .get(user_id) |
| 1477 | .map(|user| (user.color.as_ref().map(|c| c.0), user.name.clone().map(Cow::Owned))) | |
| 1445 | .map(|user| (user.color, user.name.clone().map(Cow::Owned))) | |
| 1478 | 1446 | .unwrap_or_default() |
| 1479 | 1447 | } |
| 1480 | 1448 | |
| @@ -1482,7 +1450,7 @@ impl ApplicationSettings { | ||
| 1482 | 1450 | self.tunables |
| 1483 | 1451 | .users |
| 1484 | 1452 | .get(user_id) |
| 1485 | .and_then(|user| user.color.as_ref().map(|c| c.0)) | |
| 1453 | .and_then(|user| user.color) | |
| 1486 | 1454 | .unwrap_or_else(|| user_color(user_id.as_str())) |
| 1487 | 1455 | } |
| 1488 | 1456 | |
| @@ -1559,13 +1527,13 @@ mod tests { | ||
| 1559 | 1527 | fn test_merge_users() { |
| 1560 | 1528 | let a = None; |
| 1561 | 1529 | let b = vec![(user_id!("@a:b.c").to_owned(), UserDisplayTunables { |
| 1562 | color: Some(UserColor(Color::Red)), | |
| 1530 | color: Some(Color::Red), | |
| 1563 | 1531 | name: Some("Hello".into()), |
| 1564 | 1532 | })] |
| 1565 | 1533 | .into_iter() |
| 1566 | 1534 | .collect::<HashMap<_, _>>(); |
| 1567 | 1535 | let c = vec![(user_id!("@a:b.c").to_owned(), UserDisplayTunables { |
| 1568 | color: Some(UserColor(Color::Green)), | |
| 1536 | color: Some(Color::Green), | |
| 1569 | 1537 | name: Some("World".into()), |
| 1570 | 1538 | })] |
| 1571 | 1539 | .into_iter() |
| @@ -1611,17 +1579,52 @@ mod tests { | ||
| 1611 | 1579 | assert_eq!(res.typing_notice_send, None); |
| 1612 | 1580 | assert_eq!(res.typing_notice_display, None); |
| 1613 | 1581 | assert_eq!(res.users, Some(HashMap::new())); |
| 1582 | } | |
| 1614 | 1583 | |
| 1584 | #[test] | |
| 1585 | fn test_parse_user_colors() { | |
| 1586 | let expect = |color| UserDisplayTunables { color: Some(color), name: Some("Tim".into()) }; | |
| 1587 | ||
| 1588 | // Unprefixed color: | |
| 1615 | 1589 | let res: Tunables = serde_json::from_str( |
| 1616 | 1590 | "{\"users\": {\"@a:b.c\": {\"color\": \"black\", \"name\": \"Tim\"}}}", |
| 1617 | 1591 | ) |
| 1618 | 1592 | .unwrap(); |
| 1619 | 1593 | assert_eq!(res.typing_notice_send, None); |
| 1620 | 1594 | assert_eq!(res.typing_notice_display, None); |
| 1621 | let users = vec![(user_id!("@a:b.c").to_owned(), UserDisplayTunables { | |
| 1622 | color: Some(UserColor(Color::Black)), | |
| 1623 | name: Some("Tim".into()), | |
| 1624 | })]; | |
| 1595 | let users = vec![(user_id!("@a:b.c").to_owned(), expect(Color::Black))]; | |
| 1596 | assert_eq!(res.users, Some(users.into_iter().collect())); | |
| 1597 | ||
| 1598 | // Color with `light-` prefix: | |
| 1599 | let res: Tunables = serde_json::from_str( | |
| 1600 | "{\"users\": {\"@a:b.c\": {\"color\": \"light-red\", \"name\": \"Tim\"}}}", | |
| 1601 | ) | |
| 1602 | .unwrap(); | |
| 1603 | let users = vec![(user_id!("@a:b.c").to_owned(), expect(Color::LightRed))]; | |
| 1604 | assert_eq!(res.users, Some(users.into_iter().collect())); | |
| 1605 | ||
| 1606 | // Color name with `light-` prefix: | |
| 1607 | let res: Tunables = serde_json::from_str( | |
| 1608 | "{\"users\": {\"@a:b.c\": {\"color\": \"light-red\", \"name\": \"Tim\"}}}", | |
| 1609 | ) | |
| 1610 | .unwrap(); | |
| 1611 | let users = vec![(user_id!("@a:b.c").to_owned(), expect(Color::LightRed))]; | |
| 1612 | assert_eq!(res.users, Some(users.into_iter().collect())); | |
| 1613 | ||
| 1614 | // Color name with `light` prefix, no hyphen: | |
| 1615 | let res: Tunables = serde_json::from_str( | |
| 1616 | "{\"users\": {\"@a:b.c\": {\"color\": \"lightblue\", \"name\": \"Tim\"}}}", | |
| 1617 | ) | |
| 1618 | .unwrap(); | |
| 1619 | let users = vec![(user_id!("@a:b.c").to_owned(), expect(Color::LightBlue))]; | |
| 1620 | assert_eq!(res.users, Some(users.into_iter().collect())); | |
| 1621 | ||
| 1622 | // Hex color name: | |
| 1623 | let res: Tunables = serde_json::from_str( | |
| 1624 | "{\"users\": {\"@a:b.c\": {\"color\": \"#ff55bb\", \"name\": \"Tim\"}}}", | |
| 1625 | ) | |
| 1626 | .unwrap(); | |
| 1627 | let users = vec![(user_id!("@a:b.c").to_owned(), expect(Color::Rgb(0xff, 0x55, 0xbb)))]; | |
| 1625 | 1628 | assert_eq!(res.users, Some(users.into_iter().collect())); |
| 1626 | 1629 | } |
| 1627 | 1630 | |
| @@ -1924,6 +1927,7 @@ mod tests { | ||
| 1924 | 1927 | layout, |
| 1925 | 1928 | macros, |
| 1926 | 1929 | aliases, |
| 1930 | theme, | |
| 1927 | 1931 | } = &config; |
| 1928 | 1932 | |
| 1929 | 1933 | // There should be an example object for each top-level field. |
| @@ -1934,6 +1938,7 @@ mod tests { | ||
| 1934 | 1938 | assert!(layout.is_some()); |
| 1935 | 1939 | assert!(macros.is_some()); |
| 1936 | 1940 | assert!(aliases.is_some()); |
| 1941 | assert!(theme.is_some()); | |
| 1937 | 1942 | } |
| 1938 | 1943 | |
| 1939 | 1944 | #[test] |
src/config/theme.rs added +322
| @@ -0,0 +1,322 @@ | ||
| 1 | //! # Logic for parsing styling configuration into [Style]. | |
| 2 | use serde::Deserialize; | |
| 3 | ||
| 4 | use crate::prelude::*; | |
| 5 | ||
| 6 | pub fn default_theme() -> Theme { | |
| 7 | Theme { | |
| 8 | messages: ThemeMessages { | |
| 9 | code: Stylable { color: None, background: Some(Color::Indexed(236)) }, | |
| 10 | ..Default::default() | |
| 11 | }, | |
| 12 | ..Default::default() | |
| 13 | } | |
| 14 | } | |
| 15 | ||
| 16 | #[derive(Clone, Copy, Debug, Default, Deserialize)] | |
| 17 | pub struct Stylable { | |
| 18 | pub background: Option<Color>, | |
| 19 | pub color: Option<Color>, | |
| 20 | } | |
| 21 | ||
| 22 | impl Stylable { | |
| 23 | fn merge(self, other: Self) -> Self { | |
| 24 | Self { | |
| 25 | background: self.background.or(other.background), | |
| 26 | color: self.color.or(other.color), | |
| 27 | } | |
| 28 | } | |
| 29 | } | |
| 30 | ||
| 31 | impl From<Stylable> for Style { | |
| 32 | fn from(styled: Stylable) -> Self { | |
| 33 | let mut style = Style::default(); | |
| 34 | ||
| 35 | if let Some(bg) = styled.background { | |
| 36 | style = style.bg(bg); | |
| 37 | } | |
| 38 | ||
| 39 | if let Some(fg) = styled.color { | |
| 40 | style = style.fg(fg); | |
| 41 | } | |
| 42 | ||
| 43 | style | |
| 44 | } | |
| 45 | } | |
| 46 | ||
| 47 | #[derive(Clone, Debug, Default, Deserialize)] | |
| 48 | pub struct Theme { | |
| 49 | /// Configuration specificaly for messages shown within a room's timeline. | |
| 50 | #[serde(default)] | |
| 51 | messages: ThemeMessages, | |
| 52 | ||
| 53 | /// Configuration for styling a room's timeline. | |
| 54 | #[serde(default)] | |
| 55 | timeline: ThemeTimeline, | |
| 56 | ||
| 57 | /// Configuration for styling items within room lists. | |
| 58 | #[serde(default)] | |
| 59 | rooms: ThemeRooms, | |
| 60 | ||
| 61 | /// Configuration for styling tabs. | |
| 62 | #[serde(default)] | |
| 63 | tabs: ThemeTabs, | |
| 64 | ||
| 65 | /// Configuration for styling windows. | |
| 66 | #[serde(default)] | |
| 67 | windows: ThemeWindows, | |
| 68 | } | |
| 69 | ||
| 70 | impl Theme { | |
| 71 | pub fn merge(self, other: Self) -> Self { | |
| 72 | Self { | |
| 73 | messages: self.messages.merge(other.messages), | |
| 74 | tabs: self.tabs.merge(other.tabs), | |
| 75 | timeline: self.timeline.merge(other.timeline), | |
| 76 | rooms: self.rooms.merge(other.rooms), | |
| 77 | windows: self.windows.merge(other.windows), | |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 81 | pub fn values(self) -> ThemeValues { | |
| 82 | let base = Style::default(); | |
| 83 | ||
| 84 | ThemeValues { | |
| 85 | messages: self.messages.values(base), | |
| 86 | timeline: self.timeline.values(base), | |
| 87 | rooms: self.rooms.values(base), | |
| 88 | tabs: self.tabs.values(base), | |
| 89 | windows: self.windows.values(base), | |
| 90 | } | |
| 91 | } | |
| 92 | } | |
| 93 | ||
| 94 | #[derive(Clone, Debug, Default)] | |
| 95 | pub struct ThemeValues { | |
| 96 | /// Styling specificaly for messages shown within a room's timeline. | |
| 97 | pub messages: ThemeMessagesValues, | |
| 98 | ||
| 99 | /// Styling for a room's timeline. | |
| 100 | pub timeline: ThemeTimelineValues, | |
| 101 | ||
| 102 | /// Styling for items within room lists. | |
| 103 | pub rooms: ThemeRoomsValues, | |
| 104 | ||
| 105 | /// Styling for rendering tabs. | |
| 106 | pub tabs: ThemeTabsValues, | |
| 107 | ||
| 108 | /// Styling for rendering windows. | |
| 109 | pub windows: ThemeWindowsValues, | |
| 110 | } | |
| 111 | ||
| 112 | #[derive(Clone, Debug, Default, Deserialize)] | |
| 113 | struct ThemeMessages { | |
| 114 | #[serde(default)] | |
| 115 | default: Stylable, | |
| 116 | ||
| 117 | #[serde(default)] | |
| 118 | code: Stylable, | |
| 119 | ||
| 120 | #[serde(default)] | |
| 121 | code_block: Stylable, | |
| 122 | } | |
| 123 | ||
| 124 | impl ThemeMessages { | |
| 125 | fn merge(self, other: Self) -> Self { | |
| 126 | Self { | |
| 127 | default: self.default.merge(other.default), | |
| 128 | code: self.code.merge(other.code), | |
| 129 | code_block: self.code_block.merge(other.code_block), | |
| 130 | } | |
| 131 | } | |
| 132 | ||
| 133 | fn values(self, base: Style) -> ThemeMessagesValues { | |
| 134 | let code = self.code.merge(self.default); | |
| 135 | let code_block = self.code_block.merge(code); | |
| 136 | ||
| 137 | ThemeMessagesValues { | |
| 138 | default: base.patch(self.default), | |
| 139 | code: base.patch(code), | |
| 140 | code_block: base.patch(code_block), | |
| 141 | } | |
| 142 | } | |
| 143 | } | |
| 144 | ||
| 145 | #[derive(Clone, Debug, Default)] | |
| 146 | pub struct ThemeMessagesValues { | |
| 147 | pub default: Style, | |
| 148 | pub code: Style, | |
| 149 | pub code_block: Style, | |
| 150 | } | |
| 151 | ||
| 152 | #[derive(Clone, Debug, Default, Deserialize)] | |
| 153 | struct ThemeRooms { | |
| 154 | #[serde(default)] | |
| 155 | default: Stylable, | |
| 156 | ||
| 157 | #[serde(default)] | |
| 158 | unread: Stylable, | |
| 159 | } | |
| 160 | ||
| 161 | impl ThemeRooms { | |
| 162 | fn merge(self, other: Self) -> Self { | |
| 163 | Self { | |
| 164 | default: self.default.merge(other.default), | |
| 165 | unread: self.unread.merge(other.unread), | |
| 166 | } | |
| 167 | } | |
| 168 | ||
| 169 | fn values(self, base: Style) -> ThemeRoomsValues { | |
| 170 | let unread = self.unread.merge(self.default); | |
| 171 | ||
| 172 | ThemeRoomsValues { | |
| 173 | default: base.patch(self.default), | |
| 174 | unread: base.patch(unread), | |
| 175 | } | |
| 176 | } | |
| 177 | } | |
| 178 | ||
| 179 | #[derive(Clone, Debug, Default)] | |
| 180 | pub struct ThemeRoomsValues { | |
| 181 | pub default: Style, | |
| 182 | pub unread: Style, | |
| 183 | } | |
| 184 | ||
| 185 | #[derive(Clone, Debug, Default, Deserialize)] | |
| 186 | struct ThemeTabs { | |
| 187 | #[serde(default)] | |
| 188 | title: Stylable, | |
| 189 | ||
| 190 | #[serde(default)] | |
| 191 | title_focused: Stylable, | |
| 192 | } | |
| 193 | ||
| 194 | impl ThemeTabs { | |
| 195 | fn merge(self, other: Self) -> Self { | |
| 196 | Self { | |
| 197 | title: self.title.merge(other.title), | |
| 198 | title_focused: self.title_focused.merge(other.title_focused), | |
| 199 | } | |
| 200 | } | |
| 201 | ||
| 202 | fn values(self, base: Style) -> ThemeTabsValues { | |
| 203 | let title_focused = self.title_focused.merge(self.title); | |
| 204 | ||
| 205 | ThemeTabsValues { | |
| 206 | title: base.patch(self.title), | |
| 207 | title_focused: base.patch(title_focused), | |
| 208 | } | |
| 209 | } | |
| 210 | } | |
| 211 | ||
| 212 | #[derive(Clone, Debug, Default)] | |
| 213 | pub struct ThemeTabsValues { | |
| 214 | pub title: Style, | |
| 215 | pub title_focused: Style, | |
| 216 | } | |
| 217 | ||
| 218 | #[derive(Clone, Debug, Default, Deserialize)] | |
| 219 | struct ThemeTimeline { | |
| 220 | #[serde(default)] | |
| 221 | default: Stylable, | |
| 222 | ||
| 223 | #[serde(default)] | |
| 224 | date: Stylable, | |
| 225 | ||
| 226 | #[serde(default)] | |
| 227 | time: Stylable, | |
| 228 | ||
| 229 | #[serde(default)] | |
| 230 | state: Stylable, | |
| 231 | ||
| 232 | #[serde(default)] | |
| 233 | sticker: Stylable, | |
| 234 | ||
| 235 | #[serde(default)] | |
| 236 | poll: Stylable, | |
| 237 | ||
| 238 | #[serde(default)] | |
| 239 | notice: Stylable, | |
| 240 | ||
| 241 | #[serde(default)] | |
| 242 | redacted: Stylable, | |
| 243 | } | |
| 244 | ||
| 245 | impl ThemeTimeline { | |
| 246 | fn merge(self, other: Self) -> Self { | |
| 247 | Self { | |
| 248 | default: self.default.merge(other.default), | |
| 249 | date: self.date.merge(other.date), | |
| 250 | time: self.time.merge(other.time), | |
| 251 | state: self.state.merge(other.state), | |
| 252 | sticker: self.sticker.merge(other.sticker), | |
| 253 | poll: self.poll.merge(other.poll), | |
| 254 | notice: self.notice.merge(other.notice), | |
| 255 | redacted: self.redacted.merge(other.redacted), | |
| 256 | } | |
| 257 | } | |
| 258 | ||
| 259 | fn values(self, base: Style) -> ThemeTimelineValues { | |
| 260 | let base = base.patch(self.default); | |
| 261 | ||
| 262 | ThemeTimelineValues { | |
| 263 | default: base, | |
| 264 | date: base.patch(self.date), | |
| 265 | time: base.patch(self.time), | |
| 266 | state: base.patch(self.state), | |
| 267 | sticker: base.patch(self.sticker), | |
| 268 | poll: base.patch(self.poll), | |
| 269 | notice: base.patch(self.notice), | |
| 270 | redacted: base.patch(self.redacted), | |
| 271 | } | |
| 272 | } | |
| 273 | } | |
| 274 | ||
| 275 | #[derive(Clone, Debug, Default)] | |
| 276 | pub struct ThemeTimelineValues { | |
| 277 | pub default: Style, | |
| 278 | pub date: Style, | |
| 279 | pub time: Style, | |
| 280 | pub state: Style, | |
| 281 | pub sticker: Style, | |
| 282 | pub poll: Style, | |
| 283 | pub notice: Style, | |
| 284 | pub redacted: Style, | |
| 285 | } | |
| 286 | ||
| 287 | #[derive(Clone, Debug, Default, Deserialize)] | |
| 288 | struct ThemeWindows { | |
| 289 | #[serde(default)] | |
| 290 | border: Stylable, | |
| 291 | ||
| 292 | #[serde(default)] | |
| 293 | border_focused: Stylable, | |
| 294 | ||
| 295 | #[serde(default)] | |
| 296 | title: Stylable, | |
| 297 | } | |
| 298 | ||
| 299 | impl ThemeWindows { | |
| 300 | fn merge(self, other: Self) -> Self { | |
| 301 | Self { | |
| 302 | border: self.border.merge(other.border), | |
| 303 | border_focused: self.border_focused.merge(other.border_focused), | |
| 304 | title: self.title.merge(other.title), | |
| 305 | } | |
| 306 | } | |
| 307 | ||
| 308 | fn values(self, base: Style) -> ThemeWindowsValues { | |
| 309 | ThemeWindowsValues { | |
| 310 | border: base.patch(self.border), | |
| 311 | border_focused: base.patch(self.border_focused.merge(self.border)), | |
| 312 | title: base.patch(self.title), | |
| 313 | } | |
| 314 | } | |
| 315 | } | |
| 316 | ||
| 317 | #[derive(Clone, Debug, Default)] | |
| 318 | pub struct ThemeWindowsValues { | |
| 319 | pub border: Style, | |
| 320 | pub border_focused: Style, | |
| 321 | pub title: Style, | |
| 322 | } | |
src/main.rs +8 −3
| @@ -332,6 +332,8 @@ impl Application { | ||
| 332 | 332 | term.clear()?; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | let theme = store.application.settings.theme.clone(); | |
| 336 | ||
| 335 | 337 | term.draw(|f| { |
| 336 | 338 | let area = f.area(); |
| 337 | 339 | |
| @@ -347,9 +349,12 @@ impl Application { | ||
| 347 | 349 | .show_dialog(dialogstr) |
| 348 | 350 | .show_mode(modestr) |
| 349 | 351 | .borders(true) |
| 350 | .border_style(Style::default().add_modifier(StyleModifier::DIM)) | |
| 351 | .tab_style(Style::default().add_modifier(StyleModifier::DIM)) | |
| 352 | .tab_style_focused(Style::default().remove_modifier(StyleModifier::DIM)) | |
| 352 | .border_style(theme.windows.border.add_modifier(StyleModifier::DIM)) | |
| 353 | .border_style_focused( | |
| 354 | theme.windows.border_focused.remove_modifier(StyleModifier::DIM), | |
| 355 | ) | |
| 356 | .tab_style(theme.tabs.title.add_modifier(StyleModifier::DIM)) | |
| 357 | .tab_style_focused(theme.tabs.title_focused.remove_modifier(StyleModifier::DIM)) | |
| 353 | 358 | .focus(focused); |
| 354 | 359 | f.render_stateful_widget(screen, area, sstate); |
| 355 | 360 | |
src/message/html.rs +38 −29
| @@ -368,7 +368,13 @@ impl StyleTreeNode { | ||
| 368 | 368 | } |
| 369 | 369 | }, |
| 370 | 370 | StyleTreeNode::Code(child, _) => { |
| 371 | let style = style.patch(printer.settings().theme.messages.code); | |
| 372 | ||
| 373 | let old_style = printer.replace_base_style(style); | |
| 374 | ||
| 371 | 375 | child.print(printer, style); |
| 376 | ||
| 377 | printer.replace_base_style(old_style); | |
| 372 | 378 | }, |
| 373 | 379 | StyleTreeNode::Header(child, level) => { |
| 374 | 380 | let style = style.add_modifier(StyleModifier::BOLD); |
| @@ -415,9 +421,11 @@ impl StyleTreeNode { | ||
| 415 | 421 | }, |
| 416 | 422 | StyleTreeNode::Pre(child) => { |
| 417 | 423 | let mut subp = printer.sub(2).literal(true); |
| 424 | let code_style = style.patch(subp.settings().theme.messages.code_block); | |
| 425 | let _ = subp.replace_base_style(code_style); | |
| 418 | 426 | let subw = subp.width(); |
| 419 | 427 | |
| 420 | child.print(&mut subp, style); | |
| 428 | child.print(&mut subp, code_style); | |
| 421 | 429 | |
| 422 | 430 | printer.commit(); |
| 423 | 431 | printer.push_line( |
| @@ -1446,6 +1454,7 @@ pub mod tests { | ||
| 1446 | 1454 | fn test_pre_tag() { |
| 1447 | 1455 | let info = mock_room(); |
| 1448 | 1456 | let settings = mock_settings(); |
| 1457 | let code_style = settings.theme.messages.code_block; | |
| 1449 | 1458 | let s = concat!( |
| 1450 | 1459 | "<pre><code class=\"language-rust\">", |
| 1451 | 1460 | "fn hello() -> usize {\n", |
| @@ -1469,19 +1478,19 @@ pub mod tests { | ||
| 1469 | 1478 | text.lines[1], |
| 1470 | 1479 | Line::from(vec![ |
| 1471 | 1480 | Span::raw(line::VERTICAL), |
| 1472 | Span::raw("fn"), | |
| 1473 | Span::raw(" "), | |
| 1474 | Span::raw("hello"), | |
| 1475 | Span::raw("("), | |
| 1476 | Span::raw(")"), | |
| 1477 | Span::raw(" "), | |
| 1478 | Span::raw("-"), | |
| 1479 | Span::raw(">"), | |
| 1480 | Span::raw(" "), | |
| 1481 | Span::raw("usize"), | |
| 1482 | Span::raw(" "), | |
| 1483 | Span::raw("{"), | |
| 1484 | Span::raw(" "), | |
| 1481 | Span::styled("fn", code_style), | |
| 1482 | Span::styled(" ", code_style), | |
| 1483 | Span::styled("hello", code_style), | |
| 1484 | Span::styled("(", code_style), | |
| 1485 | Span::styled(")", code_style), | |
| 1486 | Span::styled(" ", code_style), | |
| 1487 | Span::styled("-", code_style), | |
| 1488 | Span::styled(">", code_style), | |
| 1489 | Span::styled(" ", code_style), | |
| 1490 | Span::styled("usize", code_style), | |
| 1491 | Span::styled(" ", code_style), | |
| 1492 | Span::styled("{", code_style), | |
| 1493 | Span::styled(" ", code_style), | |
| 1485 | 1494 | Span::raw(line::VERTICAL) |
| 1486 | 1495 | ]) |
| 1487 | 1496 | ); |
| @@ -1489,13 +1498,13 @@ pub mod tests { | ||
| 1489 | 1498 | text.lines[2], |
| 1490 | 1499 | Line::from(vec![ |
| 1491 | 1500 | Span::raw(line::VERTICAL), |
| 1492 | Span::raw(" "), | |
| 1493 | Span::raw(" "), | |
| 1494 | Span::raw("/"), | |
| 1495 | Span::raw("/"), | |
| 1496 | Span::raw(" "), | |
| 1497 | Span::raw("weired"), | |
| 1498 | Span::raw(" "), | |
| 1501 | Span::styled(" ", code_style), | |
| 1502 | Span::styled(" ", code_style), | |
| 1503 | Span::styled("/", code_style), | |
| 1504 | Span::styled("/", code_style), | |
| 1505 | Span::styled(" ", code_style), | |
| 1506 | Span::styled("weired", code_style), | |
| 1507 | Span::styled(" ", code_style), | |
| 1499 | 1508 | Span::raw(line::VERTICAL) |
| 1500 | 1509 | ]) |
| 1501 | 1510 | ); |
| @@ -1503,12 +1512,12 @@ pub mod tests { | ||
| 1503 | 1512 | text.lines[3], |
| 1504 | 1513 | Line::from(vec![ |
| 1505 | 1514 | Span::raw(line::VERTICAL), |
| 1506 | Span::raw(" "), | |
| 1507 | Span::raw("return"), | |
| 1508 | Span::raw(" "), | |
| 1509 | Span::raw("5"), | |
| 1510 | Span::raw(";"), | |
| 1511 | Span::raw(" "), | |
| 1515 | Span::styled(" ", code_style), | |
| 1516 | Span::styled("return", code_style), | |
| 1517 | Span::styled(" ", code_style), | |
| 1518 | Span::styled("5", code_style), | |
| 1519 | Span::styled(";", code_style), | |
| 1520 | Span::styled(" ", code_style), | |
| 1512 | 1521 | Span::raw(line::VERTICAL) |
| 1513 | 1522 | ]) |
| 1514 | 1523 | ); |
| @@ -1516,8 +1525,8 @@ pub mod tests { | ||
| 1516 | 1525 | text.lines[4], |
| 1517 | 1526 | Line::from(vec![ |
| 1518 | 1527 | Span::raw(line::VERTICAL), |
| 1519 | Span::raw("}"), | |
| 1520 | Span::raw(" ".repeat(22)), | |
| 1528 | Span::styled("}", code_style), | |
| 1529 | Span::styled(" ".repeat(22), code_style), | |
| 1521 | 1530 | Span::raw(line::VERTICAL) |
| 1522 | 1531 | ]) |
| 1523 | 1532 | ); |
src/message/mod.rs +38 −20
| @@ -117,14 +117,6 @@ const fn span_static(s: &'static str) -> Span<'static> { | ||
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | const BOLD_STYLE: Style = Style { | |
| 121 | fg: None, | |
| 122 | bg: None, | |
| 123 | add_modifier: StyleModifier::BOLD, | |
| 124 | sub_modifier: StyleModifier::empty(), | |
| 125 | underline_color: None, | |
| 126 | }; | |
| 127 | ||
| 128 | 120 | const TIME_GUTTER: usize = 12; |
| 129 | 121 | const READ_GUTTER: usize = 5; |
| 130 | 122 | const MIN_MSG_LEN: usize = 30; |
| @@ -228,10 +220,10 @@ impl MessageTimeStamp { | ||
| 228 | 220 | dt1.date_naive() == dt2.date_naive() |
| 229 | 221 | } |
| 230 | 222 | |
| 231 | fn show_date(self) -> Span<'static> { | |
| 223 | fn show_date(self, settings: &ApplicationSettings) -> Span<'static> { | |
| 232 | 224 | let time = self.as_datetime().format("%A, %B %d %Y").to_string(); |
| 233 | 225 | |
| 234 | Span::styled(time, BOLD_STYLE) | |
| 226 | Span::styled(time, settings.theme.timeline.date.add_modifier(StyleModifier::BOLD)) | |
| 235 | 227 | } |
| 236 | 228 | |
| 237 | 229 | /// A compact date and time, for places without a date separator line. |
| @@ -239,11 +231,11 @@ impl MessageTimeStamp { | ||
| 239 | 231 | self.as_datetime().format("%Y-%m-%d %H:%M").to_string() |
| 240 | 232 | } |
| 241 | 233 | |
| 242 | fn show_time(self) -> Span<'static> { | |
| 234 | fn show_time(self, settings: &ApplicationSettings) -> Span<'static> { | |
| 243 | 235 | let time = self.as_datetime().format("%T"); |
| 244 | 236 | let time = format!(" [{time}]"); |
| 245 | 237 | |
| 246 | Span::raw(time) | |
| 238 | Span::styled(time, settings.theme.timeline.time) | |
| 247 | 239 | } |
| 248 | 240 | } |
| 249 | 241 | |
| @@ -492,6 +484,33 @@ impl MessageEvent { | ||
| 492 | 484 | self.msgtype().and_then(content_filename) |
| 493 | 485 | } |
| 494 | 486 | |
| 487 | fn message_style(&self, settings: &ApplicationSettings) -> Style { | |
| 488 | let content = match self { | |
| 489 | MessageEvent::EncryptedOriginal(_) | MessageEvent::EncryptedRedacted(_) => { | |
| 490 | return settings.theme.timeline.default; | |
| 491 | }, | |
| 492 | MessageEvent::Redacted(..) => return settings.theme.timeline.redacted, | |
| 493 | MessageEvent::State(_) => return settings.theme.timeline.state, | |
| 494 | MessageEvent::Original(ev, _) => &ev.content, | |
| 495 | MessageEvent::Local(_, _, content) => content, | |
| 496 | MessageEvent::Sticker(..) => return settings.theme.timeline.sticker, | |
| 497 | MessageEvent::Poll(..) | MessageEvent::UnstablePoll(..) => { | |
| 498 | return settings.theme.timeline.poll; | |
| 499 | }, | |
| 500 | }; | |
| 501 | ||
| 502 | match &content.msgtype { | |
| 503 | MessageType::Text(_) | | |
| 504 | MessageType::Audio(_) | | |
| 505 | MessageType::Emote(_) | | |
| 506 | MessageType::File(_) | | |
| 507 | MessageType::Image(_) | | |
| 508 | MessageType::Video(_) => settings.theme.messages.default, | |
| 509 | MessageType::Notice(_) | MessageType::ServerNotice(_) => settings.theme.timeline.notice, | |
| 510 | _ => settings.theme.messages.default, | |
| 511 | } | |
| 512 | } | |
| 513 | ||
| 495 | 514 | fn redact(&mut self, redaction: SyncRoomRedactionEvent) { |
| 496 | 515 | match self { |
| 497 | 516 | MessageEvent::EncryptedOriginal(_) => return, |
| @@ -819,7 +838,7 @@ impl<'a> MessageFormatter<'a> { | ||
| 819 | 838 | let reply_style = if settings.tunables.message_user_color { |
| 820 | 839 | style.patch(settings.get_user_color(&msg.sender)) |
| 821 | 840 | } else { |
| 822 | style | |
| 841 | style.patch(msg.event.message_style(settings)) | |
| 823 | 842 | }; |
| 824 | 843 | |
| 825 | 844 | let width = self.width(); |
| @@ -932,14 +951,13 @@ impl<'a> MessageFormatter<'a> { | ||
| 932 | 951 | protos |
| 933 | 952 | } |
| 934 | 953 | |
| 935 | fn push_thread_reply_count(&mut self, len: usize, text: &mut Text<'a>) { | |
| 954 | fn push_thread_reply_count(&mut self, len: usize, text: &mut Text<'a>, style: Style) { | |
| 936 | 955 | if len == 0 { |
| 937 | 956 | return; |
| 938 | 957 | } |
| 939 | 958 | |
| 940 | 959 | // If we have threaded replies to this message, show how many. |
| 941 | 960 | let plural = len != 1; |
| 942 | let style = Style::default(); | |
| 943 | 961 | let mut threaded = |
| 944 | 962 | printer::TextPrinter::new(self.width(), style, self.settings, self.info).literal(true); |
| 945 | 963 | let len = Span::styled(len.to_string(), style.add_modifier(StyleModifier::BOLD)); |
| @@ -1055,7 +1073,7 @@ impl Message { | ||
| 1055 | 1073 | } |
| 1056 | 1074 | |
| 1057 | 1075 | fn get_render_style(&self, selected: bool, settings: &ApplicationSettings) -> Style { |
| 1058 | let mut style = Style::default(); | |
| 1076 | let mut style = self.event.message_style(settings); | |
| 1059 | 1077 | |
| 1060 | 1078 | if selected { |
| 1061 | 1079 | style = style.add_modifier(StyleModifier::REVERSED) |
| @@ -1133,7 +1151,7 @@ impl Message { | ||
| 1133 | 1151 | settings: &'a ApplicationSettings, |
| 1134 | 1152 | ) -> MessageFormatter<'a> { |
| 1135 | 1153 | let orig = width; |
| 1136 | let date = self.show_date(prev).then(|| self.timestamp.show_date()); | |
| 1154 | let date = self.show_date(prev).then(|| self.timestamp.show_date(settings)); | |
| 1137 | 1155 | let trackbar = self.show_trackbar(prev, info, settings); |
| 1138 | 1156 | let user_gutter = settings.tunables.user_gutter_width; |
| 1139 | 1157 | |
| @@ -1143,7 +1161,7 @@ impl Message { | ||
| 1143 | 1161 | let cols = MessageColumns::Four; |
| 1144 | 1162 | let fill = width - user_gutter - TIME_GUTTER - READ_GUTTER; |
| 1145 | 1163 | let user = self.show_sender(prev, true, info, settings, width); |
| 1146 | let time = Some(self.timestamp.show_time()); | |
| 1164 | let time = Some(self.timestamp.show_time(settings)); | |
| 1147 | 1165 | |
| 1148 | 1166 | let read = self |
| 1149 | 1167 | .event |
| @@ -1176,7 +1194,7 @@ impl Message { | ||
| 1176 | 1194 | let cols = MessageColumns::Three; |
| 1177 | 1195 | let fill = width - user_gutter - TIME_GUTTER; |
| 1178 | 1196 | let user = self.show_sender(prev, true, info, settings, width); |
| 1179 | let time = Some(self.timestamp.show_time()); | |
| 1197 | let time = Some(self.timestamp.show_time(settings)); | |
| 1180 | 1198 | let read = Vec::new(); |
| 1181 | 1199 | |
| 1182 | 1200 | MessageFormatter { |
| @@ -1323,7 +1341,7 @@ impl Message { | ||
| 1323 | 1341 | } |
| 1324 | 1342 | |
| 1325 | 1343 | if let Some(thread) = self.event.event_id().and_then(|id| info.get_thread(Some(id))) { |
| 1326 | fmt.push_thread_reply_count(thread.len(), &mut text); | |
| 1344 | fmt.push_thread_reply_count(thread.len(), &mut text, style); | |
| 1327 | 1345 | } |
| 1328 | 1346 | |
| 1329 | 1347 | (text, protos) |
src/message/printer.rs +5
| @@ -69,6 +69,11 @@ impl<'a> TextPrinter<'a> { | ||
| 69 | 69 | self |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | /// Set the base style and return the old style. | |
| 73 | pub fn replace_base_style(&mut self, style: Style) -> Style { | |
| 74 | std::mem::replace(&mut self.base_style, style) | |
| 75 | } | |
| 76 | ||
| 72 | 77 | /// Indicates whether emojis should be replaced by shortcodes |
| 73 | 78 | pub fn emoji_shortcodes(&self) -> bool { |
| 74 | 79 | self.tunables().message_shortcode_display |
src/tests.rs +3 −1
| @@ -178,7 +178,7 @@ pub fn mock_tunables() -> TunableValues { | ||
| 178 | 178 | typing_notice_send: true, |
| 179 | 179 | typing_notice_display: true, |
| 180 | 180 | users: vec![(TEST_USER5.clone(), UserDisplayTunables { |
| 181 | color: Some(UserColor(Color::Black)), | |
| 181 | color: Some(Color::Black), | |
| 182 | 182 | name: Some("USER 5".into()), |
| 183 | 183 | })] |
| 184 | 184 | .into_iter() |
| @@ -224,12 +224,14 @@ pub fn mock_settings() -> ApplicationSettings { | ||
| 224 | 224 | layout: None, |
| 225 | 225 | macros: None, |
| 226 | 226 | aliases: None, |
| 227 | theme: None, | |
| 227 | 228 | }, |
| 228 | 229 | tunables: mock_tunables(), |
| 229 | 230 | dirs: mock_dirs(), |
| 230 | 231 | layout: Default::default(), |
| 231 | 232 | macros: HashMap::default(), |
| 232 | 233 | aliases: Aliases::default(), |
| 234 | theme: crate::config::theme::default_theme().values().into(), | |
| 233 | 235 | enable_enhanced_keys: false, |
| 234 | 236 | } |
| 235 | 237 | } |
src/windows/mod.rs +48 −42
| @@ -31,26 +31,21 @@ pub mod welcome; | ||
| 31 | 31 | const MEMBER_FETCH_DEBOUNCE: Duration = Duration::from_secs(5); |
| 32 | 32 | |
| 33 | 33 | #[inline] |
| 34 | fn bold_style() -> Style { | |
| 35 | Style::default().add_modifier(StyleModifier::BOLD) | |
| 34 | fn bold_span(s: &str, style: Style) -> Span<'_> { | |
| 35 | Span::styled(s, style.bold()) | |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | #[inline] |
| 39 | fn bold_span(s: &str) -> Span<'_> { | |
| 40 | Span::styled(s, bold_style()) | |
| 39 | fn bold_spans(s: &str, style: Style) -> Line<'_> { | |
| 40 | bold_span(s, style).into() | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | #[inline] |
| 44 | fn bold_spans(s: &str) -> Line<'_> { | |
| 45 | bold_span(s).into() | |
| 46 | } | |
| 47 | ||
| 48 | #[inline] | |
| 49 | pub fn selected_style(selected: bool) -> Style { | |
| 44 | pub fn selected_style(selected: bool, style: Style) -> Style { | |
| 50 | 45 | if selected { |
| 51 | Style::default().add_modifier(StyleModifier::REVERSED) | |
| 46 | style.add_modifier(StyleModifier::REVERSED) | |
| 52 | 47 | } else { |
| 53 | Style::default() | |
| 48 | style | |
| 54 | 49 | } |
| 55 | 50 | } |
| 56 | 51 | |
| @@ -409,8 +404,11 @@ impl IambWindow { | ||
| 409 | 404 | } |
| 410 | 405 | |
| 411 | 406 | pub type MemberListState = ListState<MemberItem, IambInfo>; |
| 407 | ||
| 412 | 408 | pub type PinnedListState = ListState<PinnedItem, IambInfo>; |
| 409 | ||
| 413 | 410 | pub type RoomListState = ListState<GenericRoomItem, IambInfo>; |
| 411 | ||
| 414 | 412 | pub type VerifyListState = ListState<VerifyItem, IambInfo>; |
| 415 | 413 | |
| 416 | 414 | impl From<RoomState> for IambWindow { |
| @@ -783,24 +781,25 @@ impl Window<IambInfo> for IambWindow { | ||
| 783 | 781 | } |
| 784 | 782 | |
| 785 | 783 | fn get_tab_title(&self, store: &mut ProgramStore) -> Line<'_> { |
| 784 | let style = Default::default(); | |
| 786 | 785 | match self { |
| 787 | IambWindow::DirectList(_) => bold_spans("Direct Messages"), | |
| 788 | IambWindow::RoomList(_) => bold_spans("Rooms"), | |
| 789 | IambWindow::SpaceList(_) => bold_spans("Spaces"), | |
| 790 | IambWindow::VerifyList(_) => bold_spans("Verifications"), | |
| 791 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb"), | |
| 792 | IambWindow::ChatList(_) => bold_spans("DMs & Rooms"), | |
| 793 | IambWindow::UnreadList(_) => bold_spans("Unread Messages"), | |
| 794 | IambWindow::MentionsList(_) => bold_spans("Unread Mentions"), | |
| 795 | IambWindow::InvitesList(_) => bold_spans("Open Invites"), | |
| 786 | IambWindow::DirectList(_) => bold_spans("Direct Messages", style), | |
| 787 | IambWindow::RoomList(_) => bold_spans("Rooms", style), | |
| 788 | IambWindow::SpaceList(_) => bold_spans("Spaces", style), | |
| 789 | IambWindow::VerifyList(_) => bold_spans("Verifications", style), | |
| 790 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb", style), | |
| 791 | IambWindow::ChatList(_) => bold_spans("DMs & Rooms", style), | |
| 792 | IambWindow::UnreadList(_) => bold_spans("Unread Messages", style), | |
| 793 | IambWindow::MentionsList(_) => bold_spans("Unread Mentions", style), | |
| 794 | IambWindow::InvitesList(_) => bold_spans("Open Invites", style), | |
| 796 | 795 | |
| 797 | 796 | IambWindow::Room(w) => w.get_tab_title(store), |
| 798 | 797 | IambWindow::MemberList(state, room_id, _) => { |
| 799 | 798 | let title = store.application.get_room_title(room_id.as_ref()); |
| 800 | 799 | let n = state.len(); |
| 801 | 800 | let v = vec![ |
| 802 | bold_span("Room Members "), | |
| 803 | Span::styled(format!("({n}): "), bold_style()), | |
| 801 | bold_span("Room Members ", style), | |
| 802 | Span::styled(format!("({n}): "), style.bold()), | |
| 804 | 803 | title.into(), |
| 805 | 804 | ]; |
| 806 | 805 | Line::from(v) |
| @@ -809,8 +808,8 @@ impl Window<IambInfo> for IambWindow { | ||
| 809 | 808 | let title = store.application.get_room_title(room_id.as_ref()); |
| 810 | 809 | let n = state.len(); |
| 811 | 810 | let v = vec![ |
| 812 | bold_span("Pinned Messages "), | |
| 813 | Span::styled(format!("({n}): "), bold_style()), | |
| 811 | bold_span("Pinned Messages ", style), | |
| 812 | Span::styled(format!("({n}): "), style.bold()), | |
| 814 | 813 | title.into(), |
| 815 | 814 | ]; |
| 816 | 815 | Line::from(v) |
| @@ -819,24 +818,25 @@ impl Window<IambInfo> for IambWindow { | ||
| 819 | 818 | } |
| 820 | 819 | |
| 821 | 820 | fn get_win_title(&self, store: &mut ProgramStore) -> Line<'_> { |
| 821 | let style = store.application.settings.theme.windows.title; | |
| 822 | 822 | match self { |
| 823 | IambWindow::DirectList(_) => bold_spans("Direct Messages"), | |
| 824 | IambWindow::RoomList(_) => bold_spans("Rooms"), | |
| 825 | IambWindow::SpaceList(_) => bold_spans("Spaces"), | |
| 826 | IambWindow::VerifyList(_) => bold_spans("Verifications"), | |
| 827 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb"), | |
| 828 | IambWindow::ChatList(_) => bold_spans("DMs & Rooms"), | |
| 829 | IambWindow::UnreadList(_) => bold_spans("Unread Messages"), | |
| 830 | IambWindow::MentionsList(_) => bold_spans("Unread Mentions"), | |
| 831 | IambWindow::InvitesList(_) => bold_spans("Open Invites"), | |
| 832 | ||
| 833 | IambWindow::Room(w) => w.get_title(store), | |
| 823 | IambWindow::DirectList(_) => bold_spans("Direct Messages", style), | |
| 824 | IambWindow::RoomList(_) => bold_spans("Rooms", style), | |
| 825 | IambWindow::SpaceList(_) => bold_spans("Spaces", style), | |
| 826 | IambWindow::VerifyList(_) => bold_spans("Verifications", style), | |
| 827 | IambWindow::Welcome(_) => bold_spans("Welcome to iamb", style), | |
| 828 | IambWindow::ChatList(_) => bold_spans("DMs & Rooms", style), | |
| 829 | IambWindow::UnreadList(_) => bold_spans("Unread Messages", style), | |
| 830 | IambWindow::MentionsList(_) => bold_spans("Unread Mentions", style), | |
| 831 | IambWindow::InvitesList(_) => bold_spans("Open Invites", style), | |
| 832 | ||
| 833 | IambWindow::Room(w) => w.get_title(store, style), | |
| 834 | 834 | IambWindow::MemberList(state, room_id, _) => { |
| 835 | 835 | let title = store.application.get_room_title(room_id.as_ref()); |
| 836 | 836 | let n = state.len(); |
| 837 | 837 | let v = vec![ |
| 838 | bold_span("Room Members "), | |
| 839 | Span::styled(format!("({n}): "), bold_style()), | |
| 838 | bold_span("Room Members ", style), | |
| 839 | Span::styled(format!("({n}): "), style.bold()), | |
| 840 | 840 | title.into(), |
| 841 | 841 | ]; |
| 842 | 842 | Line::from(v) |
| @@ -845,8 +845,8 @@ impl Window<IambInfo> for IambWindow { | ||
| 845 | 845 | let title = store.application.get_room_title(room_id.as_ref()); |
| 846 | 846 | let n = state.len(); |
| 847 | 847 | let v = vec![ |
| 848 | bold_span("Pinned Messages "), | |
| 849 | Span::styled(format!("({n}): "), bold_style()), | |
| 848 | bold_span("Pinned Messages ", style), | |
| 849 | Span::styled(format!("({n}): "), style.bold()), | |
| 850 | 850 | title.into(), |
| 851 | 851 | ]; |
| 852 | 852 | Line::from(v) |
| @@ -1084,9 +1084,15 @@ impl ListItem<IambInfo> for GenericRoomItem { | ||
| 1084 | 1084 | &self, |
| 1085 | 1085 | selected: bool, |
| 1086 | 1086 | _: &ViewportContext<ListCursor>, |
| 1087 | _: &mut ProgramStore, | |
| 1087 | store: &mut ProgramStore, | |
| 1088 | 1088 | ) -> Text<'_> { |
| 1089 | let style = selected_style(selected); | |
| 1089 | let style = if self.unread.is_unread() { | |
| 1090 | store.application.settings.theme.rooms.unread | |
| 1091 | } else { | |
| 1092 | store.application.settings.theme.rooms.default | |
| 1093 | }; | |
| 1094 | ||
| 1095 | let style = selected_style(selected, style); | |
| 1090 | 1096 | let (name, mut labels) = name_and_labels(&self.name, &self.unread, self.membership, style); |
| 1091 | 1097 | let mut spans = vec![name]; |
| 1092 | 1098 | |
src/windows/room/mod.rs +7 −7
| @@ -891,14 +891,14 @@ impl RoomState { | ||
| 891 | 891 | } |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | pub fn get_title(&self, store: &mut ProgramStore) -> Line<'_> { | |
| 894 | pub fn get_title(&self, store: &mut ProgramStore, style: Style) -> Line<'_> { | |
| 895 | 895 | let Some(room) = self.room() else { |
| 896 | 896 | return Line::from("Unjoined Room"); |
| 897 | 897 | }; |
| 898 | 898 | |
| 899 | 899 | let room_id = room.room_id(); |
| 900 | 900 | let title = store.application.get_room_title(room_id); |
| 901 | let style = Style::default().add_modifier(StyleModifier::BOLD); | |
| 901 | let bold_style = style.add_modifier(StyleModifier::BOLD); | |
| 902 | 902 | let mut spans = vec![]; |
| 903 | 903 | |
| 904 | 904 | let encryption_settings = &store.application.settings.tunables.encryption; |
| @@ -910,16 +910,16 @@ impl RoomState { | ||
| 910 | 910 | if let RoomState::Chat(chat) = self && |
| 911 | 911 | chat.thread().is_some() |
| 912 | 912 | { |
| 913 | spans.push("Thread in ".into()); | |
| 913 | spans.push(Span::styled("Thread in ", style)); | |
| 914 | 914 | } |
| 915 | 915 | |
| 916 | spans.push(Span::styled(title, style)); | |
| 916 | spans.push(Span::styled(title, bold_style)); | |
| 917 | 917 | |
| 918 | 918 | match room.topic() { |
| 919 | 919 | Some(desc) if !desc.is_empty() => { |
| 920 | spans.push(" (".into()); | |
| 921 | spans.push(desc.into()); | |
| 922 | spans.push(")".into()); | |
| 920 | spans.push(Span::styled(" (", style)); | |
| 921 | spans.push(Span::styled(desc, style)); | |
| 922 | spans.push(Span::styled(")", style)); | |
| 923 | 923 | }, |
| 924 | 924 | _ => { |
| 925 | 925 | spans.push(" ".into()); |
src/windows/verify.rs +5 −6
| @@ -140,9 +140,8 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 140 | 140 | store: &mut ProgramStore, |
| 141 | 141 | ) -> Text<'_> { |
| 142 | 142 | let mut lines = vec![]; |
| 143 | let bold = Style::default().add_modifier(StyleModifier::BOLD); | |
| 144 | let selected_bold = super::selected_style(selected).add_modifier(StyleModifier::BOLD); | |
| 145 | let selected = super::selected_style(selected); | |
| 143 | let bold = Style::default().bold(); | |
| 144 | let selected = super::selected_style(selected, Default::default()); | |
| 146 | 145 | |
| 147 | 146 | let mut other_device = None; |
| 148 | 147 | let state = match self.request.state() { |
| @@ -277,13 +276,13 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 277 | 276 | if let Some(display_name) = device.display_name() { |
| 278 | 277 | vec![ |
| 279 | 278 | Span::styled("Device verification with ", selected), |
| 280 | Span::styled(display_name.to_owned(), selected_bold), | |
| 279 | Span::styled(display_name.to_owned(), selected.bold()), | |
| 281 | 280 | Span::styled(format!(" ({state})"), selected), |
| 282 | 281 | ] |
| 283 | 282 | } else { |
| 284 | 283 | vec![ |
| 285 | 284 | Span::styled("Device verification with ", selected), |
| 286 | Span::styled(device.device_id().to_string(), selected_bold), | |
| 285 | Span::styled(device.device_id().to_string(), selected.bold()), | |
| 287 | 286 | Span::styled(format!(" ({state})"), selected), |
| 288 | 287 | ] |
| 289 | 288 | } |
| @@ -297,7 +296,7 @@ impl ListItem<IambInfo> for VerifyItem { | ||
| 297 | 296 | let color = store.application.settings.get_user_color(self.request.other_user_id()); |
| 298 | 297 | vec![ |
| 299 | 298 | Span::styled("User verification with ", selected), |
| 300 | Span::styled(self.request.other_user_id().as_str(), selected_bold.patch(color)), | |
| 299 | Span::styled(self.request.other_user_id().as_str(), selected.bold().patch(color)), | |
| 301 | 300 | Span::styled(format!(" ({state})"), selected), |
| 302 | 301 | ] |
| 303 | 302 | }; |