aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jankowski <daniel.jankowski@rub.de>2023-09-24 11:06:01 +0200
committerDaniel Jankowski <daniel.jankowski@rub.de>2023-09-24 11:06:01 +0200
commit6bb55a7d5a5f2d57954b2b65eac9c62243e06b0d (patch)
tree59a6922992df3cff5cb0373cf8383d37d570b5f6
parentfix: clickable tabs when using index in template (diff)
downloadsl0pstatus-6bb55a7d5a5f2d57954b2b65eac9c62243e06b0d.tar.gz
sl0pstatus-6bb55a7d5a5f2d57954b2b65eac9c62243e06b0d.tar.xz
sl0pstatus-6bb55a7d5a5f2d57954b2b65eac9c62243e06b0d.zip
feat: use ansi colors by name
-rw-r--r--README.md17
-rw-r--r--plugin-dev-workspace.kdl6
-rw-r--r--src/render.rs20
3 files changed, 32 insertions, 11 deletions
diff --git a/README.md b/README.md
index 297980a..e7f3170 100644
--- a/README.md
+++ b/README.md
@@ -82,7 +82,7 @@ layout {
hide_frame_for_single_pane "true"
- mode_normal "#[bg=#89B4FA] "
+ mode_normal "#[bg=blue] "
mode_tmux "#[bg=#ffc387] "
tab_normal "#[fg=#6C7086] {name} "
@@ -112,12 +112,15 @@ Options can be combined with a `,`, when they occur in the same bracket.
Possible formatting options are:
-| name | value | example | description |
-|--------|-------------------|---------------|------------------|
-| fg | hex or ansi color | `#[fg=#ffffff]` | foreground color |
-| bg | hex or ansi color | `#[bg=#ffffff]` | background color |
-| bold | none | `#[bold]` | bold text |
-| italic | none | `#[italic]` | italic text |
+| name | value | example | description |
+|--------|---------------------------|---------------|------------------|
+| fg | hex or ansi color or name | `#[fg=#ffffff]` | foreground color |
+| bg | hex or ansi color or name | `#[bg=#ffffff]` | background color |
+| bold | none | `#[bold]` | bold text |
+| italic | none | `#[italic]` | italic text |
+
+Colors can be specified either by giving the hexadecimal rgb value or the ansi color (0..255). To simplify the specification
+by ansi color codes, the color name can also be used. They refer to the configured color in the terminal.
### 🧱 Widgets
diff --git a/plugin-dev-workspace.kdl b/plugin-dev-workspace.kdl
index 26a709d..2ac832c 100644
--- a/plugin-dev-workspace.kdl
+++ b/plugin-dev-workspace.kdl
@@ -11,10 +11,10 @@ layout {
hide_frame_for_single_pane "true"
- mode_normal "#[bg=#89B4FA] "
- mode_tmux "#[bg=#ffc387] "
+ mode_normal "#[bg=blue] "
+ mode_tmux "#[bg=yellow] "
- tab_normal "#[fg=#6C7086,bg=#181825] {name} "
+ tab_normal "#[fg=#6C7086,bg=#181825] {index} :: {name} "
tab_normal_fullscreen "#[fg=#6C7086,bg=#181825] {index} :: {name} [] "
tab_normal_sync "#[fg=#6C7086,bg=#181825] {index} :: {name} <> "
tab_active "#[fg=#9399B2,bg=#181825,bold,italic] {name} "
diff --git a/src/render.rs b/src/render.rs
index e6dfd66..976700e 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -1,6 +1,6 @@
use std::{collections::BTreeMap, sync::Arc};
-use anstyle::{Ansi256Color, Color, RgbColor, Style};
+use anstyle::{Ansi256Color, AnsiColor, Color, RgbColor, Style};
use zellij_tile::prelude::bail;
use crate::{widgets::widget::Widget, ZellijState};
@@ -150,6 +150,10 @@ fn parse_color(color: &str) -> Option<Color> {
);
}
+ if let Some(color) = color_by_name(color) {
+ return Some(color.into());
+ }
+
if let Ok(result) = color.parse::<u8>() {
return Some(Ansi256Color(result).into());
}
@@ -157,6 +161,20 @@ fn parse_color(color: &str) -> Option<Color> {
None
}
+fn color_by_name(color: &str) -> Option<AnsiColor> {
+ match color {
+ "black" => Some(AnsiColor::Black),
+ "red" => Some(AnsiColor::Red),
+ "green" => Some(AnsiColor::Green),
+ "yellow" => Some(AnsiColor::Yellow),
+ "blue" => Some(AnsiColor::Blue),
+ "magenta" => Some(AnsiColor::Magenta),
+ "cyan" => Some(AnsiColor::Cyan),
+ "white" => Some(AnsiColor::White),
+ _ => None,
+ }
+}
+
#[cfg(test)]
mod test {
use super::*;