From 978d35d356e8752bdd272884df48a6289d88b40a Mon Sep 17 00:00:00 2001 From: Moritz Poldrack Date: Sun, 31 Jul 2022 14:32:48 +0200 Subject: lint: homogenize operations and minor fixes (gocritic) Apply GoDoc comment policy (comments for humans should have a space after the //; machine-readable comments shouldn't) Use strings.ReplaceAll instead of strings.Replace when appropriate Remove if/else chains by replacing them with switches Use short assignment/increment notation Replace single case switches with if statements Combine else and if when appropriate Signed-off-by: Moritz Poldrack Acked-by: Robin Jarry --- widgets/terminal.go | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'widgets/terminal.go') diff --git a/widgets/terminal.go b/widgets/terminal.go index 293481de..55a849ab 100644 --- a/widgets/terminal.go +++ b/widgets/terminal.go @@ -343,8 +343,7 @@ func (term *Terminal) Draw(ctx *ui.Context) { } func (term *Terminal) MouseEvent(localX int, localY int, event tcell.Event) { - switch event := event.(type) { - case *tcell.EventMouse: + if event, ok := event.(*tcell.EventMouse); ok { if term.OnEvent != nil { if term.OnEvent(event) { return @@ -399,22 +398,20 @@ func (term *Terminal) Event(event tcell.Event) bool { if term.closed { return false } - switch event := event.(type) { - case *tcell.EventKey: + if event, ok := event.(*tcell.EventKey); ok { if event.Key() == tcell.KeyRune { term.vterm.KeyboardUnichar( event.Rune(), convertMods(event.Modifiers())) - } else { - if key, ok := keyMap[event.Key()]; ok { - if key.Key == vterm.KeyNone { - term.vterm.KeyboardUnichar( - key.Rune, key.Mod) - } else if key.Mod == vterm.ModNone { - term.vterm.KeyboardKey(key.Key, - convertMods(event.Modifiers())) - } else { - term.vterm.KeyboardKey(key.Key, key.Mod) - } + } else if key, ok := keyMap[event.Key()]; ok { + switch { + case key.Key == vterm.KeyNone: + term.vterm.KeyboardUnichar( + key.Rune, key.Mod) + case key.Mod == vterm.ModNone: + term.vterm.KeyboardKey(key.Key, + convertMods(event.Modifiers())) + default: + term.vterm.KeyboardKey(key.Key, key.Mod) } } term.flushTerminal() @@ -432,19 +429,21 @@ func (term *Terminal) styleFromCell(cell *vterm.ScreenCell) tcell.Style { bg tcell.Color fg tcell.Color ) - if background.IsDefaultBg() { + switch { + case background.IsDefaultBg(): bg = tcell.ColorDefault - } else if background.IsIndexed() { + case background.IsIndexed(): bg = tcell.Color(tcell.PaletteColor(int(background.GetIndex()))) - } else if background.IsRgb() { + case background.IsRgb(): r, g, b := background.GetRGB() bg = tcell.NewRGBColor(int32(r), int32(g), int32(b)) } - if foreground.IsDefaultFg() { + switch { + case foreground.IsDefaultFg(): fg = tcell.ColorDefault - } else if foreground.IsIndexed() { + case foreground.IsIndexed(): fg = tcell.Color(tcell.PaletteColor(int(foreground.GetIndex()))) - } else if foreground.IsRgb() { + case foreground.IsRgb(): r, g, b := foreground.GetRGB() fg = tcell.NewRGBColor(int32(r), int32(g), int32(b)) } -- cgit