Skip to content

Commit

Permalink
Show modal while running linters
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed May 6, 2020
1 parent 6fe1383 commit bcc0a31
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
25 changes: 13 additions & 12 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,20 @@ func (g *Gui) modal(p tview.Primitive, width, height int) *tview.Grid {
}

// message shows the given message as a modal.
func (g *Gui) message(message, doneLabel string, doneFunc func()) {
func (g *Gui) message(message, doneLabel string) {
modal := tview.NewModal().
SetText(message).
SetBackgroundColor(tcell.ColorBlack).
AddButtons([]string{doneLabel}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == doneLabel {
doneFunc()
}
g.switchPage(modalPageName, mainPageName)
})

g.pages.AddAndSwitchToPage("modal", g.modal(modal, 150, 60), true).ShowPage(mainPageName)
SetBackgroundColor(tcell.ColorBlack)

if doneLabel != "" {
modal.AddButtons([]string{doneLabel}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == doneLabel {
g.switchPage(modalPageName, mainPageName)
}
})
}
g.pages.AddAndSwitchToPage(modalPageName, g.modal(modal, 150, 60), true).ShowPage(mainPageName)
}

// registerPath adds path to golangci-lint runner as an arg.
Expand All @@ -154,7 +155,7 @@ func (g *Gui) enableLinter(node *tview.TreeNode, linter *config.Linter) {

func (g *Gui) disableLinter(node *tview.TreeNode, linter *config.Linter) {
if err := g.runner.DisableLinter(linter.Name()); err != nil {
g.message(err.Error(), "Enter", func() {})
g.message(err.Error(), "Enter")
return
}
node.SetColor(item.DefaultLinterColor)
Expand Down
33 changes: 21 additions & 12 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,26 @@ func (g *Gui) grobalKeybind(event *tcell.EventKey) {
case 'q':
g.application.Stop()
case 'r':
issues, err := g.runner.Run()
if err != nil {
g.resultsItem.ShowMessage(err.Error())
return
}
if len(issues) == 0 {
g.resultsItem.ShowMessage("no issues found")
} else {
g.resultsItem.SetLatestIssues(issues)
g.resultsItem.ShowLatestIssues()
g.switchPanel(g.resultsItem)
}
g.message("running linters...", "")

go func() {
issues, err := g.runner.Run()
g.switchPage(modalPageName, mainPageName)
if err != nil {
g.resultsItem.ShowMessage(err.Error())
g.application.Draw()
return
}

if len(issues) == 0 {
g.resultsItem.ShowMessage("no issues found")
} else {
g.resultsItem.SetLatestIssues(issues)
g.resultsItem.ShowLatestIssues()
g.switchPanel(g.resultsItem)
}
g.application.Draw()
}()

}
}

0 comments on commit bcc0a31

Please sign in to comment.