Skip to content

Commit

Permalink
fix: Some UI fixes/improvements. (#119)
Browse files Browse the repository at this point in the history
* Add tag.

* Update deps.
  • Loading branch information
milesj authored Dec 27, 2024
1 parent e33246f commit b101098
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 57 deletions.
60 changes: 40 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ members = ["crates/*", "examples/*"]
async-trait = "0.1.83"
crossterm = "0.28.1"
dirs = "5.0.1"
iocraft = "0.5.1"
iocraft = "0.5.2"
# iocraft = { git = "https://github.com/ccbrown/iocraft", branch = "main" }
miette = "7.4.0"
regex = { version = "1.11.1", default-features = false }
relative-path = "1.9.3"
reqwest = { version = "0.12.9", default-features = false }
reqwest = { version = "0.12.10", default-features = false }
rustc-hash = "2.1.0"
serial_test = "3.2.0"
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.133"
serde_json = "1.0.134"
serde_yaml = "0.9.34"
thiserror = "2.0.8"
thiserror = "2.0.9"
tokio = { version = "1.42.0", default-features = false, features = [
"io-util",
"rt",
Expand Down
1 change: 1 addition & 0 deletions crates/console/src/components/input_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn InputField<'a>(props: &mut InputFieldProps<'a>, hooks: Hooks) -> impl Int
border_edges: Edges::Left,
border_style: BorderStyle::Round,
padding_left: 1,
margin_top: 1,
) {
StyledText(
content: &props.label,
Expand Down
29 changes: 3 additions & 26 deletions crates/console/src/components/styled_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ pub fn StyledText<'a>(props: &StyledTextProps, hooks: Hooks) -> impl Into<AnyEle
element! {
Text(
color: if theme.supports_color {
tag.and_then(tag_to_style)
.or(props.style)
.map(|style| theme.style(style))
tag.as_ref()
.and_then(|tag| theme.tag_to_color(tag))
.or_else(|| props.style.as_ref().and_then(|style| theme.style_to_color(style)))
.or(props.color)
} else {
None
Expand All @@ -48,26 +48,3 @@ pub fn StyledText<'a>(props: &StyledTextProps, hooks: Hooks) -> impl Into<AnyEle
}
}
}

fn tag_to_style(tag: String) -> Option<Style> {
let style = match tag.as_str() {
"caution" => Style::Caution,
"failure" => Style::Failure,
"invalid" => Style::Invalid,
"muted" => Style::Muted,
"mutedlight" | "muted_light" => Style::MutedLight,
"success" => Style::Success,
"file" => Style::File,
"hash" | "version" => Style::Hash,
"id" => Style::Id,
"label" => Style::Label,
"path" => Style::Path,
"property" => Style::Property,
"shell" => Style::Shell,
"symbol" => Style::Symbol,
"url" => Style::Url,
_ => return None,
};

Some(style)
}
4 changes: 2 additions & 2 deletions crates/console/src/components/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ pub fn TableCol<'a>(props: &mut TableColProps<'a>, hooks: Hooks) -> impl Into<An
element! {
Box(
justify_content: align_to_justify(attrs.align),
padding_left: 1,
// padding_right: 1,
margin_left: 1,
margin_right: 1,
width: attrs.width,
) {
#(&mut props.children)
Expand Down
37 changes: 33 additions & 4 deletions crates/console/src/theme.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::ui::style_to_color;
use iocraft::Color;
use starbase_styles::{color::Color as NativeColor, Style};
use std::collections::HashMap;

// https://www.ditig.com/publications/256-colors-cheat-sheet
#[derive(Clone, Debug)]
pub struct ConsoleTheme {
pub supports_color: bool,
pub brand_color: Color,

// Backgrounds
Expand Down Expand Up @@ -60,6 +60,10 @@ pub struct ConsoleTheme {
pub style_shell_color: Color,
pub style_symbol_color: Color,
pub style_url_color: Color,

// Misc
pub supports_color: bool,
pub custom_tags: HashMap<String, Color>,
}

impl Default for ConsoleTheme {
Expand Down Expand Up @@ -104,6 +108,7 @@ impl Default for ConsoleTheme {
style_symbol_color: style_to_color(Style::Symbol),
style_url_color: style_to_color(Style::Url),
supports_color: true,
custom_tags: HashMap::new(),
}
}
}
Expand All @@ -119,8 +124,8 @@ impl ConsoleTheme {
}
}

pub fn style(&self, style: Style) -> Color {
match style {
pub fn style_to_color(&self, style: &Style) -> Option<Color> {
let color = match style {
Style::Caution => self.style_caution_color,
Style::Failure => self.style_failure_color,
Style::Invalid => self.style_invalid_color,
Expand All @@ -136,7 +141,31 @@ impl ConsoleTheme {
Style::Shell => self.style_shell_color,
Style::Symbol => self.style_symbol_color,
Style::Url => self.style_url_color,
}
Style::Tag(tag) => return self.custom_tags.get(tag).cloned(),
};

Some(color)
}

pub fn tag_to_color(&self, tag: &str) -> Option<Color> {
self.style_to_color(&match tag {
"caution" => Style::Caution,
"failure" => Style::Failure,
"invalid" => Style::Invalid,
"muted" => Style::Muted,
"mutedlight" => Style::MutedLight,
"success" => Style::Success,
"file" => Style::File,
"hash" => Style::Hash,
"id" => Style::Id,
"label" => Style::Label,
"path" => Style::Path,
"property" => Style::Property,
"shell" => Style::Shell,
"symbol" => Style::Symbol,
"url" => Style::Url,
tag => Style::Tag(tag.to_owned()),
})
}

pub fn variant(&self, variant: Variant) -> Color {
Expand Down
5 changes: 4 additions & 1 deletion crates/styles/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ pub enum Color {
GrayLight = 246,
}

#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum Style {
Tag(String),

// States
Caution,
Failure,
Expand Down Expand Up @@ -70,6 +72,7 @@ impl Style {
Style::Shell => Color::Pink,
Style::Symbol => Color::Lime,
Style::Url => Color::Blue,
Style::Tag(_) => Color::White,
}
}
}
Expand Down

0 comments on commit b101098

Please sign in to comment.