diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-09-10 09:38:48 +0200 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-09-10 09:38:48 +0200 |
| commit | f19f3412dd7d3f1d6ed645cf78bf215a24cbab09 (patch) | |
| tree | 0f7ecb0c7a3858bd19f88fbd6432719c92b081d8 | |
| parent | chore: add documentation how to install with nix (diff) | |
| download | sl0pstatus-f19f3412dd7d3f1d6ed645cf78bf215a24cbab09.tar.gz sl0pstatus-f19f3412dd7d3f1d6ed645cf78bf215a24cbab09.tar.xz sl0pstatus-f19f3412dd7d3f1d6ed645cf78bf215a24cbab09.zip | |
chore: move from unmaintained ansi_term to anstyle
Diffstat (limited to '')
| -rw-r--r-- | Cargo.lock | 11 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | plugin-dev-workspace.kdl | 8 | ||||
| -rw-r--r-- | src/config.rs | 6 | ||||
| -rw-r--r-- | src/render.rs | 57 |
5 files changed, 46 insertions, 38 deletions
@@ -42,13 +42,10 @@ dependencies = [ ] [[package]] -name = "ansi_term" -version = "0.12.1" +name = "anstyle" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] +checksum = "15c4c2c83f81532e5845a733998b6971faca23490340a418e9b72a3ec9de12ea" [[package]] name = "anyhow" @@ -2848,7 +2845,7 @@ dependencies = [ name = "zjstatus" version = "0.4.0" dependencies = [ - "ansi_term", + "anstyle", "anyhow", "chrono", "chrono-tz", @@ -5,10 +5,10 @@ authors = ["Daniel Jankowski"] edition = "2018" [dependencies] -ansi_term = "0.12.1" zellij-tile = "0.38.0" chrono = "0.4.0" regex = "1.9.4" strip-ansi-escapes = "0.2.0" chrono-tz = "0.8.3" anyhow = "1.0.75" +anstyle = "1.0.2" diff --git a/plugin-dev-workspace.kdl b/plugin-dev-workspace.kdl index e2e970e..459a6cb 100644 --- a/plugin-dev-workspace.kdl +++ b/plugin-dev-workspace.kdl @@ -5,7 +5,7 @@ layout { pane size=1 borderless=true { plugin location="file:target/wasm32-wasi/debug/zjstatus.wasm" { - format_left "{mode} #[fg=#89B4FA,bold]{session} {tabs}" + format_left "{mode} #[fg=#89B4FA,bg=#181825,bold]{session} {tabs}" format_right "{datetime}" format_space "#[bg=#181825]" @@ -14,10 +14,10 @@ layout { mode_normal "#[bg=#89B4FA] " mode_tmux "#[bg=#ffc387] " - tab_normal "#[fg=#6C7086] {name} " - tab_active "#[fg=#9399B2,bold,italic] {name} " + tab_normal "#[fg=#6C7086,bg=#181825] {name} " + tab_active "#[fg=#9399B2,bg=#181825,bold,italic] {name} " - datetime "#[fg=#6C7086,bold] {format} " + datetime "#[fg=#6C7086,bg=#181825,bold] {format} " datetime_format "%A, %d %b %Y %H:%M" datetime_timezone "Europe/Berlin" } diff --git a/src/config.rs b/src/config.rs index ce8b4b2..b0c6f69 100644 --- a/src/config.rs +++ b/src/config.rs @@ -222,7 +222,7 @@ fn parts_from_config(format: Option<&String>) -> Vec<FormattedPart> { #[cfg(test)] mod test { use super::*; - use ansi_term::Colour; + use anstyle::RgbColor; #[test] fn test_formatted_part_from_string() { @@ -233,8 +233,8 @@ mod test { assert_eq!( part, FormattedPart { - fg: Some(Colour::RGB(255, 0, 0)), - bg: Some(Colour::RGB(0, 255, 0)), + fg: Some(RgbColor(255, 0, 0).into()), + bg: Some(RgbColor(0, 255, 0).into()), bold: true, italic: true, content: "foo".to_string(), diff --git a/src/render.rs b/src/render.rs index 1be4b91..e6dfd66 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,14 +1,14 @@ use std::{collections::BTreeMap, sync::Arc}; -use ansi_term::{Colour, Colour::Fixed, Colour::RGB, Style}; +use anstyle::{Ansi256Color, Color, RgbColor, Style}; use zellij_tile::prelude::bail; use crate::{widgets::widget::Widget, ZellijState}; #[derive(Clone, Debug, PartialEq)] pub struct FormattedPart { - pub fg: Option<Colour>, - pub bg: Option<Colour>, + pub fg: Option<Color>, + pub bg: Option<Color>, pub bold: bool, pub italic: bool, pub content: String, @@ -58,18 +58,26 @@ impl FormattedPart { } pub fn format_string(&self, text: String) -> String { - let mut style = match self.fg { - Some(color) => Style::new().fg(color), - None => Style::new(), - }; + let mut style = Style::new(); - style.background = self.bg; - style.is_italic = self.italic; - style.is_bold = self.bold; + style = style.fg_color(self.fg); + style = style.bg_color(self.bg); - let style = style.paint(text); + if self.italic { + style = style.italic(); + } + + if self.bold { + style = style.bold(); + } - format!("{}", style) + format!( + "{}{}{}{}", + style.render_reset(), + style.render(), + text, + style.render_reset() + ) } pub fn format_string_with_widgets( @@ -120,7 +128,7 @@ fn hex_to_rgb(s: &str) -> anyhow::Result<Vec<u8>> { .collect() } -fn parse_color(color: &str) -> Option<Colour> { +fn parse_color(color: &str) -> Option<Color> { if color.starts_with('#') { let rgb = hex_to_rgb(color.strip_prefix('#').unwrap()); if rgb.is_err() { @@ -132,15 +140,18 @@ fn parse_color(color: &str) -> Option<Colour> { return None; } - return Some(RGB( - *rgb.first().unwrap(), - *rgb.get(1).unwrap(), - *rgb.get(2).unwrap(), - )); + return Some( + RgbColor( + *rgb.first().unwrap(), + *rgb.get(1).unwrap(), + *rgb.get(2).unwrap(), + ) + .into(), + ); } if let Ok(result) = color.parse::<u8>() { - return Some(Fixed(result)); + return Some(Ansi256Color(result).into()); } None @@ -173,12 +184,12 @@ mod test { #[test] fn test_parse_color() { let result = parse_color("#010203"); - let expected = Colour::RGB(1, 2, 3); - assert_eq!(result, Some(expected)); + let expected = RgbColor(1, 2, 3); + assert_eq!(result, Some(expected.into())); let result = parse_color("255"); - let expected = Colour::Fixed(255); - assert_eq!(result, Some(expected)); + let expected = Ansi256Color(255); + assert_eq!(result, Some(expected.into())); let result = parse_color("365"); assert_eq!(result, None); |
