Skip to content

Commit

Permalink
use cmp.Or to simplify the code for filename in footer
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Apr 14, 2024
1 parent 891b0dd commit d1fc361
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions tui/tui_window.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tui

import (
"cmp"
"fmt"

"github.com/gdamore/tcell"
Expand Down Expand Up @@ -152,17 +153,13 @@ func (ui *tuiWindow) drawScrollBar(s *state.WindowState, height int, left int) {
}

func (ui *tuiWindow) drawFooter(s *state.WindowState, offsetStyleWidth int) {
j := int(s.Cursor - s.Offset)
name := s.Name
if name == "" {
name = "[No name]"
}
var modified string
if s.Modified {
modified = " : +"
}
b := s.Bytes[int(s.Cursor-s.Offset)]
left := fmt.Sprintf(" %s%s%s : 0x%02x : '%s'",
prettyMode(s.Mode), name, modified, s.Bytes[j], prettyRune(s.Bytes[j]))
prettyMode(s.Mode), cmp.Or(s.Name, "[No name]"), modified, b, prettyRune(b))
right := fmt.Sprintf("%d/%d : 0x%0*x/0x%0*x : %.2f%% ",
s.Cursor, s.Length, offsetStyleWidth, s.Cursor, offsetStyleWidth, s.Length,
float64(s.Cursor*100)/float64(max(s.Length, 1)))
Expand Down

0 comments on commit d1fc361

Please sign in to comment.