aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/terminal.go
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-07-31 14:32:48 +0200
committerRobin Jarry <robin@jarry.cc>2022-08-04 21:58:01 +0200
commit978d35d356e8752bdd272884df48a6289d88b40a (patch)
tree3910243e688ef503159d07ce44b22cfea5d6c6fd /widgets/terminal.go
parentc882cf9960be691fe55617b87cdfcfbabd5d5557 (diff)
downloadaerc-978d35d356e8752bdd272884df48a6289d88b40a.tar.gz
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 <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets/terminal.go')
-rw-r--r--widgets/terminal.go41
1 files changed, 20 insertions, 21 deletions
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))
}