Skip to content

Commit

Permalink
[WIP] fix display of formatting issues when show_status_codes is false
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Oct 28, 2024
1 parent ec57887 commit 45b0aac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/effects/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn run(ctx: Context) -> Context {
let location = ui.instance_location(instance).dimmed();
let state = instance.state.borrow().clone();
let state_name = state.get_name();
let state_link = ui.status_code_link(&state_name);
let state_link = ui.instance_status_code_link(&state_name);
let state_link = format!("({state_link})").dimmed();

match state {
Expand Down
17 changes: 12 additions & 5 deletions src/effects/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'a> Ui<'a> {
})
.sorted()
.unique()
.map(|state_name| self.status_code_link(&state_name))
.map(|state_name| self.instance_status_code_link(&state_name))
.join(", ");
let state_links = if !state_links.is_empty() {
format!("({state_links})").dimmed()
Expand Down Expand Up @@ -263,7 +263,7 @@ impl<'a> Ui<'a> {
} else {
state_name.normal()
};
let state_link = self.status_code_link(&state_name);
let state_link = self.instance_status_code_link(&state_name);
let state_link = if !state_link.is_empty() {
format!("({state_link})").dimmed()
} else {
Expand Down Expand Up @@ -521,10 +521,17 @@ impl<'a> Ui<'a> {
format!("{plain_link}").normal()
}

pub fn status_code_link(&self, pascal_case: &str) -> ColoredString {
if !self.ctx.config.cli.options.show_status_codes {
return "".normal();
/// If enabled, render the reason code as a clickable link
pub fn instance_status_code_link(&self, pascal_case: &str) -> ColoredString {
if self.ctx.config.cli.options.show_status_codes {
self.status_code_link(pascal_case)
} else {
"".normal()
}
}

/// Render the reason code as a clickable link
fn status_code_link(&self, pascal_case: &str) -> ColoredString {
let base_url = "https://jamiemason.github.io/syncpack/guide/status-codes/";
let lower_case = pascal_case.to_lowercase();
let plain_link = self.link(format!("{base_url}#{lower_case}"), pascal_case);
Expand Down

0 comments on commit 45b0aac

Please sign in to comment.