diff options
author | xroberx <xroberx@gmail.com> | 2024-05-09 13:30:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-09 13:30:40 +0200 |
commit | 55b21a1e73885613907f975d871e040a171cf37d (patch) | |
tree | fafd8c8f1468035eae5ea26c3dd977391dc6feb0 /tui/format.go | |
parent | 7af730c68aede0c8f536bae791e0f6f10f6b0627 (diff) |
Fix division by zero error in formatFileRow (#359)
Co-authored-by: Rober <rober@arch>
Diffstat (limited to 'tui/format.go')
-rw-r--r-- | tui/format.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/tui/format.go b/tui/format.go index 5f48d99..360138a 100644 --- a/tui/format.go +++ b/tui/format.go @@ -22,15 +22,17 @@ const ( ) func (ui *UI) formatFileRow(item fs.Item, maxUsage, maxSize int64, marked, ignored bool) string { - var part int - - switch { - case ignored: - part = 0 - case ui.ShowApparentSize: - part = int(float64(item.GetSize()) / float64(maxSize) * 100.0) - default: - part = int(float64(item.GetUsage()) / float64(maxUsage) * 100.0) + part := 0 + if !ignored { + if ui.ShowApparentSize { + if size := item.GetSize(); size > 0 { + part = int(float64(size) / float64(maxSize) * 100.0) + } + } else { + if usage := item.GetUsage(); usage > 0 { + part = int(float64(usage) / float64(maxUsage) * 100.0) + } + } } row := string(item.GetFlag()) |