Add working tview, add working load ond Tables, remove giu
This commit is contained in:
@@ -8,14 +8,11 @@ import (
|
||||
|
||||
engine "git.pablu.de/pablu/sqv-engine"
|
||||
"github.com/charmbracelet/bubbles/table"
|
||||
"github.com/charmbracelet/bubbles/textarea"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
var baseStyle = lipgloss.NewStyle().
|
||||
BorderStyle(lipgloss.NormalBorder()).
|
||||
BorderForeground(lipgloss.Color("240"))
|
||||
|
||||
func tabBorderWithBottom(left, middle, right string) lipgloss.Border {
|
||||
border := lipgloss.RoundedBorder()
|
||||
border.BottomLeft = left
|
||||
@@ -37,6 +34,7 @@ var (
|
||||
type model struct {
|
||||
tables []table.Model
|
||||
tableNames []string
|
||||
textarea textarea.Model
|
||||
|
||||
currTable int
|
||||
}
|
||||
@@ -97,7 +95,13 @@ func (m model) View() string {
|
||||
row := lipgloss.JoinHorizontal(lipgloss.Top, renderedTabs...)
|
||||
doc.WriteString(row)
|
||||
doc.WriteString("\n")
|
||||
doc.WriteString(windowStyle.Width((lipgloss.Width(row) - windowStyle.GetHorizontalFrameSize())).Render(m.tables[m.currTable].View()))
|
||||
windowWidth := (lipgloss.Width(row) - windowStyle.GetHorizontalFrameSize())
|
||||
doc.WriteString(windowStyle.Width(windowWidth).Render(m.tables[m.currTable].View()))
|
||||
doc.WriteString("\n")
|
||||
|
||||
// Is this correct??
|
||||
m.textarea.SetWidth(windowWidth)
|
||||
doc.WriteString(windowStyle.Width(windowWidth).Render(m.textarea.View()))
|
||||
|
||||
return docStyle.Render(doc.String())
|
||||
// return baseStyle.Render(m.table.View()) + "\n"
|
||||
@@ -113,7 +117,7 @@ func convertToViewTable(m *engine.Manager) ([]string, []table.Model) {
|
||||
for i, column := range t.Columns {
|
||||
columns[i] = table.Column{
|
||||
Title: column.Name,
|
||||
Width: 10,
|
||||
Width: max(lipgloss.Width(column.Name), 10),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +138,7 @@ func convertToViewTable(m *engine.Manager) ([]string, []table.Model) {
|
||||
table.WithColumns(columns),
|
||||
table.WithRows(rows),
|
||||
table.WithFocused(true),
|
||||
table.WithHeight(7),
|
||||
table.WithHeight(25),
|
||||
)
|
||||
|
||||
s := table.DefaultStyles()
|
||||
@@ -167,7 +171,14 @@ func main() {
|
||||
|
||||
tableNames, tables := convertToViewTable(m)
|
||||
|
||||
p := tea.NewProgram(model{tables: tables, tableNames: tableNames}, tea.WithAltScreen())
|
||||
ta := textarea.New()
|
||||
ta.Placeholder = "select * from ?"
|
||||
ta.Focus()
|
||||
|
||||
ta.Prompt = "| "
|
||||
ta.CharLimit = 280
|
||||
|
||||
p := tea.NewProgram(model{tables: tables, tableNames: tableNames, textarea: ta}, tea.WithAltScreen())
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatalf("Alas, theres been an error: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user