Clean log from ANSI

This commit is contained in:
Wildan M 2025-11-03 21:23:48 +07:00
parent 97d8b2f691
commit 7524f32f71
3 changed files with 20 additions and 91 deletions

87
Cargo.lock generated
View File

@ -429,12 +429,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
[[package]]
name = "cfg_aliases"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
@ -772,12 +766,6 @@ dependencies = [
"syn",
]
[[package]]
name = "downcast-rs"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
[[package]]
name = "dryoc"
version = "0.6.2"
@ -1585,18 +1573,6 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "nix"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4"
dependencies = [
"bitflags 2.9.1",
"cfg-if 1.0.1",
"cfg_aliases 0.1.1",
"libc",
]
[[package]]
name = "nom"
version = "7.1.3"
@ -1818,27 +1794,6 @@ version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
[[package]]
name = "portable-pty"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4a596a2b3d2752d94f51fac2d4a96737b8705dddd311a32b9af47211f08671e"
dependencies = [
"anyhow",
"bitflags 1.3.2",
"downcast-rs",
"filedescriptor",
"lazy_static",
"libc",
"log",
"nix",
"serial2",
"shared_library",
"shell-words",
"winapi",
"winreg",
]
[[package]]
name = "potential_utf"
version = "0.1.2"
@ -1888,7 +1843,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "626214629cda6781b6dc1d316ba307189c85ba657213ce642d9c77670f8202c8"
dependencies = [
"bytes",
"cfg_aliases 0.2.1",
"cfg_aliases",
"pin-project-lite",
"quinn-proto",
"quinn-udp",
@ -1928,7 +1883,7 @@ version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcebb1209ee276352ef14ff8732e24cc2b02bbac986cd74a4c81bcb2f9881970"
dependencies = [
"cfg_aliases 0.2.1",
"cfg_aliases",
"libc",
"once_cell",
"socket2",
@ -2107,13 +2062,13 @@ dependencies = [
"pkgar 0.1.19",
"pkgar-core 0.1.19",
"pkgar-keys 0.1.19",
"portable-pty",
"ratatui",
"redox-pkg",
"redox_installer",
"redoxer",
"regex",
"serde",
"strip-ansi-escapes",
"tempfile",
"termion",
"toml 0.8.23",
@ -2535,17 +2490,6 @@ dependencies = [
"serde",
]
[[package]]
name = "serial2"
version = "0.2.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cc76fa68e25e771492ca1e3c53d447ef0be3093e05cd3b47f4b712ba10c6f3c"
dependencies = [
"cfg-if 1.0.1",
"libc",
"winapi",
]
[[package]]
name = "sha2"
version = "0.10.9"
@ -2557,22 +2501,6 @@ dependencies = [
"digest 0.10.7",
]
[[package]]
name = "shared_library"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11"
dependencies = [
"lazy_static",
"libc",
]
[[package]]
name = "shell-words"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
[[package]]
name = "shlex"
version = "1.3.0"
@ -3579,15 +3507,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "winreg"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"winapi",
]
[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"

View File

@ -20,9 +20,15 @@ name = "cookbook"
path = "src/lib.rs"
doctest = false
[features]
#TODO: Actually make without tui feature works
default = ["tui"]
tui = ["ratatui", "ansi-to-tui", "filedescriptor", "strip-ansi-escapes"]
[dependencies]
anyhow = "1"
blake3 = "=1.5.3" # 1.5.4 is incompatible with blake3 0.3 dependency from pkgar
# blake3 1.5.4 is incompatible with 0.3 dependency from pkgar
blake3 = "=1.5.3"
libc = "0.2"
ignore = "0.4"
object = { version = "0.36", features = ["build_core"] }
@ -30,22 +36,23 @@ pbr = "1.0.2"
pkgar = { path = "pkgar/pkgar" }
pkgar-core = { path = "pkgar/pkgar-core" }
pkgar-keys = { path = "pkgar/pkgar-keys" }
portable-pty = "0.9.0"
redox-pkg = "0.2.8"
redox_installer = "0.2.37"
redoxer = "0.2.56"
regex = "1.11"
serde = { version = "=1.0.197", features = ["derive"] }
termion = "4"
toml = "0.8"
walkdir = "2.3.1"
filedescriptor = "0.8.3"
ansi-to-tui = "7.0.0"
redox_installer = "0.2.37"
filedescriptor = { version = "0.8.3", optional = true }
ansi-to-tui = { version = "7.0.0", optional = true }
strip-ansi-escapes = { version = "0.2.1", optional = true }
[dependencies.ratatui]
version = "0.29.0"
default-features = false
features = ["termion"]
optional = true
[dev-dependencies]
tempfile = "3"

View File

@ -730,7 +730,10 @@ impl TuiApp {
let (Some(logs), line) = self.get_recipe_log(recipe_name) else {
return Ok(());
};
fs::write(log_path, join_logs(logs, line))?;
let str = strip_ansi_escapes::strip_str(join_logs(logs, line));
if !str.trim_end().is_empty() {
fs::write(log_path, str)?;
}
return Ok(());
}
@ -770,7 +773,7 @@ impl TuiApp {
return;
}
StatusUpdate::FlushLog(name, path) => {
// TODO: This blocks the TUI for a moment, maybe open separate thread?
// TODO: This blocks the TUI, maybe open separate thread?
// FIXME: handle error here?
let _ = self.write_log(&name, &path);
return;