Introduce initial implementation of the vmic CLI with PipeWire integration
- Added `Cargo.toml` to define dependencies and project metadata. - Implemented core CLI functionality for managing virtual microphones (`create`, `edit`, `delete`, `list`, `route`, and `wipe` commands) using `clap`. - Integrated `rusqlite` for persistent state storage and `pipewire` to manage PipeWire nodes. - Ensured graceful handling of feedback loops and system defaults during virtual mic creation and deletion. - Added error handling via `thiserror` for cleaner error definitions.
This commit is contained in:
59
src/ui.rs
Normal file
59
src/ui.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
//! Colorized status output (NO_COLOR-aware).
|
||||
|
||||
use std::io::IsTerminal;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
/// Honors NO_COLOR (<https://no-color.org>), dumb terminals, and redirected output.
|
||||
fn color_enabled() -> bool {
|
||||
static ENABLED: OnceLock<bool> = OnceLock::new();
|
||||
*ENABLED.get_or_init(|| {
|
||||
std::env::var_os("NO_COLOR").is_none()
|
||||
&& std::env::var("TERM").map(|t| t != "dumb").unwrap_or(true)
|
||||
&& std::io::stdout().is_terminal()
|
||||
&& std::io::stderr().is_terminal()
|
||||
})
|
||||
}
|
||||
|
||||
fn paint(code: &str, s: &str) -> String {
|
||||
if color_enabled() {
|
||||
format!("\x1b[{code}m{s}\x1b[0m")
|
||||
} else {
|
||||
s.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn red(s: &str) -> String {
|
||||
paint("31", s)
|
||||
}
|
||||
|
||||
pub fn yellow(s: &str) -> String {
|
||||
paint("33", s)
|
||||
}
|
||||
|
||||
pub fn green(s: &str) -> String {
|
||||
paint("32", s)
|
||||
}
|
||||
|
||||
pub fn blue(s: &str) -> String {
|
||||
paint("34", s)
|
||||
}
|
||||
|
||||
pub fn cyan(s: &str) -> String {
|
||||
paint("36", s)
|
||||
}
|
||||
|
||||
pub fn err(msg: &str) {
|
||||
eprintln!("{}", red(&format!("Error: {msg}")));
|
||||
}
|
||||
|
||||
pub fn warn(msg: &str) {
|
||||
eprintln!("{}", yellow(&format!("Warning: {msg}")));
|
||||
}
|
||||
|
||||
pub fn info(msg: &str) {
|
||||
println!("{}", blue(msg));
|
||||
}
|
||||
|
||||
pub fn ok(msg: &str) {
|
||||
println!("{}", green(msg));
|
||||
}
|
||||
Reference in New Issue
Block a user