This commit is contained in:
lubeilin
2023-03-13 22:11:52 +08:00
parent 5b2c2435d5
commit 6f7992ea9f
46 changed files with 760 additions and 2124 deletions
-3
View File
@@ -1,8 +1,5 @@
use std::net::Ipv4Addr;
use console::style;
use switch::Route;
use crate::command::entity::{DeviceItem, RouteItem, Status};
pub mod table;
+10 -7
View File
@@ -1,8 +1,4 @@
const NODE: &str = "+";
const EDGE: &str = "-";
const HIGH: &str = "|";
const SPACE: &str = " ";
const EMPTY: &str = "";
use console::style;
pub fn println_table(table: Vec<Vec<String>>) {
if table.is_empty() {
@@ -11,16 +7,23 @@ pub fn println_table(table: Vec<Vec<String>>) {
let mut width_list = vec![0; table[0].len()];
for in_list in table.iter() {
for (index, item) in in_list.iter().enumerate() {
let width = console::measure_text_width(item)+6;
let width = console::measure_text_width(item) + 6;
if width_list[index] < width {
width_list[index] = width;
}
}
}
let mut head = true;
for in_list in table {
for (index, item) in in_list.iter().enumerate() {
print!("{item:width$}", item = item, width = width_list[index]);
if head {
print!("{item:width$}", item = item, width = width_list[index]);
} else {
let str = format!("{item:width$}", item = item, width = width_list[index]);
print!("{}", style(str).green());
}
}
head = false;
println!()
}
}