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
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions src/alias_style.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use super::*;

#[derive(Debug, PartialEq, Clone, ValueEnum)]
pub(crate) enum AliasStyle {
Left,
Right,
Separate,
}
2 changes: 1 addition & 1 deletion src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<'run, 'src> Analyzer<'run, 'src> {
Rc::clone(next)
}),
}),
doc,
doc: doc.filter(|doc| !doc.is_empty()),
groups: groups.into(),
loaded: loaded.into(),
modules: self.modules,
Expand Down
126 changes: 65 additions & 61 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
}
Expand All @@ -69,6 +71,14 @@ impl Color {
self.restyle(Style::new().fg(Cyan))
}

fn effective_style(&self) -> Style {
if self.active() {
self.style
} else {
Style::new()
}
}

pub(crate) fn error(self) -> Self {
self.restyle(Style::new().fg(Red).bold())
}
Expand All @@ -77,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 {
Expand Down
16 changes: 16 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use {

#[derive(Debug, PartialEq)]
pub(crate) struct Config {
pub(crate) alias_style: AliasStyle,
pub(crate) allow_missing: bool,
pub(crate) check: bool,
pub(crate) color: Color,
Expand Down Expand Up @@ -86,6 +87,7 @@ mod cmd {
}

mod arg {
pub(crate) const ALIAS_STYLE: &str = "ALIAS_STYLE";
pub(crate) const ALLOW_MISSING: &str = "ALLOW-MISSING";
pub(crate) const ARGUMENTS: &str = "ARGUMENTS";
pub(crate) const CHECK: &str = "CHECK";
Expand Down Expand Up @@ -145,6 +147,16 @@ impl Config {
.usage(AnsiColor::Yellow.on_default() | Effects::BOLD)
.valid(AnsiColor::Green.on_default()),
)
.arg(
Arg::new(arg::ALIAS_STYLE)
.long("alias-style")
.env("JUST_ALIAS_STYLE")
.action(ArgAction::Set)
.value_parser(clap::value_parser!(AliasStyle))
.default_value("right")
.help("Set list command alias display style")
.conflicts_with(arg::NO_ALIASES),
)
.arg(
Arg::new(arg::CHECK)
.long("check")
Expand Down Expand Up @@ -739,6 +751,10 @@ impl Config {
let explain = matches.get_flag(arg::EXPLAIN);

Ok(Self {
alias_style: matches
.get_one::<AliasStyle>(arg::ALIAS_STYLE)
.unwrap()
.clone(),
allow_missing: matches.get_flag(arg::ALLOW_MISSING),
check: matches.get_flag(arg::CHECK),
color: (*matches.get_one::<UseColor>(arg::COLOR).unwrap()).into(),
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
pub(crate) use {
crate::{
alias::Alias,
alias_style::AliasStyle,
analyzer::Analyzer,
argument_parser::ArgumentParser,
assignment::Assignment,
Expand Down Expand Up @@ -179,6 +180,7 @@ pub mod summary;
pub mod request;

mod alias;
mod alias_style;
mod analyzer;
mod argument_parser;
mod assignment;
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ impl<'run, 'src> Parser<'run, 'src> {
attributes,
body,
dependencies,
doc,
doc: doc.filter(|doc| !doc.is_empty()),
file_depth: self.file_depth,
import_offsets: self.import_offsets.clone(),
name,
Expand Down
Loading
Loading