Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display recipe aliases inline with the recipe doc #2342

Merged
merged 30 commits into from
Dec 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
511c8fe
Condense aliases into the recipe doc
marcaddeo Sep 3, 2024
70da034
Fix clippy errors
marcaddeo Sep 3, 2024
d316092
Paint aliases in --list purple
marcaddeo Sep 7, 2024
381a13c
Use unwrap_or_default
marcaddeo Sep 12, 2024
63671cf
Add --no-inline-aliases option
marcaddeo Sep 12, 2024
fa06fff
Use a Vec for aliases in format_doc instead of Option<Vec>
marcaddeo Sep 25, 2024
136fdb8
Fix clippy lint
marcaddeo Sep 25, 2024
3c8e130
Alter the iterator instead of multiple conditionals
marcaddeo Sep 25, 2024
a4c1b68
Convert test format
marcaddeo Sep 25, 2024
031d546
Add test for --no-inline-aliases
marcaddeo Sep 25, 2024
663289f
Move NO_INLINE_ALIASES to be in alpha order, and make it conflict wit…
marcaddeo Sep 25, 2024
5d97d86
Add --inline-aliases-left flag to display aliases to the left of the doc
marcaddeo Sep 25, 2024
040d0ea
Fix clippy error
marcaddeo Sep 25, 2024
04a854e
Switch to --alias-style flag
marcaddeo Oct 8, 2024
b199d57
Clean up backtick/doc coloring code
marcaddeo Dec 12, 2024
b9abcbd
Avoid Vec::new()
casey Dec 12, 2024
0b518b2
Tweak help text
casey Dec 12, 2024
7df991d
Sort color functions
casey Dec 12, 2024
faf4ae4
Modify
casey Dec 12, 2024
918cc2b
Tweak tests
casey Dec 12, 2024
952c952
Add default and multiple tests
casey Dec 12, 2024
9cfb270
Revise
casey Dec 12, 2024
ae8ebab
Fix tests
casey Dec 12, 2024
eb3d68a
Revise
casey Dec 12, 2024
29737ca
Use color variable
casey Dec 12, 2024
832c425
More tweaks
casey Dec 12, 2024
79bc981
More ocd tweaking
casey Dec 12, 2024
2d42e8d
Merge branch 'master' into condense-aliases-in-list-command
casey Dec 12, 2024
6aa6e12
Merge branch 'master' into condense-aliases-in-list-command
casey Dec 12, 2024
8e61c03
Tweak names
casey Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Sort color functions
casey committed Dec 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 7df991d000a0703449343a5f56afc22ee79738e9
126 changes: 63 additions & 63 deletions src/color.rs
Original file line number Diff line number Diff line change
@@ -12,27 +12,16 @@ pub(crate) struct Color {
}

impl Color {
fn restyle(self, style: Style) -> Self {
Self { style, ..self }
}

fn redirect(self, stream: impl IsTerminal) -> Self {
Self {
is_terminal: stream.is_terminal(),
..self
}
}

fn effective_style(&self) -> Style {
if self.active() {
self.style
} else {
Style::new()
pub(crate) fn active(&self) -> bool {
match self.use_color {
UseColor::Always => true,
UseColor::Never => false,
UseColor::Auto => self.is_terminal,
}
}

pub(crate) fn auto() -> Self {
Self::default()
pub(crate) fn alias(self) -> Self {
self.restyle(Style::new().fg(Purple))
}

pub(crate) fn always() -> Self {
@@ -42,25 +31,38 @@ impl Color {
}
}

pub(crate) fn never() -> Self {
Self {
use_color: UseColor::Never,
..Self::default()
}
pub(crate) fn annotation(self) -> Self {
self.restyle(Style::new().fg(Purple))
}

pub(crate) fn stderr(self) -> Self {
self.redirect(io::stderr())
pub(crate) fn auto() -> Self {
Self::default()
}

pub(crate) fn stdout(self) -> Self {
self.redirect(io::stdout())
pub(crate) fn banner(self) -> Self {
self.restyle(Style::new().fg(Cyan).bold())
}

pub(crate) fn command(self, foreground: Option<ansi_term::Color>) -> Self {
self.restyle(Style {
foreground,
is_bold: true,
..Style::default()
})
}

pub(crate) fn context(self) -> Self {
self.restyle(Style::new().fg(Blue).bold())
}

pub(crate) fn diff_added(self) -> Self {
self.restyle(Style::new().fg(Green))
}

pub(crate) fn diff_deleted(self) -> Self {
self.restyle(Style::new().fg(Red))
}

pub(crate) fn doc(self) -> Self {
self.restyle(Style::new().fg(Blue))
}
@@ -69,8 +71,12 @@ impl Color {
self.restyle(Style::new().fg(Cyan))
}

pub(crate) fn alias(self) -> Self {
self.restyle(Style::new().fg(Purple))
fn effective_style(&self) -> Style {
if self.active() {
self.style
} else {
Style::new()
}
}

pub(crate) fn error(self) -> Self {
@@ -81,65 +87,59 @@ impl Color {
self.restyle(Style::new().fg(Yellow).bold())
}

pub(crate) fn warning(self) -> Self {
self.restyle(Style::new().fg(Yellow).bold())
pub(crate) fn message(self) -> Self {
self.restyle(Style::new().bold())
}

pub(crate) fn banner(self) -> Self {
self.restyle(Style::new().fg(Cyan).bold())
pub(crate) fn never() -> Self {
Self {
use_color: UseColor::Never,
..Self::default()
}
}

pub(crate) fn command(self, foreground: Option<ansi_term::Color>) -> Self {
self.restyle(Style {
foreground,
is_bold: true,
..Style::default()
})
pub(crate) fn paint<'a>(&self, text: &'a str) -> ANSIGenericString<'a, str> {
self.effective_style().paint(text)
}

pub(crate) fn parameter(self) -> Self {
self.restyle(Style::new().fg(Cyan))
}

pub(crate) fn message(self) -> Self {
self.restyle(Style::new().bold())
}

pub(crate) fn annotation(self) -> Self {
self.restyle(Style::new().fg(Purple))
}

pub(crate) fn string(self) -> Self {
self.restyle(Style::new().fg(Green))
pub(crate) fn prefix(&self) -> Prefix {
self.effective_style().prefix()
}

pub(crate) fn diff_added(self) -> Self {
self.restyle(Style::new().fg(Green))
fn redirect(self, stream: impl IsTerminal) -> Self {
Self {
is_terminal: stream.is_terminal(),
..self
}
}

pub(crate) fn diff_deleted(self) -> Self {
self.restyle(Style::new().fg(Red))
fn restyle(self, style: Style) -> Self {
Self { style, ..self }
}

pub(crate) fn active(&self) -> bool {
match self.use_color {
UseColor::Always => true,
UseColor::Never => false,
UseColor::Auto => self.is_terminal,
}
pub(crate) fn stderr(self) -> Self {
self.redirect(io::stderr())
}

pub(crate) fn paint<'a>(&self, text: &'a str) -> ANSIGenericString<'a, str> {
self.effective_style().paint(text)
pub(crate) fn stdout(self) -> Self {
self.redirect(io::stdout())
}

pub(crate) fn prefix(&self) -> Prefix {
self.effective_style().prefix()
pub(crate) fn string(self) -> Self {
self.restyle(Style::new().fg(Green))
}

pub(crate) fn suffix(&self) -> Suffix {
self.effective_style().suffix()
}

pub(crate) fn warning(self) -> Self {
self.restyle(Style::new().fg(Yellow).bold())
}
}

impl From<UseColor> for Color {