From 75590982a2dac72ce4e67b8cc30e7c827a5dbd1f Mon Sep 17 00:00:00 2001 From: harakeishi Date: Sun, 21 Apr 2024 13:51:07 +0900 Subject: [PATCH 1/3] =?UTF-8?q?List=E3=81=8B=E3=82=89table=E3=81=B8?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trv/trv.go | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/trv/trv.go b/trv/trv.go index f168991..e89e7b1 100644 --- a/trv/trv.go +++ b/trv/trv.go @@ -16,7 +16,7 @@ type Trv struct { DB DB Tables []Table SourceSelecter *tview.DropDown - TableViewer *tview.List + TableViewer *tview.Table Searcher *tview.InputField Pages *tview.Pages InfoLayout *tview.Grid @@ -29,6 +29,11 @@ type Trv struct { ErrorWindow *tview.Modal } +type Info struct { + Table Table + Column Column +} + /* Prepare to start trv. Specifically, loading the configuration, loading the data, and preparing the TUI. @@ -141,9 +146,15 @@ func (t *Trv) addDropdownOption() error { // set table view func (t *Trv) setTableViewer() { - t.TableViewer = tview.NewList() + t.TableViewer = tview.NewTable().SetBorders(false) t.TableViewer.SetTitle("Result(Ctrl+r)") t.TableViewer.SetBorder(true) + t.TableViewer.SetSelectable(true, false) + t.TableViewer.SetSelectedFunc(func(row int, column int) { + cell := t.TableViewer.GetCell(row, column) + info := cell.GetReference().(Info) + t.InfoText.SetText(fmt.Sprintf("table name: %s\ndetails: %s\n\ncolumn: %s\ntype: %s\ncomment: %s", info.Table.Name, info.Table.Description, info.Column.Name, info.Column.Type, info.Column.Comment)) + }) } // set search box @@ -258,23 +269,28 @@ func (t *Trv) setLayout() { // Filter and display data func (t *Trv) filterList() { target := t.Searcher.GetText() + row := 0 t.TableViewer.Clear() for _, r := range t.Tables { for i, c := range r.Columns { if strings.Contains(strings.ToLower(r.getFullName(i)), strings.ToLower(target)) || target == "" { - t.TableViewer.AddItem(r.getFullName(i), c.Comment, 1, func() {}) - t.TableViewer.SetSelectedFunc(func(i int, s1, s2 string, r rune) { - for _, v := range t.Tables { - for a, b := range v.Columns { - if v.getFullName(a) == s1 { - t.InfoText.SetText(fmt.Sprintf("table name: %s\ndetails: %s\n\ncolumn: %s\ntype: %s\ncomment: %s", v.Name, v.Description, b.Name, b.Type, b.Comment)) - } - } - } - }) + t.TableViewer.SetCell(row, 0, tview.NewTableCell(r.getFullName(i)). + SetTextColor(tcell.ColorWhite). + SetAlign(tview.AlignLeft)) + t.TableViewer.SetCell(row, 1, tview.NewTableCell(c.Name). + SetTextColor(tcell.ColorBeige). + SetAlign(tview.AlignLeft)) + cell := t.TableViewer.GetCell(row, 0) + cell.SetReference(Info{Table: r, Column: c}) + row++ } } } + if t.TableViewer.GetRowCount() == 0 { + t.TableViewer.SetCell(row, 0, tview.NewTableCell("No result"). + SetTextColor(tcell.ColorWhite). + SetAlign(tview.AlignLeft)) + } } // drawing From cfd140ecc41306e92bd0162a7dfec17f5729e5de Mon Sep 17 00:00:00 2001 From: harakeishi Date: Sun, 21 Apr 2024 13:51:38 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trv/trv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trv/trv.go b/trv/trv.go index e89e7b1..914de3d 100644 --- a/trv/trv.go +++ b/trv/trv.go @@ -277,7 +277,7 @@ func (t *Trv) filterList() { t.TableViewer.SetCell(row, 0, tview.NewTableCell(r.getFullName(i)). SetTextColor(tcell.ColorWhite). SetAlign(tview.AlignLeft)) - t.TableViewer.SetCell(row, 1, tview.NewTableCell(c.Name). + t.TableViewer.SetCell(row, 1, tview.NewTableCell(c.Comment). SetTextColor(tcell.ColorBeige). SetAlign(tview.AlignLeft)) cell := t.TableViewer.GetCell(row, 0) From d50038ba640e2f3bae9131ee4bfa660e3e8dbc0f Mon Sep 17 00:00:00 2001 From: harakeishi Date: Sun, 21 Apr 2024 13:57:36 +0900 Subject: [PATCH 3/3] remove --- trv/trv.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/trv/trv.go b/trv/trv.go index 914de3d..22251c9 100644 --- a/trv/trv.go +++ b/trv/trv.go @@ -286,11 +286,6 @@ func (t *Trv) filterList() { } } } - if t.TableViewer.GetRowCount() == 0 { - t.TableViewer.SetCell(row, 0, tview.NewTableCell("No result"). - SetTextColor(tcell.ColorWhite). - SetAlign(tview.AlignLeft)) - } } // drawing