Move the hyperlink escape codes into a function

This commit is contained in:
Daan Boerlage 2025-01-21 22:22:43 +01:00
parent 054d66bf9c
commit 086dbb8af0
Signed by: daan
GPG key ID: FCE070E1E4956606
4 changed files with 13 additions and 6 deletions

View file

@ -1,5 +1,6 @@
use crate::cli::FormatMode; use crate::cli::FormatMode;
use crate::jira_config::JiraConfig; use crate::jira_config::JiraConfig;
use crate::term::hyperlink;
use crate::types::issue::JiraIssue; use crate::types::issue::JiraIssue;
use crossterm::style::{Color, Stylize}; use crossterm::style::{Color, Stylize};
use std::io::Write; use std::io::Write;
@ -99,9 +100,11 @@ fn pretty_print(issue: &JiraIssue) -> Result<(), Box<dyn std::error::Error>> {
} }
println!("\n== Actions {:=<69}", ""); println!("\n== Actions {:=<69}", "");
println!( println!(
"\u{1b}]8;;{}\u{7}{}\u{1b}]8;;\u{7}", "{}",
issue.href, hyperlink(
"Open Issue".green().underline(Color::Green) &issue.href,
&"Open Issue".green().underline(Color::Green).to_string()
)
); );
Ok(()) Ok(())

View file

@ -2,6 +2,7 @@ mod cli;
mod cmd; mod cmd;
mod jira_config; mod jira_config;
mod jql; mod jql;
mod term;
mod types; mod types;
use clap::Parser; use clap::Parser;

3
src/term.rs Normal file
View file

@ -0,0 +1,3 @@
pub fn hyperlink(url: &str, text: &str) -> String {
format!("\u{1b}]8;;{}\u{7}{}\u{1b}]8;;\u{7}", url, text)
}

View file

@ -1,3 +1,4 @@
use crate::term::hyperlink;
use crossterm::style::Stylize; use crossterm::style::Stylize;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::io::Write; use std::io::Write;
@ -107,9 +108,8 @@ pub fn display_issues_pretty(issues: &[JiraIssue]) -> Result<(), Box<dyn std::er
)?; )?;
writeln!( writeln!(
tw, tw,
"\u{1b}]8;;{}\u{7}{}\u{1b}]8;;\u{7}", "{}",
issue.href, &hyperlink(&issue.href, &"Open Issue".green().to_string())
"Open Issue".green()
)?; )?;
tw.flush().unwrap(); tw.flush().unwrap();