Skip to content

Commit

Permalink
Merge pull request #7 from harakeishi/add_error_window
Browse files Browse the repository at this point in the history
エラーウィンドウの追加
  • Loading branch information
harakeishi committed Nov 11, 2022
2 parents 524af33 + e09d4fc commit 4893b21
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion trv/trv.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ type Trv struct {
App *tview.Application
Layout *tview.Grid
Modal tview.Primitive
ErrorModal tview.Primitive
Form *tview.Form
ErrorWindow *tview.Modal
}

/*
Expand Down Expand Up @@ -51,9 +53,11 @@ func (t *Trv) Init() error {
t.setLayout()
t.setForm()
t.setModal()
t.setErrorModal()
t.setPages()

t.Pages.HidePage("modal")
t.Pages.HidePage("error")

t.App.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
switch event.Key() {
Expand Down Expand Up @@ -93,6 +97,12 @@ func (t *Trv) setSourceSelecter() error {
return
}
t.DB, err = t.Config.Source[index].setDbData()
if err != nil {
t.ErrorWindow.SetText(fmt.Sprintf("-ERROR-\n%s", err))
t.ErrorWindow.Box.SetTitle("ERROR")
t.Pages.ShowPage("error")
return
}
t.Tables = t.DB.tables
t.filterList()
t.App.SetFocus(t.Searcher)
Expand Down Expand Up @@ -197,11 +207,28 @@ func (t *Trv) setModal() {
AddItem(t.Form, 0, 0, 4, 4, 0, 0, true)
}

func (t *Trv) setErrorModal() {
t.ErrorWindow = tview.NewModal().
SetText("Do you want to quit the application?").
AddButtons([]string{"Quit"}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Quit" {
t.App.Stop()
}
})

t.ErrorModal = tview.NewGrid().
SetColumns(0, 4, 0).
SetRows(0, 4, 0).
AddItem(t.ErrorWindow, 0, 0, 4, 4, 0, 0, true)
}

// set pages
func (t *Trv) setPages() {
t.Pages = tview.NewPages().
AddPage("background", t.Layout, true, true).
AddPage("modal", t.Modal, true, true)
AddPage("modal", t.Modal, true, true).
AddPage("error", t.ErrorModal, true, true)
}

// Set the layout of the area displaying information about the column
Expand Down

0 comments on commit 4893b21

Please sign in to comment.