feat(komorebic): add log command

This commit adds a log command directly to the komorebic cli to make it
easier for users to check the logs if they don't have tail installed or
are not familiar with it.

A separate logfile with ANSI color codes is now being written to the
user's tempdir, which is tailed by the log command until the process is
halted by a Ctrl-C signal.
This commit is contained in:
LGUG2Z
2021-08-18 06:21:16 -07:00
parent 23aada05d0
commit 13b335cecc
4 changed files with 37 additions and 7 deletions

View File

@@ -17,6 +17,7 @@ komorebi-core = { path = "../komorebi-core" }
clap = "3.0.0-beta.4"
color-eyre = "0.5"
dirs = "3"
fs-tail = "0.1"
paste = "1"
powershell_script = "0.2"
serde = { version = "1", features = ["derive"] }

View File

@@ -11,6 +11,7 @@ use clap::ArgEnum;
use clap::Clap;
use color_eyre::eyre::ContextCompat;
use color_eyre::Result;
use fs_tail::TailedFile;
use paste::paste;
use uds_windows::UnixListener;
use uds_windows::UnixStream;
@@ -178,6 +179,8 @@ enum SubCommand {
Stop,
/// Show a JSON representation of the current window manager state
State,
/// Tail komorebi.exe's process logs (cancel with Ctrl-C)
Log,
/// Change focus to the window in the specified direction
#[clap(setting = AppSettings::ArgRequiredElseHelp)]
Focus(Focus),
@@ -277,6 +280,15 @@ fn main() -> Result<()> {
let opts: Opts = Opts::parse();
match opts.subcmd {
SubCommand::Log => {
let mut color_log = std::env::temp_dir();
color_log.push("komorebi.log");
let file = TailedFile::new(File::open(color_log)?);
let locked = file.lock();
for line in locked.lines() {
println!("{}", line?)
}
}
SubCommand::Focus(arg) => {
send_message(&*SocketMessage::FocusWindow(arg.operation_direction).as_bytes()?)?;
}