From 5f76c98f3c0eb783cfcda17df941b429c8377dbc Mon Sep 17 00:00:00 2001 From: itchyny Date: Wed, 30 Oct 2024 23:00:08 +0900 Subject: [PATCH] use explicit argument indexes in fmt.Sprintf and fmt.Errorf --- editor/editor.go | 4 ++-- tui/tui_window.go | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/editor/editor.go b/editor/editor.go index 733bce8..b129f11 100644 --- a/editor/editor.go +++ b/editor/editor.go @@ -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 { diff --git a/tui/tui_window.go b/tui/tui_window.go index c00aa33..2a8446b 100644 --- a/tui/tui_window.go +++ b/tui/tui_window.go @@ -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)) }