Skip to content

Commit

Permalink
format vfmt off areas
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-ward committed Jan 1, 2025
1 parent 75fa1d4 commit 2e18efd
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 71 deletions.
42 changes: 20 additions & 22 deletions lsv/entry.v
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,26 @@ fn make_entry(file string, dir_name string, options Options) Entry {
indicator := if is_dir && options.dir_indicator { '/' } else { '' }

return Entry{
// vfmt off
name: file + indicator
dir_name: dir_name
stat: stat
link_stat: link_stat
dir: is_dir
file: is_file
link: is_link
exe: is_exe
fifo: is_fifo
block: is_block
socket: is_socket
character: is_character_device
unknown: is_unknown
link_origin: link_origin
size: size
size_comma: if options.size_comma { num_with_commas(size)} else { '' }
size_ki: if options.size_ki { readable_size(size, true) } else { '' }
size_kb: if options.size_kb { readable_size(size, false) } else { '' }
checksum: if is_file { checksum(file, dir_name, options) } else { '' }
invalid: invalid
// vfmt on
name: file + indicator
dir_name: dir_name
stat: stat
link_stat: link_stat
dir: is_dir
file: is_file
link: is_link
exe: is_exe
fifo: is_fifo
block: is_block
socket: is_socket
character: is_character_device
unknown: is_unknown
link_origin: link_origin
size: size
size_comma: if options.size_comma { num_with_commas(size) } else { '' }
size_ki: if options.size_ki { readable_size(size, true) } else { '' }
size_kb: if options.size_kb { readable_size(size, false) } else { '' }
checksum: if is_file { checksum(file, dir_name, options) } else { '' }
invalid: invalid
}
}

Expand Down
2 changes: 1 addition & 1 deletion lsv/filter.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn filter(entries []Entry, options Options) []Entry {
// vfmt off
options.only_dirs { entries.clone().filter(it.dir) }
options.only_files { entries.clone().filter(it.file) }
else { entries }
else { entries }
// vfmt on
}
}
42 changes: 21 additions & 21 deletions lsv/format.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fn print_files(entries []Entry, options Options) {

match true {
// vfmt off
options.long_format { format_long_listing(entries, options) }
options.list_by_lines { format_by_lines(entries, width, options) }
options.with_commas { format_with_commas(entries, options) }
options.one_per_line { format_one_per_line(entries, options) }
else { format_by_cells(entries, width, options) }
options.long_format { format_long_listing(entries, options) }
options.list_by_lines { format_by_lines(entries, width, options) }
options.with_commas { format_with_commas(entries, options) }
options.one_per_line { format_one_per_line(entries, options) }
else { format_by_cells(entries, width, options) }
// vfmt on
}
}
Expand Down Expand Up @@ -131,15 +131,15 @@ fn (entries []Entry) max_name_len(options Options) int {
fn get_style_for(entry Entry, options Options) Style {
return match true {
// vfmt off
entry.link { options.style_ln }
entry.dir { options.style_di }
entry.exe { options.style_ex }
entry.fifo { options.style_pi }
entry.block { options.style_bd }
entry.link { options.style_ln }
entry.dir { options.style_di }
entry.exe { options.style_ex }
entry.fifo { options.style_pi }
entry.block { options.style_bd }
entry.character { options.style_cd }
entry.socket { options.style_so }
entry.file { options.style_fi }
else { no_style }
entry.socket { options.style_so }
entry.file { options.style_fi }
else { no_style }
// vfmt on
}
}
Expand All @@ -162,15 +162,15 @@ fn get_style_for_link(entry Entry, options Options) Style {

return match true {
// vfmt off
is_dir { options.style_di }
is_exe { options.style_ex }
is_fifo { options.style_pi }
is_block { options.style_bd }
is_dir { options.style_di }
is_exe { options.style_ex }
is_fifo { options.style_pi }
is_block { options.style_bd }
is_character_device { options.style_cd }
is_socket { options.style_so }
is_unknown { unknown_style }
is_file { options.style_fi }
else { no_style }
is_socket { options.style_so }
is_unknown { unknown_style }
is_file { options.style_fi }
else { no_style }
// vfmt on
}
}
Expand Down
50 changes: 25 additions & 25 deletions lsv/format_long.v
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ fn format_long_listing(entries []Entry, options Options) {
if !options.no_size {
content := match true {
// vfmt off
entry.invalid { unknown }
entry.dir || entry.socket || entry.fifo { '-' }
options.size_ki && options.size_ki && !options.size_kb { entry.size_ki }
options.size_kb && options.size_kb { entry.size_kb }
entry.invalid { unknown }
entry.dir || entry.socket || entry.fifo { '-' }
options.size_ki && options.size_ki && !options.size_kb { entry.size_ki }
options.size_kb && options.size_kb { entry.size_kb }
options.size_comma { entry.size_comma }
else { entry.size.str() }
else { entry.size.str() }
// vfmt on
}
size_style := match entry.link_stat.size > 0 {
Expand Down Expand Up @@ -288,10 +288,10 @@ fn format_header(options Options, longest Longest) (string, []int) {
fn time_format(options Options) string {
return match true {
// vfmt off
options.time_iso { date_iso_format }
options.time_compact { date_compact_format }
options.time_compact_with_day { date_compact_format_with_day }
else { date_format }
options.time_iso { date_iso_format }
options.time_compact { date_compact_format }
options.time_compact_with_day { date_compact_format_with_day }
else { date_format }
// vfmt on
}
}
Expand Down Expand Up @@ -332,13 +332,13 @@ fn statistics(entries []Entry, len int, options Options) {
// vfmt off
options.size_ki { readable_size(total, true) }
options.size_kb { readable_size(total, false) }
options.size_comma { num_with_commas(total) }
else { total.str() }
options.size_comma { num_with_commas(total) + ' bytes' }
else { total.str() }
// vfmt on
}

totals := style_string(size, options.style_fi, options)
stats = '${dir_count_styled} ${dirs} | ${file_count_styled} ${files} [${totals}]'
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)
Expand All @@ -351,16 +351,16 @@ fn statistics(entries []Entry, len int, options Options) {
fn file_flag(entry Entry, options Options) string {
return match true {
// vfmt off
entry.invalid { unknown }
entry.link { style_string('l', options.style_ln, options) }
entry.dir { style_string('d', options.style_di, options) }
entry.exe { style_string('x', options.style_ex, options) }
entry.fifo { style_string('p', options.style_pi, options) }
entry.block { style_string('b', options.style_bd, options) }
entry.invalid { unknown }
entry.link { style_string('l', options.style_ln, options) }
entry.dir { style_string('d', options.style_di, options) }
entry.exe { style_string('x', options.style_ex, options) }
entry.fifo { style_string('p', options.style_pi, options) }
entry.block { style_string('b', options.style_bd, options) }
entry.character { style_string('c', options.style_cd, options) }
entry.socket { style_string('s', options.style_so, options) }
entry.file { style_string('f', options.style_fi, options) }
else { ' ' }
entry.socket { style_string('s', options.style_so, options) }
entry.file { style_string('f', options.style_fi, options) }
else { ' ' }
// vfmt on
}
}
Expand Down Expand Up @@ -428,11 +428,11 @@ fn longest_group_name_len(entries []Entry, title string, options Options) int {
fn longest_size_len(entries []Entry, title string, options Options) int {
lengths := entries.map(match true {
// vfmt off
it.dir { 1 } // '-'
it.dir { 1 } // '-'
options.size_ki && !options.size_kb { it.size_ki.len }
options.size_kb { it.size_kb.len }
options.size_comma { it.size_comma.len }
else { it.size.str().len }
options.size_kb { it.size_kb.len }
options.size_comma { it.size_comma.len }
else { it.size.str().len }
// vfmt on
})
max := arrays.max(lengths) or { 0 }
Expand Down
4 changes: 2 additions & 2 deletions lsv/sort.v
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn sort(entries []Entry, options Options) []Entry {
// vfmt off
a.size < b.size { 1 }
a.size > b.size { -1 }
else { compare_strings(a.name, b.name) }
else { compare_strings(a.name, b.name) }
// vfmt on
}
}
Expand All @@ -25,7 +25,7 @@ fn sort(entries []Entry, options Options) []Entry {
// vfmt off
a.stat.mtime < b.stat.mtime { 1 }
a.stat.mtime > b.stat.mtime { -1 }
else { compare_strings(a.name, b.name) }
else { compare_strings(a.name, b.name) }
// vfmt on
}
}
Expand Down

0 comments on commit 2e18efd

Please sign in to comment.