From 03c42ee8c8c627d9f27cdfeedaa2c64282288f92 Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Fri, 5 Apr 2024 22:01:19 +0200 Subject: [PATCH 1/2] Refactor to use consistent parserState receiver --- oviewer/content.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/oviewer/content.go b/oviewer/content.go index c2ed51e8..8bf7cb5c 100644 --- a/oviewer/content.go +++ b/oviewer/content.go @@ -286,18 +286,18 @@ func (es *parseState) parseEscapeSequence(mainc rune) bool { } // overstrike set style for overstrike. -func (state *parseState) overstrike(m content, style tcell.Style) tcell.Style { - if !state.bsFlag { +func (es *parseState) overstrike(m content, style tcell.Style) tcell.Style { + if !es.bsFlag { return style } - if state.bsContent.mainc == m.mainc { + if es.bsContent.mainc == m.mainc { style = OverStrikeStyle - } else if state.bsContent.mainc == '_' { + } else if es.bsContent.mainc == '_' { style = OverLineStyle } - state.bsFlag = false - state.bsContent = DefaultContent + es.bsFlag = false + es.bsContent = DefaultContent return style } From 363dfc71fe8a818bade5165d56a5dd0033e3e677 Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Fri, 5 Apr 2024 22:02:51 +0200 Subject: [PATCH 2/2] Clean unused receivers The code is clearer about what is used --- oviewer/draw.go | 4 ++-- oviewer/event.go | 2 +- oviewer/input_delimiter.go | 8 ++++---- oviewer/input_filter.go | 4 ++-- oviewer/input_goto.go | 8 ++++---- oviewer/input_header.go | 8 ++++---- oviewer/input_jumptarget.go | 8 ++++---- oviewer/input_multicolor.go | 4 ++-- oviewer/input_normal.go | 10 +++++----- oviewer/input_savebuffer.go | 8 ++++---- oviewer/input_search.go | 8 ++++---- oviewer/input_section_delimiter.go | 8 ++++---- oviewer/input_section_num.go | 8 ++++---- oviewer/input_section_start.go | 8 ++++---- oviewer/input_skip.go | 8 ++++---- oviewer/input_tabwidth.go | 8 ++++---- oviewer/input_viewmode.go | 8 ++++---- oviewer/input_watch.go | 8 ++++---- oviewer/input_writeba.go | 8 ++++---- oviewer/reader.go | 2 +- oviewer/search.go | 2 +- 21 files changed, 70 insertions(+), 70 deletions(-) diff --git a/oviewer/draw.go b/oviewer/draw.go index d166e782..a3da8a69 100644 --- a/oviewer/draw.go +++ b/oviewer/draw.go @@ -296,7 +296,7 @@ func (root *Root) drawNoWrapLine(y int, startX int, lN int, lc contents) (int, i // bodyStyle applies the style from the beginning to the end of one line of the body. // Apply style to contents. -func (root *Root) bodyStyle(lc contents, s OVStyle) { +func (*Root) bodyStyle(lc contents, s OVStyle) { RangeStyle(lc, 0, len(lc), s) } @@ -314,7 +314,7 @@ func (root *Root) searchHighlight(line LineC) { } // plainStyle defaults to the original style. -func (root *Root) plainStyle(lc contents) { +func (*Root) plainStyle(lc contents) { for x := 0; x < len(lc); x++ { lc[x].style = tcell.StyleDefault } diff --git a/oviewer/event.go b/oviewer/event.go index ddf0676c..6d4cafb8 100644 --- a/oviewer/event.go +++ b/oviewer/event.go @@ -277,7 +277,7 @@ type eventCloseDocument struct { } // CloseDocument fires the eventCloseDocument event. -func (root *Root) CloseDocument(m *Document) { +func (root *Root) CloseDocument(_ *Document) { root.sendCloseDocument() } diff --git a/oviewer/input_delimiter.go b/oviewer/input_delimiter.go index 267f63e5..4d57fdd8 100644 --- a/oviewer/input_delimiter.go +++ b/oviewer/input_delimiter.go @@ -41,12 +41,12 @@ func newDelimiterEvent(clist *candidate) *eventDelimiter { } // Mode returns InputMode. -func (e *eventDelimiter) Mode() InputMode { +func (*eventDelimiter) Mode() InputMode { return Delimiter } // Prompt returns the prompt string in the input field. -func (e *eventDelimiter) Prompt() string { +func (*eventDelimiter) Prompt() string { return "Delimiter:" } @@ -59,11 +59,11 @@ func (e *eventDelimiter) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventDelimiter) Up(str string) string { +func (e *eventDelimiter) Up(_ string) string { return e.clist.up() } // Down returns strings when the down key is pressed during input. -func (e *eventDelimiter) Down(str string) string { +func (e *eventDelimiter) Down(_ string) string { return e.clist.down() } diff --git a/oviewer/input_filter.go b/oviewer/input_filter.go index f9dbf659..5634bd7a 100644 --- a/oviewer/input_filter.go +++ b/oviewer/input_filter.go @@ -35,12 +35,12 @@ func newSearchFilterEvent(clist *candidate) *eventInputFilter { } // Mode returns InputMode. -func (e *eventInputFilter) Mode() InputMode { +func (*eventInputFilter) Mode() InputMode { return Filter } // Prompt returns the prompt string in the input field. -func (e *eventInputFilter) Prompt() string { +func (*eventInputFilter) Prompt() string { return "&" } diff --git a/oviewer/input_goto.go b/oviewer/input_goto.go index ed9a9c69..22cea205 100644 --- a/oviewer/input_goto.go +++ b/oviewer/input_goto.go @@ -30,12 +30,12 @@ func newGotoEvent(clist *candidate) *eventGoto { } // Mode returns InputMode. -func (e *eventGoto) Mode() InputMode { +func (*eventGoto) Mode() InputMode { return Goline } // Prompt returns the prompt string in the input field. -func (e *eventGoto) Prompt() string { +func (*eventGoto) Prompt() string { return "Goto line:" } @@ -48,11 +48,11 @@ func (e *eventGoto) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventGoto) Up(str string) string { +func (e *eventGoto) Up(_ string) string { return e.clist.up() } // Down returns strings when the down key is pressed during input. -func (e *eventGoto) Down(str string) string { +func (e *eventGoto) Down(_ string) string { return e.clist.down() } diff --git a/oviewer/input_header.go b/oviewer/input_header.go index b33c1ece..57ea805c 100644 --- a/oviewer/input_header.go +++ b/oviewer/input_header.go @@ -26,12 +26,12 @@ func newHeaderEvent() *eventHeader { } // Mode returns InputMode. -func (e *eventHeader) Mode() InputMode { +func (*eventHeader) Mode() InputMode { return Header } // Prompt returns the prompt string in the input field. -func (e *eventHeader) Prompt() string { +func (*eventHeader) Prompt() string { return "Header length:" } @@ -43,7 +43,7 @@ func (e *eventHeader) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventHeader) Up(str string) string { +func (*eventHeader) Up(str string) string { n, err := strconv.Atoi(str) if err != nil { return "0" @@ -52,7 +52,7 @@ func (e *eventHeader) Up(str string) string { } // Down returns strings when the down key is pressed during input. -func (e *eventHeader) Down(str string) string { +func (*eventHeader) Down(str string) string { n, err := strconv.Atoi(str) if err != nil || n <= 0 { return "0" diff --git a/oviewer/input_jumptarget.go b/oviewer/input_jumptarget.go index 0fe0ee53..e6b54898 100644 --- a/oviewer/input_jumptarget.go +++ b/oviewer/input_jumptarget.go @@ -37,12 +37,12 @@ func newJumpTargetEvent(clist *candidate) *eventJumpTarget { } // Mode returns InputMode. -func (e *eventJumpTarget) Mode() InputMode { +func (*eventJumpTarget) Mode() InputMode { return JumpTarget } // Prompt returns the prompt string in the input field. -func (e *eventJumpTarget) Prompt() string { +func (*eventJumpTarget) Prompt() string { return "Jump Target line:" } @@ -55,11 +55,11 @@ func (e *eventJumpTarget) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventJumpTarget) Up(str string) string { +func (e *eventJumpTarget) Up(_ string) string { return e.clist.up() } // Down returns strings when the down key is pressed during input. -func (e *eventJumpTarget) Down(str string) string { +func (e *eventJumpTarget) Down(_ string) string { return e.clist.down() } diff --git a/oviewer/input_multicolor.go b/oviewer/input_multicolor.go index cc0532bc..f9db1542 100644 --- a/oviewer/input_multicolor.go +++ b/oviewer/input_multicolor.go @@ -45,12 +45,12 @@ func newMultiColorEvent(clist *candidate) *eventMultiColor { } // Mode returns InputMode. -func (e *eventMultiColor) Mode() InputMode { +func (*eventMultiColor) Mode() InputMode { return MultiColor } // Prompt returns the prompt string in the input field. -func (e *eventMultiColor) Prompt() string { +func (*eventMultiColor) Prompt() string { return "multicolor:" } diff --git a/oviewer/input_normal.go b/oviewer/input_normal.go index ec000d2a..bab1da03 100644 --- a/oviewer/input_normal.go +++ b/oviewer/input_normal.go @@ -14,26 +14,26 @@ func normal() *eventNormal { } // Mode returns InputMode. -func (e *eventNormal) Mode() InputMode { +func (*eventNormal) Mode() InputMode { return Normal } // Prompt returns the prompt string in the input field. -func (e *eventNormal) Prompt() string { +func (*eventNormal) Prompt() string { return "" } // Confirm returns the event when the input is confirmed. -func (e *eventNormal) Confirm(str string) tcell.Event { +func (*eventNormal) Confirm(_ string) tcell.Event { return nil } // Up returns strings when the up key is pressed during input. -func (e *eventNormal) Up(str string) string { +func (*eventNormal) Up(_ string) string { return "" } // Down returns strings when the down key is pressed during input. -func (e *eventNormal) Down(str string) string { +func (*eventNormal) Down(_ string) string { return "" } diff --git a/oviewer/input_savebuffer.go b/oviewer/input_savebuffer.go index 540203a6..a1b10c24 100644 --- a/oviewer/input_savebuffer.go +++ b/oviewer/input_savebuffer.go @@ -39,12 +39,12 @@ func newSaveBufferEvent(clist *candidate) *eventSaveBuffer { } // Mode returns InputMode. -func (e *eventSaveBuffer) Mode() InputMode { +func (*eventSaveBuffer) Mode() InputMode { return SaveBuffer } // Prompt returns the prompt string in the input field. -func (e *eventSaveBuffer) Prompt() string { +func (*eventSaveBuffer) Prompt() string { return "(Save)file:" } @@ -56,11 +56,11 @@ func (e *eventSaveBuffer) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventSaveBuffer) Up(str string) string { +func (e *eventSaveBuffer) Up(_ string) string { return e.clist.up() } // Down returns strings when the down key is pressed during input. -func (e *eventSaveBuffer) Down(str string) string { +func (e *eventSaveBuffer) Down(_ string) string { return e.clist.down() } diff --git a/oviewer/input_search.go b/oviewer/input_search.go index f6d1fd3a..c97daf87 100644 --- a/oviewer/input_search.go +++ b/oviewer/input_search.go @@ -43,12 +43,12 @@ func newSearchEvent(clist *candidate) *eventInputSearch { } // Mode returns InputMode. -func (e *eventInputSearch) Mode() InputMode { +func (*eventInputSearch) Mode() InputMode { return Search } // Prompt returns the prompt string in the input field. -func (e *eventInputSearch) Prompt() string { +func (*eventInputSearch) Prompt() string { return "/" } @@ -100,12 +100,12 @@ func newBackSearchEvent(clist *candidate) *eventInputBackSearch { } // Mode returns InputMode. -func (e *eventInputBackSearch) Mode() InputMode { +func (*eventInputBackSearch) Mode() InputMode { return Backsearch } // Prompt returns the prompt string in the input field. -func (e *eventInputBackSearch) Prompt() string { +func (*eventInputBackSearch) Prompt() string { return "?" } diff --git a/oviewer/input_section_delimiter.go b/oviewer/input_section_delimiter.go index c0109deb..97c726d3 100644 --- a/oviewer/input_section_delimiter.go +++ b/oviewer/input_section_delimiter.go @@ -39,12 +39,12 @@ func newSectionDelimiterEvent(clist *candidate) *eventSectionDelimiter { } // Mode returns InputMode. -func (e *eventSectionDelimiter) Mode() InputMode { +func (*eventSectionDelimiter) Mode() InputMode { return SectionDelimiter } // Prompt returns the prompt string in the input field. -func (e *eventSectionDelimiter) Prompt() string { +func (*eventSectionDelimiter) Prompt() string { return "Section delimiter:" } @@ -57,11 +57,11 @@ func (e *eventSectionDelimiter) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventSectionDelimiter) Up(str string) string { +func (e *eventSectionDelimiter) Up(_ string) string { return e.clist.up() } // Down returns strings when the down key is pressed during input. -func (e *eventSectionDelimiter) Down(str string) string { +func (e *eventSectionDelimiter) Down(_ string) string { return e.clist.down() } diff --git a/oviewer/input_section_num.go b/oviewer/input_section_num.go index 89c50c13..62b71387 100644 --- a/oviewer/input_section_num.go +++ b/oviewer/input_section_num.go @@ -26,12 +26,12 @@ func newSectionNumEvent() *eventSectionNum { } // Mode returns InputMode. -func (e *eventSectionNum) Mode() InputMode { +func (*eventSectionNum) Mode() InputMode { return SectionNum } // Prompt returns the prompt string in the input field. -func (e *eventSectionNum) Prompt() string { +func (*eventSectionNum) Prompt() string { return "Section Num:" } @@ -43,7 +43,7 @@ func (e *eventSectionNum) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventSectionNum) Up(str string) string { +func (*eventSectionNum) Up(str string) string { n, err := strconv.Atoi(str) if err != nil { return "0" @@ -52,7 +52,7 @@ func (e *eventSectionNum) Up(str string) string { } // Down returns strings when the down key is pressed during input. -func (e *eventSectionNum) Down(str string) string { +func (*eventSectionNum) Down(str string) string { n, err := strconv.Atoi(str) if err != nil || n <= 0 { return "0" diff --git a/oviewer/input_section_start.go b/oviewer/input_section_start.go index 4fcfb049..9bae5c4a 100644 --- a/oviewer/input_section_start.go +++ b/oviewer/input_section_start.go @@ -34,12 +34,12 @@ func newSectionStartEvent(clist *candidate) *eventSectionStart { } // Mode returns InputMode. -func (e *eventSectionStart) Mode() InputMode { +func (*eventSectionStart) Mode() InputMode { return SectionStart } // Prompt returns the prompt string in the input field. -func (e *eventSectionStart) Prompt() string { +func (*eventSectionStart) Prompt() string { return "Section start:" } @@ -52,11 +52,11 @@ func (e *eventSectionStart) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventSectionStart) Up(str string) string { +func (e *eventSectionStart) Up(_ string) string { return e.clist.up() } // Down returns strings when the down key is pressed during input. -func (e *eventSectionStart) Down(str string) string { +func (e *eventSectionStart) Down(_ string) string { return e.clist.down() } diff --git a/oviewer/input_skip.go b/oviewer/input_skip.go index 9ff2d7c3..ed68aebb 100644 --- a/oviewer/input_skip.go +++ b/oviewer/input_skip.go @@ -26,12 +26,12 @@ func newSkipLinesEvent() *eventSkipLines { } // Mode returns InputMode. -func (e *eventSkipLines) Mode() InputMode { +func (*eventSkipLines) Mode() InputMode { return SkipLines } // Prompt returns the prompt string in the input field. -func (e *eventSkipLines) Prompt() string { +func (*eventSkipLines) Prompt() string { return "Skip lines:" } @@ -43,7 +43,7 @@ func (e *eventSkipLines) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventSkipLines) Up(str string) string { +func (*eventSkipLines) Up(str string) string { n, err := strconv.Atoi(str) if err != nil { return "0" @@ -52,7 +52,7 @@ func (e *eventSkipLines) Up(str string) string { } // Down returns strings when the down key is pressed during input. -func (e *eventSkipLines) Down(str string) string { +func (*eventSkipLines) Down(str string) string { n, err := strconv.Atoi(str) if err != nil || n <= 0 { return "0" diff --git a/oviewer/input_tabwidth.go b/oviewer/input_tabwidth.go index 295a2c64..923f9096 100644 --- a/oviewer/input_tabwidth.go +++ b/oviewer/input_tabwidth.go @@ -42,12 +42,12 @@ func newTabWidthEvent(clist *candidate) *eventTabWidth { } // Mode returns InputMode. -func (e *eventTabWidth) Mode() InputMode { +func (*eventTabWidth) Mode() InputMode { return TabWidth } // Prompt returns the prompt string in the input field. -func (e *eventTabWidth) Prompt() string { +func (*eventTabWidth) Prompt() string { return "TAB width:" } @@ -60,11 +60,11 @@ func (e *eventTabWidth) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventTabWidth) Up(str string) string { +func (e *eventTabWidth) Up(_ string) string { return e.clist.up() } // Down returns strings when the down key is pressed during input. -func (e *eventTabWidth) Down(str string) string { +func (e *eventTabWidth) Down(_ string) string { return e.clist.down() } diff --git a/oviewer/input_viewmode.go b/oviewer/input_viewmode.go index f7bde499..934c98e8 100644 --- a/oviewer/input_viewmode.go +++ b/oviewer/input_viewmode.go @@ -32,12 +32,12 @@ func newViewModeEvent(clist *candidate) *eventViewMode { } // Mode returns InputMode. -func (e *eventViewMode) Mode() InputMode { +func (*eventViewMode) Mode() InputMode { return ViewMode } // Prompt returns the prompt string in the input field. -func (e *eventViewMode) Prompt() string { +func (*eventViewMode) Prompt() string { return "Mode:" } @@ -49,11 +49,11 @@ func (e *eventViewMode) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventViewMode) Up(str string) string { +func (e *eventViewMode) Up(_ string) string { return e.clist.up() } // Down returns strings when the down key is pressed during input. -func (e *eventViewMode) Down(str string) string { +func (e *eventViewMode) Down(_ string) string { return e.clist.down() } diff --git a/oviewer/input_watch.go b/oviewer/input_watch.go index 74ff97db..cc002db8 100644 --- a/oviewer/input_watch.go +++ b/oviewer/input_watch.go @@ -34,12 +34,12 @@ func newWatchIntervalEvent(clist *candidate) *eventWatchInterval { } // Mode returns InputMode. -func (e *eventWatchInterval) Mode() InputMode { +func (*eventWatchInterval) Mode() InputMode { return Watch } // Prompt returns the prompt string in the input field. -func (e *eventWatchInterval) Prompt() string { +func (*eventWatchInterval) Prompt() string { return "Watch interval:" } @@ -52,11 +52,11 @@ func (e *eventWatchInterval) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventWatchInterval) Up(str string) string { +func (e *eventWatchInterval) Up(_ string) string { return e.clist.up() } // Down returns strings when the down key is pressed during input. -func (e *eventWatchInterval) Down(str string) string { +func (e *eventWatchInterval) Down(_ string) string { return e.clist.down() } diff --git a/oviewer/input_writeba.go b/oviewer/input_writeba.go index 9ac3d7b4..25a09879 100644 --- a/oviewer/input_writeba.go +++ b/oviewer/input_writeba.go @@ -30,12 +30,12 @@ func newWriteBAEvent(clist *candidate) *eventWriteBA { } // Mode returns InputMode. -func (e *eventWriteBA) Mode() InputMode { +func (*eventWriteBA) Mode() InputMode { return WriteBA } // Prompt returns the prompt string in the input field. -func (e *eventWriteBA) Prompt() string { +func (*eventWriteBA) Prompt() string { return "WriteAndQuit Before:After:" } @@ -48,11 +48,11 @@ func (e *eventWriteBA) Confirm(str string) tcell.Event { } // Up returns strings when the up key is pressed during input. -func (e *eventWriteBA) Up(str string) string { +func (e *eventWriteBA) Up(_ string) string { return e.clist.up() } // Down returns strings when the down key is pressed during input. -func (e *eventWriteBA) Down(str string) string { +func (e *eventWriteBA) Down(_ string) string { return e.clist.down() } diff --git a/oviewer/reader.go b/oviewer/reader.go index 897ab084..deac0521 100644 --- a/oviewer/reader.go +++ b/oviewer/reader.go @@ -401,7 +401,7 @@ func (m *Document) ReadFile(fileName string) error { // ContinueReadAll continues to read even if it reaches EOF. // // Deprecated: Use ControlFile instead. -func (m *Document) ContinueReadAll(ctx context.Context, r io.Reader) error { +func (m *Document) ContinueReadAll(_ context.Context, r io.Reader) error { return m.ReadAll(r) } diff --git a/oviewer/search.go b/oviewer/search.go index d2657021..8f94986e 100644 --- a/oviewer/search.go +++ b/oviewer/search.go @@ -481,7 +481,7 @@ func (m *Document) BackSearchLine(ctx context.Context, searcher Searcher, lineNu // cancelWait waits for key to cancel. func (root *Root) cancelWait(cancel context.CancelFunc) error { - cancelApp := func(ev *tcell.EventKey) *tcell.EventKey { + cancelApp := func(_ *tcell.EventKey) *tcell.EventKey { cancel() root.setMessage("cancel") return nil