mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-10 12:09:33 +01:00
skip markdown handling for non-fancy output
This commit is contained in:
parent
8bd72dd59c
commit
45e3565a9d
3 changed files with 28 additions and 16 deletions
34
src/main.rs
34
src/main.rs
|
@ -167,7 +167,7 @@ enum Style {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SpecialRender {
|
struct SpecialRender {
|
||||||
colors: bool,
|
fancy: bool,
|
||||||
|
|
||||||
dash: char,
|
dash: char,
|
||||||
bullet: char,
|
bullet: char,
|
||||||
|
@ -219,7 +219,7 @@ impl SpecialRender {
|
||||||
|
|
||||||
fn fancy() -> Self {
|
fn fancy() -> Self {
|
||||||
Self {
|
Self {
|
||||||
colors: true,
|
fancy: true,
|
||||||
|
|
||||||
dash: '—',
|
dash: '—',
|
||||||
bullet: '•',
|
bullet: '•',
|
||||||
|
@ -262,7 +262,7 @@ impl SpecialRender {
|
||||||
|
|
||||||
fn minimal() -> Self {
|
fn minimal() -> Self {
|
||||||
Self {
|
Self {
|
||||||
colors: false,
|
fancy: false,
|
||||||
|
|
||||||
dash: '-',
|
dash: '-',
|
||||||
bullet: '-',
|
bullet: '-',
|
||||||
|
@ -305,6 +305,26 @@ impl SpecialRender {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn markdown(text: &str) -> String {
|
fn markdown(text: &str) -> String {
|
||||||
|
let SpecialRender {
|
||||||
|
fancy,
|
||||||
|
|
||||||
|
bullet,
|
||||||
|
horiz_rule,
|
||||||
|
bright_blue,
|
||||||
|
dark_grey_bg,
|
||||||
|
body_prefix,
|
||||||
|
..
|
||||||
|
} = *special_render();
|
||||||
|
|
||||||
|
if !fancy {
|
||||||
|
let mut out = String::new();
|
||||||
|
for line in text.lines() {
|
||||||
|
use std::fmt::Write;
|
||||||
|
let _ = writeln!(&mut out, "{body_prefix} {line}");
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
let arena = comrak::Arena::new();
|
let arena = comrak::Arena::new();
|
||||||
let mut options = comrak::Options::default();
|
let mut options = comrak::Options::default();
|
||||||
options.extension.strikethrough = true;
|
options.extension.strikethrough = true;
|
||||||
|
@ -328,14 +348,6 @@ fn markdown(text: &str) -> String {
|
||||||
render_queue.push((node, side));
|
render_queue.push((node, side));
|
||||||
}
|
}
|
||||||
|
|
||||||
let SpecialRender {
|
|
||||||
bullet,
|
|
||||||
horiz_rule,
|
|
||||||
bright_blue,
|
|
||||||
dark_grey_bg,
|
|
||||||
..
|
|
||||||
} = *special_render();
|
|
||||||
|
|
||||||
let mut list_numbers = Vec::new();
|
let mut list_numbers = Vec::new();
|
||||||
|
|
||||||
let (terminal_width, _) = crossterm::terminal::size().unwrap_or((80, 24));
|
let (terminal_width, _) = crossterm::terminal::size().unwrap_or((80, 24));
|
||||||
|
|
|
@ -504,13 +504,13 @@ async fn view_pr_labels(repo: &RepoName, api: &Forgejo, pr: Option<u64>) -> eyre
|
||||||
let pr = try_get_pr(repo, api, pr).await?;
|
let pr = try_get_pr(repo, api, pr).await?;
|
||||||
let labels = pr.labels.as_deref().unwrap_or_default();
|
let labels = pr.labels.as_deref().unwrap_or_default();
|
||||||
let SpecialRender {
|
let SpecialRender {
|
||||||
colors,
|
fancy,
|
||||||
black,
|
black,
|
||||||
white,
|
white,
|
||||||
reset,
|
reset,
|
||||||
..
|
..
|
||||||
} = *crate::special_render();
|
} = *crate::special_render();
|
||||||
if colors {
|
if fancy {
|
||||||
let mut total_width = 0;
|
let mut total_width = 0;
|
||||||
for label in labels {
|
for label in labels {
|
||||||
let name = label.name.as_deref().unwrap_or("???").trim();
|
let name = label.name.as_deref().unwrap_or("???").trim();
|
||||||
|
|
|
@ -476,7 +476,7 @@ impl RepoCommand {
|
||||||
let path = path.unwrap_or_else(|| PathBuf::from(format!("./{repo_name}")));
|
let path = path.unwrap_or_else(|| PathBuf::from(format!("./{repo_name}")));
|
||||||
|
|
||||||
let SpecialRender {
|
let SpecialRender {
|
||||||
colors, // actually using it to indicate fanciness FIXME
|
fancy, // actually using it to indicate fanciness FIXME
|
||||||
hide_cursor,
|
hide_cursor,
|
||||||
show_cursor,
|
show_cursor,
|
||||||
clear_line,
|
clear_line,
|
||||||
|
@ -490,7 +490,7 @@ impl RepoCommand {
|
||||||
let mut callbacks = git2::RemoteCallbacks::new();
|
let mut callbacks = git2::RemoteCallbacks::new();
|
||||||
callbacks.credentials(auth.credentials(&git_config));
|
callbacks.credentials(auth.credentials(&git_config));
|
||||||
|
|
||||||
if colors {
|
if fancy {
|
||||||
print!("{hide_cursor}");
|
print!("{hide_cursor}");
|
||||||
print!(" Preparing...");
|
print!(" Preparing...");
|
||||||
let _ = std::io::stdout().flush();
|
let _ = std::io::stdout().flush();
|
||||||
|
@ -530,7 +530,7 @@ impl RepoCommand {
|
||||||
let local_repo = git2::build::RepoBuilder::new()
|
let local_repo = git2::build::RepoBuilder::new()
|
||||||
.fetch_options(options)
|
.fetch_options(options)
|
||||||
.clone(clone_url.as_str(), &path)?;
|
.clone(clone_url.as_str(), &path)?;
|
||||||
if colors {
|
if fancy {
|
||||||
print!("{clear_line}{show_cursor}\r");
|
print!("{clear_line}{show_cursor}\r");
|
||||||
}
|
}
|
||||||
println!("Cloned {} into {}", repo_full_name, path.display());
|
println!("Cloned {} into {}", repo_full_name, path.display());
|
||||||
|
|
Loading…
Reference in a new issue