Просмотр исходного кода

tau: Do not print unnecessary table data when piping task table output

parazyd 3 лет назад
Родитель
Сommit
3326e1b060
3 измененных файлов с 14 добавлено и 2 удалено
  1. 1 0
      Cargo.lock
  2. 1 0
      bin/tau/tau-cli/Cargo.toml
  3. 12 2
      bin/tau/tau-cli/src/view.rs

+ 1 - 0
Cargo.lock

@@ -5946,6 +5946,7 @@ dependencies = [
  "clap 4.3.21",
  "colored",
  "darkfi",
+ "libc",
  "libsqlite3-sys",
  "log",
  "prettytable-rs",

+ 1 - 0
bin/tau/tau-cli/Cargo.toml

@@ -9,6 +9,7 @@ homepage = "https://dark.fi"
 repository = "https://github.com/darkrenaissance/darkfi"
 
 [dependencies]
+libc = "0.2.147"
 darkfi = { path = "../../../", features = ["rpc"]}
 
 # Async

+ 12 - 2
bin/tau/tau-cli/src/view.rs

@@ -117,8 +117,18 @@ pub fn print_task_list(tasks: Vec<TaskInfo>, ws: String) -> Result<()> {
             .build(),
     );
 
-    ws_table.printstd();
-    table.printstd();
+    if unsafe { libc::isatty(libc::STDOUT_FILENO) } == 1 {
+        ws_table.printstd();
+        table.printstd();
+    } else {
+        for row in table.row_iter() {
+            for cell in row.iter() {
+                print!("{}\t", cell.get_content());
+            }
+            print!("\n");
+        }
+    }
+
     Ok(())
 }