mirror of
https://github.com/encounter/decomp-toolkit.git
synced 2025-06-22 06:23:28 +00:00
vfs ls: Fix column sizing with Unicode chars
This commit is contained in:
parent
d1b35c4d18
commit
04b60d319c
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -249,7 +249,7 @@ dependencies = [
|
|||||||
"encode_unicode",
|
"encode_unicode",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
"unicode-width",
|
"unicode-width 0.1.14",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -401,6 +401,7 @@ dependencies = [
|
|||||||
"tracing-attributes",
|
"tracing-attributes",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"typed-path",
|
"typed-path",
|
||||||
|
"unicode-width 0.2.0",
|
||||||
"xxhash-rust",
|
"xxhash-rust",
|
||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
@ -554,7 +555,7 @@ version = "0.2.21"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
|
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-width",
|
"unicode-width 0.1.14",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -571,9 +572,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.15.0"
|
version = "0.15.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
|
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"foldhash",
|
"foldhash",
|
||||||
]
|
]
|
||||||
@ -631,7 +632,7 @@ dependencies = [
|
|||||||
"instant",
|
"instant",
|
||||||
"number_prefix",
|
"number_prefix",
|
||||||
"portable-atomic",
|
"portable-atomic",
|
||||||
"unicode-width",
|
"unicode-width 0.1.14",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1790,6 +1791,12 @@ version = "0.1.14"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unsafe-libyaml"
|
name = "unsafe-libyaml"
|
||||||
version = "0.2.11"
|
version = "0.2.11"
|
||||||
|
@ -77,6 +77,7 @@ syntect = { version = "5.2", features = ["parsing", "regex-fancy", "dump-load"],
|
|||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-attributes = "0.1"
|
tracing-attributes = "0.1"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
|
unicode-width = "0.2"
|
||||||
xxhash-rust = { version = "0.8", features = ["xxh3"] }
|
xxhash-rust = { version = "0.8", features = ["xxh3"] }
|
||||||
zerocopy = { version = "0.8", features = ["derive"] }
|
zerocopy = { version = "0.8", features = ["derive"] }
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ use anyhow::{anyhow, bail, Context};
|
|||||||
use argp::FromArgs;
|
use argp::FromArgs;
|
||||||
use size::Size;
|
use size::Size;
|
||||||
use typed_path::{Utf8NativePath, Utf8NativePathBuf, Utf8UnixPath};
|
use typed_path::{Utf8NativePath, Utf8NativePathBuf, Utf8UnixPath};
|
||||||
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
util::{file::buf_copy, path::native_path},
|
util::{file::buf_copy, path::native_path},
|
||||||
@ -72,7 +73,7 @@ fn column_widths<const N: usize>(entries: &[Columns<N>]) -> [usize; N] {
|
|||||||
let mut widths = [0usize; N];
|
let mut widths = [0usize; N];
|
||||||
for text in entries {
|
for text in entries {
|
||||||
for (i, column) in text.iter().enumerate() {
|
for (i, column) in text.iter().enumerate() {
|
||||||
widths[i] = widths[i].max(column.len());
|
widths[i] = widths[i].max(column.width_cjk());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
widths
|
widths
|
||||||
@ -133,7 +134,11 @@ pub fn ls(args: LsArgs) -> anyhow::Result<()> {
|
|||||||
print!("{}", SEPARATOR);
|
print!("{}", SEPARATOR);
|
||||||
}
|
}
|
||||||
written += 1;
|
written += 1;
|
||||||
print!("{:width$}", column, width = widths[i]);
|
print!("{}", column);
|
||||||
|
let remain = widths[i].saturating_sub(column.width_cjk());
|
||||||
|
if remain > 0 {
|
||||||
|
print!("{:width$}", "", width = remain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user