diff --git a/src/ls/format_long.v b/src/ls/format_long.v index 6110e44f..92e25d18 100644 --- a/src/ls/format_long.v +++ b/src/ls/format_long.v @@ -92,8 +92,8 @@ fn format_long_listing(entries []Entry, options Options) { // checksum if options.checksum != '' { - checksum := format_cell(entry.checksum, longest.checksum, .left, dim, options) - print(checksum) + sum := format_cell(entry.checksum, longest.checksum, .left, dim, options) + print(sum) print_space() } @@ -106,7 +106,7 @@ fn format_long_listing(entries []Entry, options Options) { // octal permissions if options.octal_permissions { - content := format_octal_permissions(entry, options) + content := format_octal_permissions(entry) print(format_cell(content, 4, .left, dim, options)) print_space() } @@ -317,40 +317,6 @@ fn right_pad_end(s string, width int) string { return if pad > 0 { s + space.repeat(pad) } else { s } } -fn statistics(entries []Entry, len int, options Options) { - file_count := entries.filter(it.file).len - total := arrays.sum(entries.map(if it.file || it.exe { it.stat.size } else { 0 })) or { 0 } - dir_count := entries.filter(it.dir).len - link_count := entries.filter(it.link).len - mut stats := '' - - dim := if options.no_dim { no_style } else { dim_style } - file_count_styled := style_string(file_count.str(), options.style_fi, options) - - file := if file_count == 1 { 'file' } else { 'files' } - files := style_string(file, dim, options) - dir_count_styled := style_string(dir_count.str(), options.style_di, options) - - dir := if dir_count == 1 { 'directory' } else { 'directories' } - dirs := style_string(dir, dim, options) - - size := match true { - options.size_ki { readable_size(total, true) } - options.size_kb { readable_size(total, false) } - else { total.str() } - } - - totals := style_string(size, options.style_fi, options) - stats = '${dir_count_styled} ${dirs} | ${file_count_styled} ${files} [${totals}]' - - if link_count > 0 { - link_count_styled := style_string(link_count.str(), options.style_ln, options) - links := style_string('links', dim, options) - stats += ' | ${link_count_styled} ${links}' - } - println(stats) -} - fn file_flag(entry Entry, options Options) string { return match true { // vfmt off @@ -367,7 +333,7 @@ fn file_flag(entry Entry, options Options) string { } } -fn format_octal_permissions(entry Entry, options Options) string { +fn format_octal_permissions(entry Entry) string { mode := entry.stat.get_mode() return '0${mode.owner.bitmask()}${mode.group.bitmask()}${mode.others.bitmask()}' } diff --git a/src/ls/icons.v b/src/ls/icons.v index 1d55ed1d..2246fd5d 100644 --- a/src/ls/icons.v +++ b/src/ls/icons.v @@ -429,12 +429,3 @@ const folders_map = { 'hidden': '\uf023' 'node_modules': '\ue5fa' } - -const other_icons_map = { - 'link': '\uf0c1' - 'linkDir': '\uf0c1' - 'brokenLink': '\uf127' - 'device': '\uf0a0' - 'socket': '\uf1e6' - 'pipe': '\ufce3' -} diff --git a/src/ls/natural_compare.v b/src/ls/natural_compare.v index d2dc1a85..4accdc24 100644 --- a/src/ls/natural_compare.v +++ b/src/ls/natural_compare.v @@ -1,12 +1,17 @@ import math -// compares strings with embedded numbers (e.g. log17.txt) +// natural_compare orders the way GNU's -v does: a run of digits weighs as a +// number rather than character by character, so log17.txt sorts before log9.txt. +// Anything else falls back to compare_strings, so a name with no digits in it +// orders exactly as it would without -v. fn natural_compare(a &string, b &string) int { pa := split(a) pb := split(b) - max := math.min(pa.len, pb.len) + // Only the shared prefix has to be walked: if every part of it compares + // equal then the name with fewer parts has run out and comes first. + shared := math.min(pa.len, pb.len) - for i := 0; i < max; i++ { + for i in 0 .. shared { if pa[i].is_int() && pb[i].is_int() { result := pa[i].int() - pb[i].int() if result != 0 { @@ -22,32 +27,22 @@ fn natural_compare(a &string, b &string) int { return pa.len - pb.len } -enum State { - init - digit - non_digit -} - +// split breaks a name into alternating runs of digits and of everything else, so +// log17.txt becomes ['log', '17', '.txt'] and 9.txt becomes ['9', '.txt']. fn split(a &string) []string { mut result := []string{} mut start := 0 - mut state := State.init + // Whether the character before this one was a digit. Starting false is what + // stops a leading run from emitting an empty first part. + mut prev_digit := false s := a.runes() - - for i := 0; i < s.len; i++ { - if s[i] >= `0` && s[i] <= `9` { - if state == State.non_digit { - result << s[start..i].string() - start = i - } - state = State.digit - } else { - if state == State.digit { - result << s[start..i].string() - start = i - } - state = State.non_digit + for i in 0 .. s.len { + is_digit := s[i] >= `0` && s[i] <= `9` + if is_digit != prev_digit { + result << s[start..i].string() + start = i } + prev_digit = is_digit } result << s[start..].string() return result diff --git a/src/ls/table.v b/src/ls/table.v index 59e0d2f1..972f5750 100644 --- a/src/ls/table.v +++ b/src/ls/table.v @@ -1,7 +1,6 @@ const table_border = `─` const table_border_pad_right = ' │' // border for between cells const table_border_pad_left = '│ ' -const table_border_divider = `│` const table_border_top_start = `┌` const table_border_top_end = `┐` const table_border_mid_start = `├` @@ -11,7 +10,6 @@ const table_border_bot_end = `┘` const table_border_t = `┬` const table_border_u_t = `┴` const table_border_cross = `┼` -const table_border_size = 2 fn print_header_border(options Options, len int, cols []int) { if options.table_format { @@ -42,10 +40,6 @@ fn border_row_bottom(len int, cols []int) string { return format_table_border(len, cols, table_border_u_t, table_border_bot_start, table_border_bot_end) } -fn border_row_middle_end(len int, cols []int) string { - return format_table_border(len, cols, table_border_u_t, table_border_mid_start, table_border_mid_end) -} - fn border_row_middle(len int, cols []int) string { return format_table_border(len, cols, table_border_cross, table_border_mid_start, table_border_mid_end)