mirror of
https://github.com/NotAShelf/stash.git
synced 2026-04-13 14:33:47 +00:00
list: if we're in a TTY, output data in a TUI
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I6a6a696493f2e7ca911b6c1e2692b67f357a4b6b
This commit is contained in:
parent
7ccaf13bda
commit
83d45c6414
4 changed files with 635 additions and 27 deletions
46
src/main.rs
46
src/main.rs
|
|
@ -5,6 +5,8 @@ use std::{
|
|||
process,
|
||||
};
|
||||
|
||||
use atty::Stream;
|
||||
|
||||
use clap::{CommandFactory, Parser, Subcommand};
|
||||
use inquire::Confirm;
|
||||
|
||||
|
|
@ -153,30 +155,38 @@ fn main() {
|
|||
"Failed to store entry",
|
||||
);
|
||||
}
|
||||
Some(Command::List { format }) => {
|
||||
let format = format.as_deref().unwrap_or("tsv");
|
||||
match format {
|
||||
"tsv" => {
|
||||
Some(Command::List { format }) => match format.as_deref() {
|
||||
Some("tsv") => {
|
||||
report_error(
|
||||
db.list(io::stdout(), cli.preview_width),
|
||||
"Failed to list entries",
|
||||
);
|
||||
}
|
||||
Some("json") => match db.list_json() {
|
||||
Ok(json) => {
|
||||
println!("{json}");
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to list entries as JSON: {e}");
|
||||
}
|
||||
},
|
||||
Some(other) => {
|
||||
log::error!("Unsupported format: {other}");
|
||||
}
|
||||
None => {
|
||||
if atty::is(Stream::Stdout) {
|
||||
report_error(
|
||||
db.list_tui(cli.preview_width),
|
||||
"Failed to list entries in TUI",
|
||||
);
|
||||
} else {
|
||||
report_error(
|
||||
db.list(io::stdout(), cli.preview_width),
|
||||
"Failed to list entries",
|
||||
);
|
||||
}
|
||||
|
||||
"json" => match db.list_json() {
|
||||
Ok(json) => {
|
||||
println!("{json}");
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to list entries as JSON: {e}");
|
||||
}
|
||||
},
|
||||
|
||||
_ => {
|
||||
log::error!("Unsupported format: {format}");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Some(Command::Decode { input }) => {
|
||||
report_error(
|
||||
db.decode(io::stdin(), io::stdout(), input),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue