summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-06-08 22:23:26 +0200
committerCyborus <cyborus@cyborus.xyz>2024-06-08 22:23:26 +0200
commit45e3565a9deba2fdc14c23774637ed8ee1f74169 (patch)
tree131b34919c41be4c083ec66d14e8d12d023064e7
parentnicer markdown printing (diff)
downloadforgejo-cli-45e3565a9deba2fdc14c23774637ed8ee1f74169.tar.xz
forgejo-cli-45e3565a9deba2fdc14c23774637ed8ee1f74169.zip
skip markdown handling for non-fancy output
-rw-r--r--src/main.rs34
-rw-r--r--src/prs.rs4
-rw-r--r--src/repo.rs6
3 files changed, 28 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index 6a80980..ebcc9d0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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));
diff --git a/src/prs.rs b/src/prs.rs
index b13b451..b4e6e30 100644
--- a/src/prs.rs
+++ b/src/prs.rs
@@ -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();
diff --git a/src/repo.rs b/src/repo.rs
index 0a58d5b..33befec 100644
--- a/src/repo.rs
+++ b/src/repo.rs
@@ -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());