aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api
diff options
context:
space:
mode:
authorMark Grey <mark.asperia@gmail.com>2025-02-07 05:59:54 -0500
committerGitHub <noreply@github.com>2025-02-07 11:59:54 +0100
commit26b99eac63869fb1209ecf39c4f9cdb21d0419ba (patch)
tree4a12d05dc3eb55b651ea90888e56932b2fb3bd73 /zellij-utils/src/plugin_api
parentdocs(issue-template): clarify requirements (diff)
downloadsl0ppij-26b99eac63869fb1209ecf39c4f9cdb21d0419ba.tar.gz
sl0ppij-26b99eac63869fb1209ecf39c4f9cdb21d0419ba.tar.xz
sl0ppij-26b99eac63869fb1209ecf39c4f9cdb21d0419ba.zip
feat(config): new theme definition spec (#3242)
* Implement initial structs from spec * kdl configuration unmarshalling * typo text styling * remove is_selected toggle * incorporate new status bar ui into theming * improve test coverage of config behavior * tab bar correction * correct also compact bar * remove spacing between table columns * refactor table styling * use text_unselected.emphasis_1 for keygroup sep * fix tab bar more text * repair field flattening for theme * remove extra styling KDL node * update tests * updated selected text conversion * padding for header bar * minor corrections for existing themes * background handling * compact bar corrections * properly handle opaque method to activate background * update newer plugins to use styling struct * correct omission of selected state * fix: bold typeface for text elements * fix: fg -> white for list_unselected conversion * fix: emphasis and opacity handling for nested_list * correct stylings in the session-manager * fix emphases translation for table component * correct emphasis for run instructions * correct frame_highlight translation for old themes * provide missing implementation of frame_highlight * fencepost emphasis color names * Set a pseudo-None for frame_unselected in old theme conversion * correct alternating bg for simplified-ui * update snapshots * fix inner text padding and errorneous snapshots * suppress warning about deprecated usage of palette * remove unused import * feat(plugins): API to change floating pane coordinates (#3958) * basic functionality through the cli * added to plugin api * add display area and viewport size to TabInfo * fix tests and add new one * some cleanups * refactor: extract pane_id parsing logic * style(fmt): rustfmt * docs(changelog): floating pane coordinate chagne API * fix(tiled-panes): opening panes from the cli (#3963) * feat(plugins): add `PastedText` Event (#3962) * working with text paste * handle utf8 conversion error * feat(plugins): add PastedText Event * docs(changelog): plugins pasted text event * black for table opaque background * properly apply opacity to table * correct padding for explicit width ribbons * feat(plugins): Allow opening panes near plugin (#3966) * added command + terminal variants * added editor variant * style(fmt): rustfmt * docs(changelog): plugin apis to open panes near plugin * feat(plugins): send info about $EDITOR and $SHELL (#3971) * feat(plugins): send info about $EDITOR and $SHELL * fix(e2e): snapshot update * docs(changelog): plugin editor and shell info * fix(floating-panes): when changing coordinates, if a pane is not floating - make it floating (#3972) * fix(panes): when changing floating pane coordinates, if the pane is not floating, float it * style(fmt): rustfmt * docs(changelog): floating pane coordinate fix * fix(break-pane): strip logical position when inserting pane to new tab (#3973) * docs(changelog): logical position fix * Optional frame_unselected theme * fixture with correct width to account for arrow padding * update snapshot and rustfmt --------- Co-authored-by: Aram Drevekenin <aram@poor.dev>
Diffstat (limited to 'zellij-utils/src/plugin_api')
-rw-r--r--zellij-utils/src/plugin_api/event.rs4
-rw-r--r--zellij-utils/src/plugin_api/style.proto21
-rw-r--r--zellij-utils/src/plugin_api/style.rs175
3 files changed, 191 insertions, 9 deletions
diff --git a/zellij-utils/src/plugin_api/event.rs b/zellij-utils/src/plugin_api/event.rs
index 08db3d6e..df80e89d 100644
--- a/zellij-utils/src/plugin_api/event.rs
+++ b/zellij-utils/src/plugin_api/event.rs
@@ -1458,7 +1458,9 @@ fn serialize_mode_update_event_with_non_default_values() {
silver: PaletteColor::EightBit(2),
pink: PaletteColor::EightBit(2),
brown: PaletteColor::Rgb((222, 221, 220)),
- },
+ }
+ .into(),
+ // TODO: replace default
rounded_corners: true,
hide_session_name: false,
},
diff --git a/zellij-utils/src/plugin_api/style.proto b/zellij-utils/src/plugin_api/style.proto
index f4f3b758..cfea362e 100644
--- a/zellij-utils/src/plugin_api/style.proto
+++ b/zellij-utils/src/plugin_api/style.proto
@@ -3,9 +3,10 @@ syntax = "proto3";
package api.style;
message Style {
- Palette palette = 1;
+ Palette palette = 1 [deprecated = true];
bool rounded_corners = 2;
bool hide_session_name = 3;
+ Styling styling = 4;
}
message Palette {
@@ -52,3 +53,21 @@ enum ThemeHue {
Dark = 0;
Light = 1;
}
+
+message Styling {
+ repeated Color text_unselected = 1;
+ repeated Color text_selected = 2;
+ repeated Color ribbon_unselected = 3;
+ repeated Color ribbon_selected =4;
+ repeated Color table_title = 5;
+ repeated Color table_cell_unselected = 6;
+ repeated Color table_cell_selected = 7;
+ repeated Color list_unselected = 8;
+ repeated Color list_selected = 9;
+ repeated Color frame_unselected = 10;
+ repeated Color frame_selected = 11;
+ repeated Color frame_highlight = 12;
+ repeated Color exit_code_success = 13;
+ repeated Color exit_code_error = 14;
+ repeated Color multiplayer_user_colors = 15;
+}
diff --git a/zellij-utils/src/plugin_api/style.rs b/zellij-utils/src/plugin_api/style.rs
index 1e3ba677..eb9eebcf 100644
--- a/zellij-utils/src/plugin_api/style.rs
+++ b/zellij-utils/src/plugin_api/style.rs
@@ -1,9 +1,11 @@
use super::generated_api::api::style::{
color::Payload as ProtobufColorPayload, Color as ProtobufColor, ColorType as ProtobufColorType,
Palette as ProtobufPalette, RgbColorPayload as ProtobufRgbColorPayload, Style as ProtobufStyle,
- ThemeHue as ProtobufThemeHue,
+ Styling as ProtobufStyling, ThemeHue as ProtobufThemeHue,
+};
+use crate::data::{
+ MultiplayerColors, Palette, PaletteColor, Style, StyleDeclaration, Styling, ThemeHue,
};
-use crate::data::{Palette, PaletteColor, Style, ThemeHue};
use crate::errors::prelude::*;
use std::convert::TryFrom;
@@ -11,24 +13,183 @@ use std::convert::TryFrom;
impl TryFrom<ProtobufStyle> for Style {
type Error = &'static str;
fn try_from(protobuf_style: ProtobufStyle) -> Result<Self, &'static str> {
+ let s = protobuf_style
+ .styling
+ .ok_or("malformed style payload")?
+ .try_into()?;
Ok(Style {
- colors: protobuf_style
- .palette
- .ok_or("malformed style payload")?
- .try_into()?,
+ colors: s,
rounded_corners: protobuf_style.rounded_corners,
hide_session_name: protobuf_style.hide_session_name,
})
}
}
+#[allow(deprecated)]
impl TryFrom<Style> for ProtobufStyle {
type Error = &'static str;
fn try_from(style: Style) -> Result<Self, &'static str> {
+ let s = ProtobufStyling::try_from(style.colors)?;
+ let palette = Palette::try_from(style.colors).map_err(|_| "malformed style payload")?;
Ok(ProtobufStyle {
- palette: Some(style.colors.try_into()?),
+ palette: Some(palette.try_into()?),
rounded_corners: style.rounded_corners,
hide_session_name: style.hide_session_name,
+ styling: Some(s),
+ })
+ }
+}
+
+fn to_array<T, const N: usize>(v: Vec<T>) -> std::result::Result<[T; N], &'static str> {
+ v.try_into()
+ .map_err(|_| "Could not obtain array from protobuf field")
+}
+
+fn to_style_declaration(
+ parsed_array: Result<[PaletteColor; 6], &'static str>,
+) -> Result<StyleDeclaration, &'static str> {
+ parsed_array.map(|arr| StyleDeclaration {
+ base: arr[0],
+ background: arr[1],
+ emphasis_0: arr[2],
+ emphasis_1: arr[3],
+ emphasis_2: arr[4],
+ emphasis_3: arr[5],
+ })
+}
+
+fn to_multiplayer_colors(
+ parsed_array: Result<[PaletteColor; 10], &'static str>,
+) -> Result<MultiplayerColors, &'static str> {
+ parsed_array.map(|arr| MultiplayerColors {
+ player_1: arr[0],
+ player_2: arr[1],
+ player_3: arr[2],
+ player_4: arr[3],
+ player_5: arr[4],
+ player_6: arr[5],
+ player_7: arr[6],
+ player_8: arr[7],
+ player_9: arr[8],
+ player_10: arr[9],
+ })
+}
+
+#[macro_export]
+macro_rules! color_definitions {
+ ($proto:expr, $declaration:ident, $size:expr) => {
+ to_style_declaration(to_array::<PaletteColor, $size>(
+ $proto
+ .$declaration
+ .into_iter()
+ .map(PaletteColor::try_from)
+ .collect::<Result<Vec<PaletteColor>, _>>()?,
+ ))?
+ };
+}
+
+#[macro_export]
+macro_rules! multiplayer_colors {
+ ($proto:expr, $size: expr) => {
+ to_multiplayer_colors(to_array::<PaletteColor, $size>(
+ $proto
+ .multiplayer_user_colors
+ .into_iter()
+ .map(PaletteColor::try_from)
+ .collect::<Result<Vec<PaletteColor>, _>>()?,
+ ))?
+ };
+}
+
+impl TryFrom<ProtobufStyling> for Styling {
+ type Error = &'static str;
+
+ fn try_from(proto: ProtobufStyling) -> std::result::Result<Self, Self::Error> {
+ let frame_unselected = if proto.frame_unselected.len() > 0 {
+ Some(color_definitions!(proto, frame_unselected, 6))
+ } else {
+ None
+ };
+
+ Ok(Styling {
+ text_unselected: color_definitions!(proto, text_unselected, 6),
+ text_selected: color_definitions!(proto, text_selected, 6),
+ ribbon_unselected: color_definitions!(proto, ribbon_unselected, 6),
+ ribbon_selected: color_definitions!(proto, ribbon_selected, 6),
+ table_title: color_definitions!(proto, table_title, 6),
+ table_cell_unselected: color_definitions!(proto, table_cell_unselected, 6),
+ table_cell_selected: color_definitions!(proto, table_cell_selected, 6),
+ list_unselected: color_definitions!(proto, list_unselected, 6),
+ list_selected: color_definitions!(proto, list_selected, 6),
+ frame_unselected,
+ frame_selected: color_definitions!(proto, frame_selected, 6),
+ frame_highlight: color_definitions!(proto, frame_highlight, 6),
+ exit_code_success: color_definitions!(proto, exit_code_success, 6),
+ exit_code_error: color_definitions!(proto, exit_code_error, 6),
+ multiplayer_user_colors: multiplayer_colors!(proto, 10),
+ })
+ }
+}
+
+impl TryFrom<StyleDeclaration> for Vec<ProtobufColor> {
+ type Error = &'static str;
+
+ fn try_from(colors: StyleDeclaration) -> std::result::Result<Self, Self::Error> {
+ Ok(vec![
+ colors.base.try_into()?,
+ colors.background.try_into()?,
+ colors.emphasis_0.try_into()?,
+ colors.emphasis_1.try_into()?,
+ colors.emphasis_2.try_into()?,
+ colors.emphasis_3.try_into()?,
+ ])
+ }
+}
+
+impl TryFrom<MultiplayerColors> for Vec<ProtobufColor> {
+ type Error = &'static str;
+
+ fn try_from(value: MultiplayerColors) -> std::result::Result<Self, Self::Error> {
+ Ok(vec![
+ value.player_1.try_into()?,
+ value.player_2.try_into()?,
+ value.player_3.try_into()?,
+ value.player_4.try_into()?,
+ value.player_5.try_into()?,
+ value.player_6.try_into()?,
+ value.player_7.try_into()?,
+ value.player_8.try_into()?,
+ value.player_9.try_into()?,
+ value.player_10.try_into()?,
+ ])
+ }
+}
+
+impl TryFrom<Styling> for ProtobufStyling {
+ type Error = &'static str;
+
+ fn try_from(style: Styling) -> std::result::Result<Self, Self::Error> {
+ let frame_unselected_vec = match style.frame_unselected {
+ None => Ok(Vec::new()),
+ Some(frame_unselected) => frame_unselected.try_into(),
+ };
+
+ Ok(ProtobufStyling {
+ text_unselected: style.text_unselected.try_into()?,
+ text_selected: style.text_selected.try_into()?,
+ ribbon_unselected: style.ribbon_unselected.try_into()?,
+ ribbon_selected: style.ribbon_selected.try_into()?,
+ table_title: style.table_title.try_into()?,
+ table_cell_unselected: style.table_cell_unselected.try_into()?,
+ table_cell_selected: style.table_cell_selected.try_into()?,
+ list_unselected: style.list_unselected.try_into()?,
+ list_selected: style.list_selected.try_into()?,
+ frame_unselected: frame_unselected_vec?,
+ frame_selected: style.frame_selected.try_into()?,
+ frame_highlight: style.frame_highlight.try_into()?,
+ exit_code_success: style.exit_code_success.try_into()?,
+ exit_code_error: style.exit_code_error.try_into()?,
+ multiplayer_user_colors: style.multiplayer_user_colors.try_into()?,
})
}
}