mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
Merge pull request #8820 from Misakait/fix/reference-calculate
Some checks are pending
CICD / Style/cargo-deny (push) Waiting to run
CICD / Style/deps (push) Waiting to run
CICD / Test all features separately (push) Blocked by required conditions
CICD / Documentation/warnings (push) Waiting to run
CICD / MinRustV (push) Waiting to run
CICD / Dependencies (push) Waiting to run
CICD / Build/Makefile (push) Blocked by required conditions
CICD / Build/stable (push) Blocked by required conditions
CICD / Build/nightly (push) Blocked by required conditions
CICD / Binary sizes (push) Blocked by required conditions
CICD / Build (push) Blocked by required conditions
CICD / Tests/BusyBox test suite (push) Blocked by required conditions
CICD / Tests/Toybox test suite (push) Blocked by required conditions
CICD / Code Coverage (push) Waiting to run
CICD / Separate Builds (push) Waiting to run
CICD / Build/SELinux (push) Blocked by required conditions
CICD / Build/SELinux-Stubs (Non-Linux) (push) Blocked by required conditions
CICD / Safe Traversal Security Check (push) Blocked by required conditions
CICD / Run benchmarks (CodSpeed) (push) Blocked by required conditions
GnuTests / Run GNU tests (native) (push) Waiting to run
GnuTests / Run GNU tests (SELinux) (push) Waiting to run
GnuTests / Aggregate GNU test results (push) Blocked by required conditions
Android / Test builds (push) Waiting to run
Code Quality / Style/format (push) Waiting to run
Code Quality / Style/lint (push) Waiting to run
Code Quality / Style/spelling (push) Waiting to run
Code Quality / Style/toml (push) Waiting to run
Code Quality / Style/Python (push) Waiting to run
Code Quality / Pre-commit hooks (push) Waiting to run
Devcontainer / Verify devcontainer (push) Waiting to run
FreeBSD / Style and Lint (push) Waiting to run
FreeBSD / Tests (push) Waiting to run
WSL2 / Test (push) Waiting to run
Some checks are pending
CICD / Style/cargo-deny (push) Waiting to run
CICD / Style/deps (push) Waiting to run
CICD / Test all features separately (push) Blocked by required conditions
CICD / Documentation/warnings (push) Waiting to run
CICD / MinRustV (push) Waiting to run
CICD / Dependencies (push) Waiting to run
CICD / Build/Makefile (push) Blocked by required conditions
CICD / Build/stable (push) Blocked by required conditions
CICD / Build/nightly (push) Blocked by required conditions
CICD / Binary sizes (push) Blocked by required conditions
CICD / Build (push) Blocked by required conditions
CICD / Tests/BusyBox test suite (push) Blocked by required conditions
CICD / Tests/Toybox test suite (push) Blocked by required conditions
CICD / Code Coverage (push) Waiting to run
CICD / Separate Builds (push) Waiting to run
CICD / Build/SELinux (push) Blocked by required conditions
CICD / Build/SELinux-Stubs (Non-Linux) (push) Blocked by required conditions
CICD / Safe Traversal Security Check (push) Blocked by required conditions
CICD / Run benchmarks (CodSpeed) (push) Blocked by required conditions
GnuTests / Run GNU tests (native) (push) Waiting to run
GnuTests / Run GNU tests (SELinux) (push) Waiting to run
GnuTests / Aggregate GNU test results (push) Blocked by required conditions
Android / Test builds (push) Waiting to run
Code Quality / Style/format (push) Waiting to run
Code Quality / Style/lint (push) Waiting to run
Code Quality / Style/spelling (push) Waiting to run
Code Quality / Style/toml (push) Waiting to run
Code Quality / Style/Python (push) Waiting to run
Code Quality / Pre-commit hooks (push) Waiting to run
Devcontainer / Verify devcontainer (push) Waiting to run
FreeBSD / Style and Lint (push) Waiting to run
FreeBSD / Tests (push) Waiting to run
WSL2 / Test (push) Waiting to run
fix(ptx): Align text wrapping behavior with GNU in traditional mode
This commit is contained in:
commit
cd2e64d48f
2 changed files with 62 additions and 4 deletions
|
|
@ -224,7 +224,7 @@ fn get_config(matches: &clap::ArgMatches) -> UResult<Config> {
|
|||
}
|
||||
config.auto_ref = matches.get_flag(options::AUTO_REFERENCE);
|
||||
config.input_ref = matches.get_flag(options::REFERENCES);
|
||||
config.right_ref &= matches.get_flag(options::RIGHT_SIDE_REFS);
|
||||
config.right_ref = matches.get_flag(options::RIGHT_SIDE_REFS);
|
||||
config.ignore_case = matches.get_flag(options::IGNORE_CASE);
|
||||
if matches.contains_id(options::MACRO_NAME) {
|
||||
config.macro_name = matches
|
||||
|
|
@ -661,7 +661,7 @@ fn prepare_line_chunks(
|
|||
}
|
||||
|
||||
fn write_traditional_output(
|
||||
config: &Config,
|
||||
config: &mut Config,
|
||||
file_map: &FileMap,
|
||||
words: &BTreeSet<WordRef>,
|
||||
output_filename: &OsStr,
|
||||
|
|
@ -677,6 +677,15 @@ fn write_traditional_output(
|
|||
|
||||
let context_reg = Regex::new(&config.context_regex).unwrap();
|
||||
|
||||
if !config.right_ref {
|
||||
let max_ref_len = if config.auto_ref {
|
||||
get_auto_max_reference_len(words)
|
||||
} else {
|
||||
0
|
||||
};
|
||||
config.line_width -= max_ref_len;
|
||||
}
|
||||
|
||||
for word_ref in words {
|
||||
let file_map_value: &FileContent = file_map
|
||||
.get(&word_ref.filename)
|
||||
|
|
@ -722,6 +731,31 @@ fn write_traditional_output(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn get_auto_max_reference_len(words: &BTreeSet<WordRef>) -> usize {
|
||||
//Get the maximum length of the reference field
|
||||
let line_num = words
|
||||
.iter()
|
||||
.map(|w| {
|
||||
if w.local_line_nr == 0 {
|
||||
1
|
||||
} else {
|
||||
(w.local_line_nr as f64).log10() as usize + 1
|
||||
}
|
||||
})
|
||||
.max()
|
||||
.unwrap_or(0);
|
||||
|
||||
let filename_len = words
|
||||
.iter()
|
||||
.filter(|w| w.filename != "-")
|
||||
.map(|w| w.filename.maybe_quote().to_string().len())
|
||||
.max()
|
||||
.unwrap_or(0);
|
||||
|
||||
// +1 for the colon
|
||||
line_num + filename_len + 1
|
||||
}
|
||||
|
||||
mod options {
|
||||
pub mod format {
|
||||
pub static ROFF: &str = "roff";
|
||||
|
|
@ -749,7 +783,7 @@ mod options {
|
|||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
|
||||
let config = get_config(&matches)?;
|
||||
let mut config = get_config(&matches)?;
|
||||
|
||||
let input_files;
|
||||
let output_file: OsString;
|
||||
|
|
@ -783,7 +817,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let word_filter = WordFilter::new(&matches, &config)?;
|
||||
let file_map = read_input(&input_files).map_err_context(String::new)?;
|
||||
let word_set = create_word_set(&config, &word_filter, &file_map);
|
||||
write_traditional_output(&config, &file_map, &word_set, &output_file)
|
||||
write_traditional_output(&mut config, &file_map, &word_set, &output_file)
|
||||
}
|
||||
|
||||
pub fn uu_app() -> Command {
|
||||
|
|
|
|||
|
|
@ -57,6 +57,30 @@ fn test_truncation_no_extra_space_in_after() {
|
|||
.stdout_contains(".xx \"\" \"Rust\" \"is/\" \"\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gnu_ext_disabled_reference_calculation() {
|
||||
let input = "Hello World Rust is good language";
|
||||
let expected_output = concat!(
|
||||
r#".xx "language" "" "Hello World Rust is good" "" ":1""#,
|
||||
"\n",
|
||||
r#".xx "" "Hello World" "Rust is good language" "" ":1""#,
|
||||
"\n",
|
||||
r#".xx "" "Hello" "World Rust is good language" "" ":1""#,
|
||||
"\n",
|
||||
r#".xx "" "Hello World Rust is" "good language" "" ":1""#,
|
||||
"\n",
|
||||
r#".xx "" "Hello World Rust" "is good language" "" ":1""#,
|
||||
"\n",
|
||||
r#".xx "" "Hello World Rust is good" "language" "" ":1""#,
|
||||
"\n",
|
||||
);
|
||||
new_ucmd!()
|
||||
.args(&["-G", "-A"])
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only(expected_output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gnu_ext_disabled_rightward_no_ref() {
|
||||
new_ucmd!()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue