Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change table view #17

Merged
merged 3 commits into from
Apr 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions trv/trv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -258,20 +269,20 @@ 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.Comment).
SetTextColor(tcell.ColorBeige).
SetAlign(tview.AlignLeft))
cell := t.TableViewer.GetCell(row, 0)
cell.SetReference(Info{Table: r, Column: c})
row++
}
}
}
Expand Down
Loading