Skip to content

Commit

Permalink
link table nicely formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
postrequest committed Apr 12, 2021
1 parent 96081e1 commit 79c146e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ log = "0.4.0"
env_logger = "0.8.2"
base64 = "0.13.0"
byteorder = "1"
prettytable-rs = "0.8"
#tui = "0.13"
#termion = "1.5"
#sqlx = { version = "0.4.0", default-features = false, features = ["runtime-actix-native-tls", "sqlite", "time"] }
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pub mod routes;
pub mod server;
pub mod util;

#[macro_use] extern crate prettytable;

#[actix_web::main]
async fn main() {
util::cli::main_loop().await;
Expand Down
22 changes: 15 additions & 7 deletions src/util/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use rustyline::Editor;
use server::links::Links;
use std::sync::mpsc;

use prettytable::Table;
use prettytable::format;

// internal packages
use crate::server;
use crate::util;
Expand Down Expand Up @@ -313,25 +316,30 @@ fn links_list(links: web::Data<Links>, all: bool) {
} else {
println!("\n[{} Links]\n", count);
}
println!(" id | type | platform | who | internal ip | last checkin | status ");
println!("----------------------------------|-------|----------|------------------------------|---------------|--------------------------------------|--------");

// create table
let mut table = Table::new();
table.set_format(*format::consts::FORMAT_NO_BORDER);
table.add_row(row!["id", "type", "platform", "who", "internal ip", "last checkin", "status"]);

// add links
for i in 0..count {
let iu = i as usize;
let mut tmp = links.links.lock().unwrap();
tmp[iu].check_status();
if !all && tmp[iu].status != server::links::LinkStatus::Active {
continue;
}
println!(
" {:2} | {:4?} | {:8} | {:29} | {:13} | {:35} | {:?} ",
table.add_row(row![
tmp[iu].name,
tmp[iu].link_type,
format!("{:?}", tmp[iu].link_type),
tmp[iu].platform,
format!("{}\\{}", tmp[iu].link_hostname, tmp[iu].link_username),
tmp[iu].internal_ip,
tmp[iu].last_checkin,
tmp[iu].status,
);
format!("{:?}", tmp[iu].status),
]);
}
table.printstd();
println!();
}

0 comments on commit 79c146e

Please sign in to comment.