Skip to content

Commit

Permalink
Handle some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Jan 5, 2024
1 parent 54c88d3 commit dc0243f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 0 additions & 2 deletions m/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ func NewLine(raw string) Line {

// Returns a representation of the string split into styled tokens. Any regexp
// matches are highlighted. A nil regexp means no highlighting.
//
//revive:disable-next-line:unexported-return
func (line *Line) HighlightedTokens(linePrefix string, search *regexp.Regexp, lineNumberOneBased *int) textstyles.CellsWithTrailer {
plain := line.Plain(lineNumberOneBased)
matchRanges := getMatchRanges(&plain, search)
Expand Down
6 changes: 3 additions & 3 deletions moar.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ func parseStatusBarStyle(styleOption string) (m.StatusBarOption, error) {

func parseUnprintableStyle(styleOption string) (textstyles.UnprintableStyleT, error) {
if styleOption == "highlight" {
return textstyles.UNPRINTABLE_STYLE_HIGHLIGHT, nil
return textstyles.UnprintableStyleHighlight, nil
}
if styleOption == "whitespace" {
return textstyles.UNPRINTABLE_STYLE_WHITESPACE, nil
return textstyles.UnprintableStyleWhitespace, nil
}

return 0, fmt.Errorf("Good ones are highlight or whitespace")
Expand Down Expand Up @@ -417,7 +417,7 @@ func main() {
noClearOnExit := flagSet.Bool("no-clear-on-exit", false, "Retain screen contents when exiting moar")
statusBarStyle := flagSetFunc(flagSet, "statusbar", m.STATUSBAR_STYLE_INVERSE,
"Status bar style: inverse, plain or bold", parseStatusBarStyle)
unprintableStyle := flagSetFunc(flagSet, "render-unprintable", textstyles.UNPRINTABLE_STYLE_HIGHLIGHT,
unprintableStyle := flagSetFunc(flagSet, "render-unprintable", textstyles.UnprintableStyleHighlight,
"How unprintable characters are rendered: highlight or whitespace", parseUnprintableStyle)
scrollLeftHint := flagSetFunc(flagSet, "scroll-left-hint",
twin.NewCell('<', twin.StyleDefault.WithAttr(twin.AttrReverse)),
Expand Down
21 changes: 11 additions & 10 deletions textstyles/ansiTokenizer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This package handles styled strings. It can strip styling from strings and it
// can turn a styled string into a series of screen cells. Some global variables
// can be used to configure how various things are rendered.
package textstyles

import (
Expand All @@ -12,10 +15,8 @@ import (
type UnprintableStyleT int

const (
//revive:disable-next-line:var-naming
UNPRINTABLE_STYLE_HIGHLIGHT UnprintableStyleT = iota
//revive:disable-next-line:var-naming
UNPRINTABLE_STYLE_WHITESPACE
UnprintableStyleHighlight UnprintableStyleT = iota
UnprintableStyleWhitespace
)

var UnprintableStyle UnprintableStyleT
Expand Down Expand Up @@ -75,9 +76,9 @@ func WithoutFormatting(s string, lineNumberOneBased *int) string {
}

case '�': // Go's broken-UTF8 marker
if UnprintableStyle == UNPRINTABLE_STYLE_HIGHLIGHT {
if UnprintableStyle == UnprintableStyleHighlight {
stripped.WriteRune('?')
} else if UnprintableStyle == UNPRINTABLE_STYLE_WHITESPACE {
} else if UnprintableStyle == UnprintableStyleWhitespace {
stripped.WriteRune(' ')
} else {
panic(fmt.Errorf("Unsupported unprintable-style: %#v", UnprintableStyle))
Expand Down Expand Up @@ -128,12 +129,12 @@ func CellsFromString(s string, lineNumberOneBased *int) CellsWithTrailer {
}

case '�': // Go's broken-UTF8 marker
if UnprintableStyle == UNPRINTABLE_STYLE_HIGHLIGHT {
if UnprintableStyle == UnprintableStyleHighlight {
cells = append(cells, twin.Cell{
Rune: '?',
Style: styleUnprintable,
})
} else if UnprintableStyle == UNPRINTABLE_STYLE_WHITESPACE {
} else if UnprintableStyle == UnprintableStyleWhitespace {
cells = append(cells, twin.Cell{
Rune: '?',
Style: twin.StyleDefault,
Expand All @@ -150,12 +151,12 @@ func CellsFromString(s string, lineNumberOneBased *int) CellsWithTrailer {

default:
if !twin.Printable(token.Rune) {
if UnprintableStyle == UNPRINTABLE_STYLE_HIGHLIGHT {
if UnprintableStyle == UnprintableStyleHighlight {
cells = append(cells, twin.Cell{
Rune: '?',
Style: styleUnprintable,
})
} else if UnprintableStyle == UNPRINTABLE_STYLE_WHITESPACE {
} else if UnprintableStyle == UnprintableStyleWhitespace {
cells = append(cells, twin.Cell{
Rune: ' ',
Style: twin.StyleDefault,
Expand Down

0 comments on commit dc0243f

Please sign in to comment.