Implemented info properly

main
Michal 2 years ago
parent 1d474bf6f5
commit 653a3e16b1

91
Cargo.lock generated

@ -12,6 +12,8 @@ dependencies = [
"mimalloc",
"serde",
"serde_derive",
"tabled",
"termion",
"toml",
]
@ -38,6 +40,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bytecount"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c"
[[package]]
name = "cc"
version = "1.0.73"
@ -94,6 +102,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "hashbrown"
version = "0.12.3"
@ -155,6 +169,12 @@ dependencies = [
"libmimalloc-sys",
]
[[package]]
name = "numtoa"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
[[package]]
name = "once_cell"
version = "1.13.0"
@ -167,6 +187,17 @@ version = "6.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4"
[[package]]
name = "papergrid"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "453cf71f2a37af495a1a124bf30d4d7469cfbea58e9f2479be9d222396a518a2"
dependencies = [
"bytecount",
"fnv",
"unicode-width",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
@ -209,6 +240,24 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "534cfe58d6a18cc17120fbf4635d53d14691c1fe4d951064df9bd326178d7d5a"
dependencies = [
"bitflags",
]
[[package]]
name = "redox_termios"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
dependencies = [
"redox_syscall",
]
[[package]]
name = "serde"
version = "1.0.140"
@ -243,6 +292,30 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "tabled"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5b2f8c37d26d87d2252187b0a45ea3cbf42baca10377c7e7eaaa2800fa9bf97"
dependencies = [
"papergrid",
"tabled_derive",
"unicode-width",
]
[[package]]
name = "tabled_derive"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9ee618502f497abf593e1c5c9577f34775b111480009ffccd7ad70d23fcaba8"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "termcolor"
version = "1.1.3"
@ -252,6 +325,18 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "termion"
version = "1.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
dependencies = [
"libc",
"numtoa",
"redox_syscall",
"redox_termios",
]
[[package]]
name = "textwrap"
version = "0.15.0"
@ -273,6 +358,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7"
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "version_check"
version = "0.9.4"

@ -23,4 +23,6 @@ toml = { version = "0.5.9", default-features = false }
serde = { version = "1.0.139", default-features = false }
serde_derive = { version = "1.0.139", default-features = false }
libc = { version = "0.2.126", default-features = false }
colored = { version = "2.0.0", default-features = false }
colored = { version = "2.0.0", default-features = false }
tabled = { version = "0.8.0", default-features = false, features = ["derive"] }
termion = { version = "1.5.6", default-features = false }

@ -14,11 +14,11 @@ on_gen = false
[mode.workspace]
[repositories]
name = [
repos = [
"crs:amethyst",
"crs:malachite/development!",
"aur::notop-git",
"nms::appendage",
"aur:notop-git",
"nms:appendage",
]
[repositories.urls]

@ -17,7 +17,7 @@ macro_rules! info {
#[macro_export]
macro_rules! log {
($verbose:expr, $($arg:tt)+) => {
$crate::internal::strings::log_fn(format!($($arg)+), $verbose);
$crate::internal::strings::log_fn(format!("{}:{} {}", file!(), line!(), format!($($arg)+)), $verbose);
}
}

@ -1,6 +1,86 @@
use crate::log;
use crate::{info, log};
use colored::Colorize;
use std::env;
use tabled::Tabled;
// For displaying the table of contents
#[derive(Clone, tabled::Tabled, Debug)]
struct RepoDisplay {
#[tabled(rename = "Name")]
name: String,
#[tabled(rename = "URL")]
url: String,
#[tabled(rename = "Priority")]
priority: usize,
}
pub fn info(verbose: bool) {
log!(verbose, "Showing Info");
unimplemented!();
let config = crate::workspace::read_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// Add the branch to the name if it's not the default branch for said repository
let repos_unparsed = config.repositories;
let mut repos = vec![];
for repo in repos_unparsed {
let name = if repo.branch.is_some() {
format!("{}/{}", repo.name, repo.branch.unwrap())
} else {
repo.name.clone()
};
repos.push(RepoDisplay {
name,
url: repo.url,
priority: repo.priority,
});
}
log!(verbose, "Repos: {:?}", repos);
// Sort by priority
repos.sort_by(|a, b| b.priority.cmp(&a.priority));
log!(verbose, "Repos Sorted: {:?}", repos);
// Displaying basic info about the Malachite Repository
let internal_name = if !config.mode.repository.name.is_empty() {
config.mode.repository.name
} else {
env::current_dir()
.unwrap()
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string()
};
let name = format!(
"{} \"{}\":",
if config.base.mode == "repository" {
"Repository".to_string()
} else if config.base.mode == "workspace" {
"Workspace".to_string()
} else {
"".to_string()
},
internal_name
);
// Get terminal width
let width = match termion::terminal_size() {
Ok((w, _)) => w,
Err(_) => 80,
};
// Create table for displaying info
let table = tabled::Table::new(&repos)
.with(tabled::Style::modern())
.with(tabled::Width::wrap(width as usize))
.with(tabled::Width::increase(width as usize))
.to_string();
// Print all of the info
info!("{}", name);
info!(
"Local Repositories: {}",
repos.len().to_string().green().bold()
);
println!("{}", table.bold());
}

Loading…
Cancel
Save