skip markdown handling for non-fancy output

This commit is contained in:
Cyborus 2024-06-08 16:23:26 -04:00
parent 8bd72dd59c
commit 45e3565a9d
No known key found for this signature in database
3 changed files with 28 additions and 16 deletions

View file

@ -167,7 +167,7 @@ enum Style {
}
struct SpecialRender {
colors: bool,
fancy: bool,
dash: char,
bullet: char,
@ -219,7 +219,7 @@ impl SpecialRender {
fn fancy() -> Self {
Self {
colors: true,
fancy: true,
dash: '',
bullet: '',
@ -262,7 +262,7 @@ impl SpecialRender {
fn minimal() -> Self {
Self {
colors: false,
fancy: false,
dash: '-',
bullet: '-',
@ -305,6 +305,26 @@ impl SpecialRender {
}
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 mut options = comrak::Options::default();
options.extension.strikethrough = true;
@ -328,14 +348,6 @@ fn markdown(text: &str) -> String {
render_queue.push((node, side));
}
let SpecialRender {
bullet,
horiz_rule,
bright_blue,
dark_grey_bg,
..
} = *special_render();
let mut list_numbers = Vec::new();
let (terminal_width, _) = crossterm::terminal::size().unwrap_or((80, 24));

View file

@ -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 labels = pr.labels.as_deref().unwrap_or_default();
let SpecialRender {
colors,
fancy,
black,
white,
reset,
..
} = *crate::special_render();
if colors {
if fancy {
let mut total_width = 0;
for label in labels {
let name = label.name.as_deref().unwrap_or("???").trim();

View file

@ -476,7 +476,7 @@ impl RepoCommand {
let path = path.unwrap_or_else(|| PathBuf::from(format!("./{repo_name}")));
let SpecialRender {
colors, // actually using it to indicate fanciness FIXME
fancy, // actually using it to indicate fanciness FIXME
hide_cursor,
show_cursor,
clear_line,
@ -490,7 +490,7 @@ impl RepoCommand {
let mut callbacks = git2::RemoteCallbacks::new();
callbacks.credentials(auth.credentials(&git_config));
if colors {
if fancy {
print!("{hide_cursor}");
print!(" Preparing...");
let _ = std::io::stdout().flush();
@ -530,7 +530,7 @@ impl RepoCommand {
let local_repo = git2::build::RepoBuilder::new()
.fetch_options(options)
.clone(clone_url.as_str(), &path)?;
if colors {
if fancy {
print!("{clear_line}{show_cursor}\r");
}
println!("Cloned {} into {}", repo_full_name, path.display());