Skip to content

Commit

Permalink
feat: use prettier cursor for select
Browse files Browse the repository at this point in the history
any thoughts @roele? particularly on naming
  • Loading branch information
jdx committed Dec 18, 2024
1 parent f8536fe commit 5d285c2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ for i in $(ls -1 assets/themes/*.tape); do
done
"""

[tasks.tests]
[tasks.test]
alias = ["t", "tests"]
depends = ["lint"]
description = "Run tests"
run = "cargo test --lib --tests"
Expand Down
2 changes: 1 addition & 1 deletion src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{theme, Theme};
///
/// # Example
/// ```rust
/// use demand::{DmandOption, List};
/// use demand::{DemandOption, List};
///
/// let list = List::new("Toppings")
/// .description("Select your toppings")
Expand Down
12 changes: 8 additions & 4 deletions src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,13 @@ impl<'a, T> Select<'a, T> {
for (i, option) in self.visible_options().iter().enumerate() {
if self.cursor_y == i {
out.set_color(&self.theme.cursor)?;
write!(out, ">")?;
write!(out, "{}", self.theme.cursor_str)?;
} else {
write!(out, " ")?;
write!(
out,
"{}",
" ".repeat(console::measure_text_width(&self.theme.cursor_str))
)?;
}
out.set_color(&self.theme.unselected_option)?;
if let Some(desc) = &option.description {
Expand Down Expand Up @@ -491,7 +495,7 @@ mod tests {
indoc! {
"Country
Select your Country
> United States
United States
Germany
Brazil
Canada
Expand Down Expand Up @@ -536,7 +540,7 @@ mod tests {
indoc! {
"things
pick a thing
> First
First
2
↑/↓/k/j up/down • enter confirm
"
Expand Down
7 changes: 7 additions & 0 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub struct Theme {
pub description: ColorSpec,
/// Cursor color
pub cursor: ColorSpec,
/// Cursor string e.g. "❯ "
pub cursor_str: String,

/// Selected option color
pub selected_option: ColorSpec,
Expand Down Expand Up @@ -96,6 +98,7 @@ impl Theme {
error_indicator: ColorSpec::new(),
description: ColorSpec::new(),
cursor: ColorSpec::new(),
cursor_str: String::from("❯"),
selected_prefix: String::from("[•]"),
selected_prefix_fg: ColorSpec::new(),
selected_option: ColorSpec::new(),
Expand Down Expand Up @@ -172,6 +175,7 @@ impl Theme {
error_indicator: make_color(red),
description: make_color(Color::Ansi256(243)),
cursor: make_color(fuchsia),
cursor_str: String::from("❯"),

selected_prefix: String::from(" ✓"),
selected_prefix_fg: make_color(Color::Rgb(2, 168, 119)),
Expand Down Expand Up @@ -228,6 +232,7 @@ impl Theme {
error_indicator: make_color(red),
description: make_color(comment),
cursor: make_color(yellow),
cursor_str: String::from("❯"),

selected_prefix: String::from(" [•]"),
selected_prefix_fg: make_color(green),
Expand Down Expand Up @@ -276,6 +281,7 @@ impl Theme {
error_indicator: make_color(Color::Ansi256(9)),
description: make_color(Color::Ansi256(8)),
cursor: make_color(Color::Ansi256(3)),
cursor_str: String::from("❯"),

selected_prefix: String::from(" [•]"),
selected_prefix_fg: make_color(Color::Ansi256(2)),
Expand Down Expand Up @@ -335,6 +341,7 @@ impl Theme {
error_indicator: make_color(red),
description: make_color(subtext0),
cursor: make_color(pink),
cursor_str: String::from("❯"),

selected_prefix: String::from(" [•]"),
selected_prefix_fg: make_color(green),
Expand Down

0 comments on commit 5d285c2

Please sign in to comment.