removing the old test UI codes
This commit is contained in:
+2
-4
@@ -1,7 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"esdi/t"
|
||||
"esdi/tui"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -98,9 +98,7 @@ import (
|
||||
|
||||
func replCmdAction(cmd *cobra.Command, args []string) {
|
||||
// repl.Run()
|
||||
// tui.Run()
|
||||
// teatui.Run()
|
||||
t.Run()
|
||||
tui.Run()
|
||||
}
|
||||
|
||||
// removeLabelCmd represents the removeLabel command
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
// Package t
|
||||
package t
|
||||
|
||||
import "esdi/t/internal/tui"
|
||||
|
||||
func Run() error {
|
||||
app := tui.NewTUI()
|
||||
return app.Start()
|
||||
}
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
// Package teatui
|
||||
package teatui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type model struct {
|
||||
choices []string
|
||||
cursor int
|
||||
selected map[int]struct{}
|
||||
}
|
||||
|
||||
func initialModel() model {
|
||||
return model{
|
||||
choices: []string{"Buy carrots", "Buy celery", "Buy holhrabi"},
|
||||
selected: make(map[int]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
|
||||
// Is it a key press?
|
||||
case tea.KeyMsg:
|
||||
|
||||
// Cool, what was the actual key pressed?
|
||||
switch msg.String() {
|
||||
|
||||
// These keys should exit the program.
|
||||
case "ctrl+c", "q":
|
||||
return m, tea.Quit
|
||||
|
||||
// The "up" and "k" keys move the cursor up
|
||||
case "up", "k":
|
||||
if m.cursor > 0 {
|
||||
m.cursor--
|
||||
}
|
||||
|
||||
// The "down" and "j" keys move the cursor down
|
||||
case "down", "j":
|
||||
if m.cursor < len(m.choices)-1 {
|
||||
m.cursor++
|
||||
}
|
||||
|
||||
// The "enter" key and the spacebar (a literal space) toggle
|
||||
// the selected state for the item that the cursor is pointing at.
|
||||
case "enter", " ":
|
||||
_, ok := m.selected[m.cursor]
|
||||
if ok {
|
||||
delete(m.selected, m.cursor)
|
||||
} else {
|
||||
m.selected[m.cursor] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the updated model to the Bubble Tea runtime for processing.
|
||||
// Note that we're not returning a command.
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m model) View() string {
|
||||
// The header
|
||||
s := "What should we buy at the market?\n\n"
|
||||
|
||||
// Iterate over our choices
|
||||
for i, choice := range m.choices {
|
||||
|
||||
// Is the cursor pointing at this choice?
|
||||
cursor := " " // no cursor
|
||||
if m.cursor == i {
|
||||
cursor = ">" // cursor!
|
||||
}
|
||||
|
||||
// Is this choice selected?
|
||||
checked := " " // not selected
|
||||
if _, ok := m.selected[i]; ok {
|
||||
checked = "x" // selected!
|
||||
}
|
||||
|
||||
// Render the row
|
||||
s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, choice)
|
||||
}
|
||||
|
||||
// The footer
|
||||
s += "\nPress q to quit.\n"
|
||||
|
||||
// Send the UI for rendering
|
||||
return s
|
||||
}
|
||||
|
||||
func Run() {
|
||||
p := tea.NewProgram(initialModel(), tea.WithAltScreen())
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Printf("Alas, there's been an error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package tui
|
||||
|
||||
import "github.com/rivo/tview"
|
||||
|
||||
func createWindow(t *tui, x, y, width, height, title string, tree *tview.TreeView) {
|
||||
t.log("x : %s\n", x)
|
||||
t.log("y : %s\n", y)
|
||||
t.log("width : %s\n", width)
|
||||
t.log("height: %s\n", height)
|
||||
t.log("title : %s\n", title)
|
||||
|
||||
newWindow := tview.NewTreeNode(title)
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
type cDashWinLayout struct {
|
||||
tree *tview.TreeView
|
||||
}
|
||||
|
||||
func createNewWindowForm(t *tui, dp *devicePane, tree *tview.TreeView, f *tview.Pages) {
|
||||
x0 := tview.NewInputField().SetLabel("x")
|
||||
y0 := tview.NewInputField().SetLabel("y")
|
||||
width := tview.NewInputField().SetLabel("width")
|
||||
height := tview.NewInputField().SetLabel("height")
|
||||
title := tview.NewInputField().SetLabel("title")
|
||||
|
||||
form := tview.NewForm().
|
||||
AddFormItem(x0).
|
||||
AddFormItem(y0).
|
||||
AddFormItem(width).
|
||||
AddFormItem(height).
|
||||
AddFormItem(title).
|
||||
AddButton("Create", func() {
|
||||
createWindow(
|
||||
t,
|
||||
x0.GetText(),
|
||||
y0.GetText(),
|
||||
width.GetText(),
|
||||
height.GetText(),
|
||||
title.GetText(),
|
||||
tree,
|
||||
)
|
||||
})
|
||||
|
||||
form.SetBorder(true).
|
||||
SetTitle("new window form").
|
||||
SetTitleAlign(tview.AlignLeft).
|
||||
SetInputCapture(func(ev *tcell.EventKey) *tcell.EventKey {
|
||||
switch ev.Key() {
|
||||
case tcell.KeyEscape:
|
||||
f.RemovePage("new-window-form")
|
||||
t.app.SetFocus(tree)
|
||||
}
|
||||
|
||||
return ev
|
||||
})
|
||||
|
||||
f.RemovePage("new-window-form")
|
||||
f.AddPage("new-window-form", form, true, true)
|
||||
|
||||
t.app.SetFocus(form)
|
||||
}
|
||||
|
||||
func createLayoutUIFormKeybinds(t *tui, dp *devicePane,
|
||||
tree *tview.TreeView, f *tview.Pages) func(*tcell.EventKey) *tcell.EventKey {
|
||||
return func(ev *tcell.EventKey) *tcell.EventKey {
|
||||
switch ev.Key() {
|
||||
case tcell.KeyEscape:
|
||||
t.app.SetFocus(dp.apiPane)
|
||||
}
|
||||
|
||||
switch ev.Rune() {
|
||||
case 'N':
|
||||
// Create a new screen
|
||||
case 'n':
|
||||
// Create a new window
|
||||
t.log("calling new window form\n")
|
||||
createNewWindowForm(t, dp, tree, f)
|
||||
case 'x':
|
||||
// Delete selected window
|
||||
case 'm':
|
||||
// Go into move mode
|
||||
case 'e':
|
||||
// Go into edit mode
|
||||
}
|
||||
|
||||
return ev
|
||||
}
|
||||
}
|
||||
|
||||
func createLayoutUI(t *tui, dp *devicePane) {
|
||||
layoutTree := tview.NewTreeView()
|
||||
actionPages := tview.NewPages()
|
||||
|
||||
flex := tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(layoutTree, 0, 1, true).
|
||||
AddItem(actionPages, 0, 2, true)
|
||||
|
||||
root := tview.NewTreeNode("Root").SetColor(tcell.ColorRed)
|
||||
layoutTree.SetRoot(root).SetCurrentNode(root)
|
||||
layoutTree.
|
||||
SetBorder(true).
|
||||
SetTitle("Tree").
|
||||
SetTitleAlign(tview.AlignLeft).
|
||||
SetInputCapture(createLayoutUIFormKeybinds(t, dp, layoutTree, actionPages))
|
||||
|
||||
dp.actionPane.RemovePage("action")
|
||||
dp.actionPane.AddPage("action", flex, true, true)
|
||||
|
||||
t.app.SetFocus(layoutTree)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Package controllers defines our controller layer
|
||||
package controllers
|
||||
|
||||
type MainController struct {
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"esdi/t/internal/events"
|
||||
"esdi/t/internal/models"
|
||||
"esdi/t/internal/ui"
|
||||
"esdi/tui/internal/events"
|
||||
"esdi/tui/internal/models"
|
||||
"esdi/tui/internal/ui"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"esdi/t/internal/models"
|
||||
"esdi/tui/internal/models"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
@@ -2,11 +2,11 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"esdi/t/internal/controllers"
|
||||
dom "esdi/t/internal/dom"
|
||||
"esdi/t/internal/events"
|
||||
"esdi/t/internal/ui"
|
||||
"esdi/t/internal/views"
|
||||
"esdi/tui/internal/controllers"
|
||||
"esdi/tui/internal/dom"
|
||||
"esdi/tui/internal/events"
|
||||
"esdi/tui/internal/ui"
|
||||
"esdi/tui/internal/views"
|
||||
"fmt"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@@ -1,8 +1,8 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"esdi/t/internal/dom"
|
||||
"esdi/t/internal/ui"
|
||||
"esdi/tui/internal/dom"
|
||||
"esdi/tui/internal/ui"
|
||||
"slices"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
@@ -1,10 +1,10 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"esdi/t/internal/controllers"
|
||||
"esdi/t/internal/dom"
|
||||
"esdi/t/internal/events"
|
||||
"esdi/t/internal/ui"
|
||||
"esdi/tui/internal/controllers"
|
||||
"esdi/tui/internal/dom"
|
||||
"esdi/tui/internal/events"
|
||||
"esdi/tui/internal/ui"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
@@ -4,9 +4,9 @@ package views
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"esdi/t/internal/controllers"
|
||||
"esdi/t/internal/dom"
|
||||
"esdi/t/internal/ui"
|
||||
"esdi/tui/internal/controllers"
|
||||
"esdi/tui/internal/dom"
|
||||
"esdi/tui/internal/ui"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
@@ -1,8 +1,8 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"esdi/t/internal/dom"
|
||||
"esdi/t/internal/ui"
|
||||
"esdi/tui/internal/dom"
|
||||
"esdi/tui/internal/ui"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
@@ -1,20 +0,0 @@
|
||||
package tui
|
||||
|
||||
import "github.com/rivo/tview"
|
||||
|
||||
type ui struct {
|
||||
Elements map[string]*view
|
||||
}
|
||||
|
||||
func NewUI() *ui {
|
||||
return &ui{
|
||||
Elements: make(map[string]*view),
|
||||
}
|
||||
}
|
||||
|
||||
type view struct {
|
||||
ID string
|
||||
Title string
|
||||
Root tview.Primitive
|
||||
Children []*view
|
||||
}
|
||||
+3
-120
@@ -1,126 +1,9 @@
|
||||
// Package tui
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
type layout struct {
|
||||
root *tview.Flex
|
||||
}
|
||||
|
||||
type devicePane struct {
|
||||
apiPane *tview.List
|
||||
actionPane *tview.Pages
|
||||
flexPane *tview.Flex
|
||||
}
|
||||
|
||||
func NewDevicePane(t *tui) *devicePane {
|
||||
dp := &devicePane{}
|
||||
|
||||
dp.actionPane = tview.NewPages()
|
||||
|
||||
dp.apiPane = tview.NewList().
|
||||
AddItem("destroy-window", "", 0, func() {
|
||||
dp.actionPane.RemovePage("action")
|
||||
dp.actionPane.AddPage("action",
|
||||
tview.NewBox().SetBorder(true).SetTitle("destroy"),
|
||||
true, true,
|
||||
)
|
||||
}).
|
||||
AddItem("layout", "", 0, func() {
|
||||
createLayoutUI(t, dp)
|
||||
})
|
||||
|
||||
dp.apiPane.SetBorder(true).SetTitle("API")
|
||||
|
||||
dp.flexPane = tview.NewFlex().
|
||||
SetDirection(tview.FlexColumn).
|
||||
AddItem(dp.apiPane, 0, 1, true).
|
||||
AddItem(dp.actionPane, 0, 4, false)
|
||||
|
||||
return dp
|
||||
}
|
||||
|
||||
type debugPane struct {
|
||||
view *tview.TextView
|
||||
}
|
||||
|
||||
func NewDebugPane(t *tui) *debugPane {
|
||||
output := tview.NewTextView().
|
||||
SetDynamicColors(true).
|
||||
SetRegions(true).
|
||||
SetChangedFunc(func() {
|
||||
t.debug.view.ScrollToEnd()
|
||||
t.app.Draw()
|
||||
})
|
||||
output.SetBorder(true).SetTitle("Output:")
|
||||
|
||||
return &debugPane{
|
||||
view: output,
|
||||
}
|
||||
}
|
||||
|
||||
type tui struct {
|
||||
app *tview.Application
|
||||
layout *layout
|
||||
debug *debugPane
|
||||
device *devicePane
|
||||
}
|
||||
|
||||
func (t *tui) log(formatter string, args ...any) {
|
||||
fmt.Fprintf(t.debug.view, formatter, args...)
|
||||
}
|
||||
|
||||
func NewTUI() *tui {
|
||||
t := &tui{}
|
||||
|
||||
debug := NewDebugPane(t)
|
||||
device := NewDevicePane(t)
|
||||
|
||||
// tui.registerDevices()
|
||||
//
|
||||
// tui.esdi.PeripheralClerk.FindDevices()
|
||||
// tui.populateDeviceList()
|
||||
|
||||
mainFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(device.flexPane, 0, 2, true).
|
||||
AddItem(debug.view, 0, 1, false)
|
||||
|
||||
t.app = tview.NewApplication()
|
||||
t.layout = &layout{
|
||||
root: mainFlex,
|
||||
}
|
||||
t.debug = debug
|
||||
t.device = device
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *tui) Start() error {
|
||||
t.app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||
if event.Key() == tcell.KeyCtrlC || event.Rune() == 'q' {
|
||||
t.app.Stop()
|
||||
return nil
|
||||
}
|
||||
|
||||
return event
|
||||
})
|
||||
|
||||
err := t.app.SetRoot(t.layout.root, true).
|
||||
SetFocus(t.device.apiPane).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
import "esdi/tui/internal/tui"
|
||||
|
||||
func Run() error {
|
||||
// Prepare the UI here
|
||||
newTui := NewTUI()
|
||||
return newTui.Start()
|
||||
app := tui.NewTUI()
|
||||
return app.Start()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user