write shit
This commit is contained in:
@ -10,3 +10,4 @@ license = "SPDX:MIT"
|
||||
thiserror = { workspace = true }
|
||||
wfassoc = { path="../wfassoc" }
|
||||
clap = { version="4.5.48", features=["derive"]}
|
||||
comfy-table = "7.2.1"
|
||||
|
@ -1,7 +1,8 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
use comfy_table::Table;
|
||||
use std::process;
|
||||
use wfassoc::{Error as WfError};
|
||||
use thiserror::Error as TeError;
|
||||
use wfassoc::{Error as WfError, FileExt, Scope};
|
||||
|
||||
// region: Basic Types
|
||||
|
||||
@ -10,7 +11,7 @@ use thiserror::Error as TeError;
|
||||
enum Error {
|
||||
/// Error from wfassoc core.
|
||||
#[error("{0}")]
|
||||
Core(#[from] WfError)
|
||||
Core(#[from] WfError),
|
||||
}
|
||||
|
||||
/// Result type used in this executable.
|
||||
@ -89,9 +90,40 @@ fn run_unregister(cli: Cli) -> Result<()> {
|
||||
}
|
||||
|
||||
fn run_query(cli: Cli) -> Result<()> {
|
||||
let exts = [
|
||||
".jpg", ".jfif", ".gif", ".bmp", ".png", ".ico", ".jpeg", ".tif", ".tiff", ".webp", ".svg",
|
||||
".kra", ".xcf", ".avif", ".qoi", ".apng", ".exr",
|
||||
];
|
||||
|
||||
let mut table = Table::new();
|
||||
table.set_header(["Extension", "Default Open", "Open With"]);
|
||||
for ext in exts.iter().map(|e| FileExt::new(e).unwrap()) {
|
||||
if let Some(ext_assoc) = ext.query(Scope::User) {
|
||||
if ext_assoc.len_open_with_progid() == 0 {
|
||||
table.add_row([ext.to_string().as_str(), ext_assoc.get_default(), ""]);
|
||||
} else {
|
||||
for (i, open_with_entry) in ext_assoc.iter_open_with_progids().enumerate() {
|
||||
if i == 0 {
|
||||
table.add_row([
|
||||
ext.to_string().as_str(),
|
||||
ext_assoc.get_default(),
|
||||
open_with_entry,
|
||||
]);
|
||||
} else {
|
||||
table.add_row(["", "", open_with_entry]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
table.add_row([ext.to_string().as_str(), "", ""]);
|
||||
}
|
||||
}
|
||||
|
||||
println!("{table}");
|
||||
|
||||
// let program = Program::new();
|
||||
// program.query()?;
|
||||
println!("Has privilege: {}", wfassoc::has_privilege());
|
||||
//println!("Has privilege: {}", wfassoc::has_privilege());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user