Skip to content

Commit

Permalink
use explicit argument indexes in fmt.Sprintf and fmt.Errorf
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Oct 30, 2024
1 parent 3848992 commit 5f76c98
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ func (e *Editor) emit(ev event.Event) (redraw, finish bool, err error) {
if l, err := e.buffer.Len(); err != nil {
e.err, e.errtyp = err, state.MessageError
} else {
e.err, e.errtyp = fmt.Errorf("%d (0x%x) bytes %s", l, l, ev.Arg), state.MessageInfo
e.err, e.errtyp = fmt.Errorf("%[1]d (0x%[1]x) bytes %[2]s", l, ev.Arg), state.MessageInfo
}
}
redraw = true
case event.Pasted:
e.err, e.errtyp = fmt.Errorf("%d (0x%x) bytes pasted", ev.Count, ev.Count), state.MessageInfo
e.err, e.errtyp = fmt.Errorf("%[1]d (0x%[1]x) bytes pasted", ev.Count), state.MessageInfo
redraw = true
default:
switch ev.Type {
Expand Down
5 changes: 2 additions & 3 deletions tui/tui_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ func (ui *tuiWindow) drawFooter(s *state.WindowState, offsetStyleWidth int) {
b := s.Bytes[int(s.Cursor-s.Offset)]
left := fmt.Sprintf(" %s%s%s : 0x%02x : '%s'",
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)))
right := fmt.Sprintf("%[1]d/%[2]d : 0x%0[3]*[1]x/0x%0[3]*[2]x : %.2[4]f%% ",
s.Cursor, s.Length, offsetStyleWidth, float64(s.Cursor*100)/float64(max(s.Length, 1)))
line := fmt.Sprintf("%s %*s", left, max(ui.region.width-len(left)-2, 0), right)
ui.getTextDrawer().setTop(ui.region.height-1).setString(line, tcell.StyleDefault.Reverse(true))
}
Expand Down

0 comments on commit 5f76c98

Please sign in to comment.