mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Merge pull request #5299 from sylvestre/dired-2
ls --dired - some minor cleanup
This commit is contained in:
commit
a2691c9f4a
2 changed files with 6 additions and 8 deletions
|
@ -33,7 +33,7 @@ impl fmt::Display for BytePosition {
|
||||||
static DIRED_TRAILING_OFFSET: usize = 2;
|
static DIRED_TRAILING_OFFSET: usize = 2;
|
||||||
|
|
||||||
/// Calculates the byte positions for DIRED
|
/// Calculates the byte positions for DIRED
|
||||||
pub fn calculate_dired_byte_positions(
|
pub fn calculate_dired(
|
||||||
output_display_len: usize,
|
output_display_len: usize,
|
||||||
dfn_len: usize,
|
dfn_len: usize,
|
||||||
dired_positions: &[BytePosition],
|
dired_positions: &[BytePosition],
|
||||||
|
@ -54,7 +54,7 @@ pub fn indent(out: &mut BufWriter<Stdout>) -> UResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn calculate_offset_and_push(dired: &mut DiredOutput, path_len: usize) {
|
pub fn calculate_subdired(dired: &mut DiredOutput, path_len: usize) {
|
||||||
let offset = if dired.subdired_positions.is_empty() {
|
let offset = if dired.subdired_positions.is_empty() {
|
||||||
DIRED_TRAILING_OFFSET
|
DIRED_TRAILING_OFFSET
|
||||||
} else {
|
} else {
|
||||||
|
@ -95,7 +95,6 @@ pub fn add_total(total_len: usize, dired: &mut DiredOutput) {
|
||||||
dired.just_printed_total = true;
|
dired.just_printed_total = true;
|
||||||
dired.dired_positions.push(BytePosition {
|
dired.dired_positions.push(BytePosition {
|
||||||
start: 0,
|
start: 0,
|
||||||
// the 2 is from the trailing spaces
|
|
||||||
// the 1 is from the line ending (\n)
|
// the 1 is from the line ending (\n)
|
||||||
end: total_len + DIRED_TRAILING_OFFSET - 1,
|
end: total_len + DIRED_TRAILING_OFFSET - 1,
|
||||||
});
|
});
|
||||||
|
@ -144,12 +143,11 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_calculate_dired_byte_positions() {
|
fn test_calculate_dired() {
|
||||||
let output_display = "sample_output".to_string();
|
let output_display = "sample_output".to_string();
|
||||||
let dfn = "sample_file".to_string();
|
let dfn = "sample_file".to_string();
|
||||||
let dired_positions = vec![BytePosition { start: 5, end: 10 }];
|
let dired_positions = vec![BytePosition { start: 5, end: 10 }];
|
||||||
let (start, end) =
|
let (start, end) = calculate_dired(output_display.len(), dfn.len(), &dired_positions);
|
||||||
calculate_dired_byte_positions(output_display.len(), dfn.len(), &dired_positions);
|
|
||||||
|
|
||||||
assert_eq!(start, 24);
|
assert_eq!(start, 24);
|
||||||
assert_eq!(end, 35);
|
assert_eq!(end, 35);
|
||||||
|
|
|
@ -1921,7 +1921,7 @@ pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> {
|
||||||
}
|
}
|
||||||
writeln!(out, "{}:", path_data.p_buf.display())?;
|
writeln!(out, "{}:", path_data.p_buf.display())?;
|
||||||
if config.dired {
|
if config.dired {
|
||||||
dired::calculate_offset_and_push(&mut dired, path_data.display_name.len());
|
dired::calculate_subdired(&mut dired, path_data.display_name.len());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
writeln!(out, "\n{}:", path_data.p_buf.display())?;
|
writeln!(out, "\n{}:", path_data.p_buf.display())?;
|
||||||
|
@ -2545,7 +2545,7 @@ fn display_item_long(
|
||||||
|
|
||||||
let displayed_file = display_file_name(item, config, None, String::new(), out).contents;
|
let displayed_file = display_file_name(item, config, None, String::new(), out).contents;
|
||||||
if config.dired {
|
if config.dired {
|
||||||
let (start, end) = dired::calculate_dired_byte_positions(
|
let (start, end) = dired::calculate_dired(
|
||||||
output_display.len(),
|
output_display.len(),
|
||||||
displayed_file.len(),
|
displayed_file.len(),
|
||||||
&dired.dired_positions,
|
&dired.dired_positions,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue