aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/account-wizard.go3
-rw-r--r--widgets/account.go6
-rw-r--r--widgets/aerc.go6
-rw-r--r--widgets/authinfo.go13
-rw-r--r--widgets/compose.go21
-rw-r--r--widgets/dirlist.go10
-rw-r--r--widgets/dirtree.go7
-rw-r--r--widgets/exline.go3
-rw-r--r--widgets/msglist.go3
-rw-r--r--widgets/msgviewer.go7
-rw-r--r--widgets/selector.go3
-rw-r--r--widgets/terminal.go41
12 files changed, 54 insertions, 69 deletions
diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go
index d7cda2d8..3673ed1c 100644
--- a/widgets/account-wizard.go
+++ b/widgets/account-wizard.go
@@ -689,8 +689,7 @@ func (wizard *AccountWizard) Focus(focus bool) {
func (wizard *AccountWizard) Event(event tcell.Event) bool {
interactive := wizard.getInteractive()
- switch event := event.(type) {
- case *tcell.EventKey:
+ if event, ok := event.(*tcell.EventKey); ok {
switch event.Key() {
case tcell.KeyUp:
fallthrough
diff --git a/widgets/account.go b/widgets/account.go
index e5087ef5..4f25f77a 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -362,11 +362,11 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
seen = true
}
if flag == models.RecentFlag {
- recent = recent + 1
+ recent++
}
}
if !seen {
- unseen = unseen + 1
+ unseen++
}
}
if accurate {
@@ -415,7 +415,7 @@ func (acct *AccountView) CheckMail() {
return
}
// Exclude selected mailbox, per IMAP specification
- exclude := append(acct.AccountConfig().CheckMailExclude, acct.dirlist.Selected())
+ exclude := append(acct.AccountConfig().CheckMailExclude, acct.dirlist.Selected()) //nolint:gocritic // intentional append to different slice
dirs := acct.dirlist.List()
dirs = acct.dirlist.FilterDirs(dirs, acct.AccountConfig().CheckMailInclude, false)
dirs = acct.dirlist.FilterDirs(dirs, exclude, true)
diff --git a/widgets/aerc.go b/widgets/aerc.go
index fb80c391..fbbf2aa8 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -456,10 +456,8 @@ func (aerc *Aerc) focus(item ui.Interactive) {
if ok {
interactive.Focus(false)
}
- } else {
- if ok {
- interactive.Focus(true)
- }
+ } else if ok {
+ interactive.Focus(true)
}
}
diff --git a/widgets/authinfo.go b/widgets/authinfo.go
index e773240e..a57d8a13 100644
--- a/widgets/authinfo.go
+++ b/widgets/authinfo.go
@@ -25,20 +25,17 @@ func (a *AuthInfo) Draw(ctx *ui.Context) {
defaultStyle := a.uiConfig.GetStyle(config.STYLE_DEFAULT)
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', defaultStyle)
var text string
- if a.authdetails == nil {
+ switch {
+ case a.authdetails == nil:
text = "(no header)"
ctx.Printf(0, 0, defaultStyle, text)
- } else if a.authdetails.Err != nil {
+ case a.authdetails.Err != nil:
style := a.uiConfig.GetStyle(config.STYLE_ERROR)
text = a.authdetails.Err.Error()
ctx.Printf(0, 0, style, text)
- } else {
+ default:
checkBounds := func(x int) bool {
- if x < ctx.Width() {
- return true
- } else {
- return false
- }
+ return x < ctx.Width()
}
setResult := func(result auth.Result) (string, tcell.Style) {
switch result {
diff --git a/widgets/compose.go b/widgets/compose.go
index b2a5e05c..30584294 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -527,11 +527,12 @@ func (c *Composer) Close() {
}
func (c *Composer) Bindings() string {
- if c.editor == nil {
+ switch c.editor {
+ case nil:
return "compose::review"
- } else if c.editor == c.focusable[c.focused] {
+ case c.focusable[c.focused]:
return "compose::editor"
- } else {
+ default:
return "compose"
}
}
@@ -798,10 +799,8 @@ func (c *Composer) resetReview() {
}
func (c *Composer) termEvent(event tcell.Event) bool {
- switch event := event.(type) {
- case *tcell.EventMouse:
- switch event.Buttons() {
- case tcell.Button1:
+ if event, ok := event.(*tcell.EventMouse); ok {
+ if event.Buttons() == tcell.Button1 {
c.FocusTerminal()
return true
}
@@ -1041,10 +1040,8 @@ func (he *headerEditor) Draw(ctx *ui.Context) {
}
func (he *headerEditor) MouseEvent(localX int, localY int, event tcell.Event) {
- switch event := event.(type) {
- case *tcell.EventMouse:
- switch event.Buttons() {
- case tcell.Button1:
+ if event, ok := event.(*tcell.EventMouse); ok {
+ if event.Buttons() == tcell.Button1 {
he.focused = true
}
@@ -1120,7 +1117,7 @@ func newReviewMessage(composer *Composer, err error) *reviewMessage {
inputs = append(inputs, config.FormatKeyStrokes(input))
}
actions = append(actions, fmt.Sprintf(" %-6s %-40s %s",
- strings.Join(inputs[:], ", "), name, cmd))
+ strings.Join(inputs, ", "), name, cmd))
}
spec := []ui.GridSpec{
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index df4e8192..03f9239a 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -270,11 +270,12 @@ func (dirlist *DirectoryList) getRUEString(name string) string {
}
di := msgStore.DirInfo
rueString := ""
- if di.Recent > 0 {
+ switch {
+ case di.Recent > 0:
rueString = fmt.Sprintf("%d/%d/%d", di.Recent, di.Unseen, di.Exists)
- } else if di.Unseen > 0 {
+ case di.Unseen > 0:
rueString = fmt.Sprintf("%d/%d", di.Unseen, di.Exists)
- } else if di.Exists > 0 {
+ case di.Exists > 0:
rueString = fmt.Sprintf("%d", di.Exists)
}
return rueString
@@ -358,8 +359,7 @@ func (dirlist *DirectoryList) drawScrollbar(ctx *ui.Context) {
}
func (dirlist *DirectoryList) MouseEvent(localX int, localY int, event tcell.Event) {
- switch event := event.(type) {
- case *tcell.EventMouse:
+ if event, ok := event.(*tcell.EventMouse); ok {
switch event.Buttons() {
case tcell.Button1:
clickedDir, ok := dirlist.Clicked(localX, localY)
diff --git a/widgets/dirtree.go b/widgets/dirtree.go
index 94868526..c3b80773 100644
--- a/widgets/dirtree.go
+++ b/widgets/dirtree.go
@@ -129,8 +129,7 @@ func (dt *DirectoryTree) Draw(ctx *ui.Context) {
}
func (dt *DirectoryTree) MouseEvent(localX int, localY int, event tcell.Event) {
- switch event := event.(type) {
- case *tcell.EventMouse:
+ if event, ok := event.(*tcell.EventMouse); ok {
switch event.Buttons() {
case tcell.Button1:
clickedDir, ok := dt.Clicked(localX, localY)
@@ -194,7 +193,7 @@ func (dt *DirectoryTree) NextPrev(delta int) {
}
for i := 0; i < delta; {
- newIdx = newIdx + step
+ newIdx += step
if newIdx < 0 {
newIdx = ndirs - 1
} else if newIdx >= ndirs {
@@ -378,7 +377,7 @@ func buildTree(node *types.Thread, stree [][]string, defaultUid uint32) {
m := make(map[string][][]string)
for _, branch := range stree {
if len(branch) > 1 {
- next := append(m[branch[0]], branch[1:])
+ next := append(m[branch[0]], branch[1:]) //nolint:gocritic // intentional append to different slice
m[branch[0]] = next
}
}
diff --git a/widgets/exline.go b/widgets/exline.go
index e172dd81..d43bdecb 100644
--- a/widgets/exline.go
+++ b/widgets/exline.go
@@ -72,8 +72,7 @@ func (ex *ExLine) Focus(focus bool) {
}
func (ex *ExLine) Event(event tcell.Event) bool {
- switch event := event.(type) {
- case *tcell.EventKey:
+ if event, ok := event.(*tcell.EventKey); ok {
switch event.Key() {
case tcell.KeyEnter, tcell.KeyCtrlJ:
cmd := ex.input.String()
diff --git a/widgets/msglist.go b/widgets/msglist.go
index 96b91cf3..e431c2e5 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -288,8 +288,7 @@ func (ml *MessageList) drawScrollbar(ctx *ui.Context) {
}
func (ml *MessageList) MouseEvent(localX int, localY int, event tcell.Event) {
- switch event := event.(type) {
- case *tcell.EventMouse:
+ if event, ok := event.(*tcell.EventMouse); ok {
switch event.Buttons() {
case tcell.Button1:
if ml.aerc == nil {
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 115eb3f1..4d70e93d 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -182,7 +182,7 @@ func enumerateParts(acct *AccountView, conf *config.AercConfig,
) ([]*PartViewer, error) {
var parts []*PartViewer
for i, part := range body.Parts {
- curindex := append(index, i+1)
+ curindex := append(index, i+1) //nolint:gocritic // intentional append to different slice
if part.MIMEType == "multipart" {
// Multipart meta-parts are faked
pv := &PartViewer{part: part}
@@ -437,8 +437,7 @@ func (ps *PartSwitcher) Draw(ctx *ui.Context) {
}
func (ps *PartSwitcher) MouseEvent(localX int, localY int, event tcell.Event) {
- switch event := event.(type) {
- case *tcell.EventMouse:
+ if event, ok := event.(*tcell.EventMouse); ok {
switch event.Buttons() {
case tcell.Button1:
height := len(ps.parts)
@@ -785,7 +784,7 @@ func newNoFilterConfigured(pv *PartViewer) *ui.Grid {
inputs = append(inputs, config.FormatKeyStrokes(input))
}
actions = append(actions, fmt.Sprintf(" %-6s %-29s %s",
- strings.Join(inputs[:], ", "), name, cmd))
+ strings.Join(inputs, ", "), name, cmd))
}
spec := []ui.GridSpec{
diff --git a/widgets/selector.go b/widgets/selector.go
index 71224c9b..8a1a1623 100644
--- a/widgets/selector.go
+++ b/widgets/selector.go
@@ -132,8 +132,7 @@ func (sel *Selector) Focus(focus bool) {
}
func (sel *Selector) Event(event tcell.Event) bool {
- switch event := event.(type) {
- case *tcell.EventKey:
+ if event, ok := event.(*tcell.EventKey); ok {
switch event.Key() {
case tcell.KeyCtrlH:
fallthrough
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))
}