summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Gerace <nickagerace@gmail.com>2021-05-23 00:39:16 -0400
committerNick Gerace <nickagerace@gmail.com>2021-05-23 00:47:29 -0400
commitc5208fa5d01624bdf794ee7f9f70bd62fe4f3968 (patch)
treec579850725a458b2a25dfddeff7f08b95e032c68
parent7ae35379eab6768a6cdd11b4ed6ba22e00d8ed44 (diff)
downloadgfold-c5208fa5d01624bdf794ee7f9f70bd62fe4f3968.zip
Bold table headers instead of repo names
-rw-r--r--CHANGELOG.md10
-rw-r--r--Cargo.lock18
-rw-r--r--Cargo.toml1
-rw-r--r--src/driver.rs20
-rw-r--r--src/util.rs28
5 files changed, 54 insertions, 23 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 986b755..d37f5b9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased]
-The latest version contains all changes.
+<!-- The latest version contains all changes. -->
+
+### Changed
+
+- Bold table headers instead of repo names
+
+### Removed
+
+- Extra newline before first entry when printing all tables
## [1.2.0] - 2021-05-16
diff --git a/Cargo.lock b/Cargo.lock
index 99d1bf4..233349f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,15 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
+name = "ansi_term"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
name = "anyhow"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -158,6 +167,7 @@ dependencies = [
name = "gfold"
version = "1.2.0"
dependencies = [
+ "ansi_term",
"anyhow",
"env_logger",
"git2",
@@ -319,9 +329,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
-version = "1.0.26"
+version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
+checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
dependencies = [
"unicode-xid",
]
@@ -484,9 +494,9 @@ dependencies = [
[[package]]
name = "vcpkg"
-version = "0.2.12"
+version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cbdbff6266a24120518560b5dc983096efb98462e51d0d68169895b237be3e5d"
+checksum = "025ce40a007e1907e58d5bc1a594def78e5573bb0b1160bc389634e8f12e4faa"
[[package]]
name = "version_check"
diff --git a/Cargo.toml b/Cargo.toml
index 5cccaf7..57037d6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,7 @@ repository = "https://github.com/nickgerace/gfold/"
version = "1.2.0"
[dependencies]
+ansi_term = { version = "^0", default-features = false }
env_logger = { version = "^0", default-features = false }
git2 = { version = "^0", default-features = false }
log = { version = "^0", default-features = false }
diff --git a/src/driver.rs b/src/driver.rs
index c92599b..ee47919 100644
--- a/src/driver.rs
+++ b/src/driver.rs
@@ -1,7 +1,8 @@
//! This module contains the types required for generating results for `gfold`.
use crate::{driver_internal::TableWrapper, util};
+use ansi_term::Style;
use anyhow::Result;
-use log::{debug, warn};
+use log::{debug, error, warn};
use std::{
cmp::Ordering,
fs,
@@ -43,12 +44,27 @@ impl Driver {
/// Print results to `STDOUT` after generation.
pub fn print_results(self) {
+ #[cfg(windows)]
+ ansi_term::enable_ansi_support();
+
debug!("Printing results with {} tables...", self.0.len());
match self.0.len().cmp(&1) {
Ordering::Greater => {
+ let last = match self.0.last() {
+ Some(s) => s.path_string.clone(),
+ None => {
+ error!(
+ "Last object not found for table vector. Continuing with empty string."
+ );
+ String::from("")
+ }
+ };
for table_wrapper in self.0 {
- println!("\n{}", table_wrapper.path_string);
+ println!("{}", Style::new().bold().paint(&table_wrapper.path_string));
table_wrapper.table.printstd();
+ if table_wrapper.path_string != last {
+ println!();
+ }
}
}
Ordering::Equal => {
diff --git a/src/util.rs b/src/util.rs
index b582b8a..ea53e0e 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -49,11 +49,11 @@ pub fn create_table_from_paths(
}
};
let url = origin.url().unwrap_or("none");
- debug!("[+] url: {:#?}", url);
+ debug!("> url: {:#?}", url);
let head = repo_obj.head().ok()?;
let branch = head.shorthand().unwrap_or("none");
- debug!("[+] branch: {:#?}", branch);
+ debug!("> branch: {:#?}", branch);
// FIXME: test using the "is_bare()" method for a repository object.
let mut opts = git2::StatusOptions::new();
@@ -78,7 +78,7 @@ pub fn create_table_from_paths(
let name = repo.as_path().file_name()?.to_str()?;
let create_row = |status_spec: &str, status: &str| -> prettytable::Row {
let mut cells = vec![
- Cell::new(name).style_spec(if *no_color { "Fl" } else { "Flb" }),
+ Cell::new(name).style_spec("Fl"),
Cell::new(status).style_spec(if *no_color { "Fl" } else { status_spec }),
Cell::new(branch).style_spec("Fl"),
Cell::new(url).style_spec("Fl"),
@@ -99,7 +99,7 @@ pub fn create_table_from_paths(
Condition::Unpushed => table.add_row(create_row("Fcl", "unpushed")),
_ => table.add_row(create_row("Frl", "error")),
};
- debug!("[+] condition: {:#?}", condition);
+ debug!("> condition: {:#?}", condition);
}
// D.R.Y. is important, but the "non_repos" loop would not benefit from the closure used by
@@ -107,11 +107,7 @@ pub fn create_table_from_paths(
// whereas the "non_repos" loop does not create any local variables beyond the row's cells.
for non_repo in non_repos {
let mut cells = vec![
- Cell::new(non_repo.as_path().file_name()?.to_str()?).style_spec(if *no_color {
- "Fl"
- } else {
- "Flb"
- }),
+ Cell::new(non_repo.as_path().file_name()?.to_str()?).style_spec("Fl"),
Cell::new("dir").style_spec(if *no_color { "Fl" } else { "Fml" }),
Cell::new("-").style_spec("Fl"),
Cell::new("-").style_spec("Fl"),
@@ -137,34 +133,34 @@ fn is_unpushed(repo: &git2::Repository, head: &git2::Reference) -> bool {
let local = match head.peel_to_commit() {
Ok(local) => local,
Err(e) => {
- debug!("[-] error: {}", e);
+ debug!("> error: {}", e);
return false;
}
};
- debug!("[+] local commit: {:#?}", local.id());
+ debug!("> local commit: {:#?}", local.id());
if let Some(name) = head.name() {
- debug!("[+] local ref: {}", name);
+ debug!("> local ref: {}", name);
}
let upstream = match repo.resolve_reference_from_short_name("origin") {
Ok(reference) => {
if let Some(name) = reference.name() {
- debug!("[+] origin ref: {}", name);
+ debug!("> origin ref: {}", name);
}
match reference.peel_to_commit() {
Ok(upstream) => upstream,
Err(e) => {
- debug!("[-] error: {}", e);
+ debug!("> error: {}", e);
return false;
}
}
}
Err(e) => {
- debug!("[-] error: {}", e);
+ debug!("> error: {}", e);
return false;
}
};
- debug!("[+] origin commit: {:#?}", upstream.id());
+ debug!("> origin commit: {:#?}", upstream.id());
matches!(repo.graph_ahead_behind(local.id(), upstream.id()), Ok(ahead) if ahead.0 > 0)
}