WIP BAK
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
@@ -33,8 +34,10 @@ type mainModel struct {
|
|||||||
table *table.Table
|
table *table.Table
|
||||||
editor textarea.Model
|
editor textarea.Model
|
||||||
picker list.Model
|
picker list.Model
|
||||||
|
}
|
||||||
|
|
||||||
debugMsgs []string
|
type tableModel struct {
|
||||||
|
Table *table.Table
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -59,7 +62,13 @@ func newMainModerl(manager *engine.Manager) mainModel {
|
|||||||
|
|
||||||
ed.ShowLineNumbers = false
|
ed.ShowLineNumbers = false
|
||||||
|
|
||||||
ta := table.New().Border(lipgloss.NormalBorder())
|
ta := table.New().
|
||||||
|
Border(lipgloss.NormalBorder()).
|
||||||
|
BorderBottom(false).
|
||||||
|
BorderTop(false).
|
||||||
|
BorderLeft(false).
|
||||||
|
BorderRight(false).
|
||||||
|
Wrap(false)
|
||||||
|
|
||||||
li := list.New(nil, list.NewDefaultDelegate(), 0, 0)
|
li := list.New(nil, list.NewDefaultDelegate(), 0, 0)
|
||||||
li.Title = "Table Picker"
|
li.Title = "Table Picker"
|
||||||
@@ -77,7 +86,6 @@ func (m mainModel) Init() tea.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m mainModel) GetTableDefinitions() tea.Msg {
|
func (m mainModel) GetTableDefinitions() tea.Msg {
|
||||||
|
|
||||||
tables := m.manager.GetTables()
|
tables := m.manager.GetTables()
|
||||||
tableNames := make([]list.Item, len(tables))
|
tableNames := make([]list.Item, len(tables))
|
||||||
|
|
||||||
@@ -150,8 +158,6 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
} else {
|
} else {
|
||||||
m.focused = EDITOR
|
m.focused = EDITOR
|
||||||
}
|
}
|
||||||
case "j":
|
|
||||||
m.table.Offset(50)
|
|
||||||
case "ctrl+e":
|
case "ctrl+e":
|
||||||
if m.focused == PICKER {
|
if m.focused == PICKER {
|
||||||
m.focused = m.lastFocused
|
m.focused = m.lastFocused
|
||||||
@@ -191,6 +197,8 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch m.focused {
|
switch m.focused {
|
||||||
|
case TABLE:
|
||||||
|
|
||||||
case EDITOR:
|
case EDITOR:
|
||||||
m.editor.Focus()
|
m.editor.Focus()
|
||||||
m.editor, edCmd = m.editor.Update(msg)
|
m.editor, edCmd = m.editor.Update(msg)
|
||||||
@@ -213,7 +221,7 @@ func (m mainModel) updateStyles(width, height int) mainModel {
|
|||||||
m.editor.SetWidth(m.width - v)
|
m.editor.SetWidth(m.width - v)
|
||||||
m.editor.SetHeight(int(editorHeight))
|
m.editor.SetHeight(int(editorHeight))
|
||||||
|
|
||||||
m.table.Width(m.width - v)
|
m.table.Width(m.width)
|
||||||
m.table.Height(int(topHeight) - h*2)
|
m.table.Height(int(topHeight) - h*2)
|
||||||
|
|
||||||
m.picker.SetSize(m.width*7/10, m.height*7/10)
|
m.picker.SetSize(m.width*7/10, m.height*7/10)
|
||||||
@@ -226,30 +234,30 @@ func (m mainModel) View() string {
|
|||||||
view, editor string
|
view, editor string
|
||||||
)
|
)
|
||||||
|
|
||||||
h, _ := defaultStyle.GetFrameSize()
|
h, v := defaultStyle.GetFrameSize()
|
||||||
topHeight := (m.height * 3 / 4) - h
|
topHeight := (m.height * 3 / 4) - h
|
||||||
editorHeight := (m.height * 1 / 4) - h
|
width := m.width - v
|
||||||
switch m.focused {
|
switch m.focused {
|
||||||
case EDITOR:
|
case EDITOR:
|
||||||
view = defaultStyle.
|
view = defaultStyle.
|
||||||
Height(topHeight).
|
Height(topHeight).
|
||||||
|
Width(width).
|
||||||
Render(m.table.Render())
|
Render(m.table.Render())
|
||||||
editor = focusedStyle.
|
editor = focusedStyle.
|
||||||
Height(editorHeight).
|
|
||||||
Render(m.editor.View())
|
Render(m.editor.View())
|
||||||
case TABLE:
|
case TABLE:
|
||||||
view = focusedStyle.
|
view = focusedStyle.
|
||||||
Height(topHeight).
|
Height(topHeight).
|
||||||
|
Width(width).
|
||||||
Render(m.table.Render())
|
Render(m.table.Render())
|
||||||
editor = defaultStyle.
|
editor = defaultStyle.
|
||||||
Height(editorHeight).
|
|
||||||
Render(m.editor.View())
|
Render(m.editor.View())
|
||||||
case PICKER:
|
case PICKER:
|
||||||
view = defaultStyle.
|
view = defaultStyle.
|
||||||
Height(topHeight).
|
Height(topHeight).
|
||||||
|
Width(width).
|
||||||
Render(m.table.Render())
|
Render(m.table.Render())
|
||||||
editor = defaultStyle.
|
editor = defaultStyle.
|
||||||
Height(editorHeight).
|
|
||||||
Render(m.editor.View())
|
Render(m.editor.View())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +273,13 @@ func (m mainModel) View() string {
|
|||||||
return main
|
return main
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
path = flag.String("path", "db.sqlite", "Path to sqlite db")
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
f, err := tea.LogToFile("debug.log", "debug")
|
f, err := tea.LogToFile("debug.log", "debug")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("fatal:", err)
|
fmt.Println("fatal:", err)
|
||||||
@@ -276,7 +290,7 @@ func main() {
|
|||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
log.SetOutput(f)
|
log.SetOutput(f)
|
||||||
|
|
||||||
m, err := engine.NewManager("../vdcmp/db.sqlite")
|
m, err := engine.NewManager(*path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("fatal:", err)
|
fmt.Println("fatal:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user