it is with great sadness the DOM and event bus go. Its all callbacks now
This commit is contained in:
@@ -15,22 +15,6 @@ const (
|
||||
LayoutToolNewWindowID = "new-window-action-form"
|
||||
)
|
||||
|
||||
// type windowReference struct {
|
||||
// ID int16
|
||||
// Form *dom.UINode
|
||||
// }
|
||||
|
||||
// func getWindowRefFromNode(node *tview.TreeNode) *windowReference {
|
||||
// ref := node.GetReference()
|
||||
// wRef, ok := ref.(*windowReference)
|
||||
//
|
||||
// if !ok {
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// return wRef
|
||||
// }
|
||||
|
||||
func FindNodeByID(node *tview.TreeNode, id int16) *tview.TreeNode {
|
||||
if node == nil {
|
||||
return nil
|
||||
@@ -54,15 +38,11 @@ func FindNodeByID(node *tview.TreeNode, id int16) *tview.TreeNode {
|
||||
type LayoutTreeView struct {
|
||||
Tree *tview.TreeView
|
||||
InputCapture func(*tcell.EventKey) *tcell.EventKey
|
||||
// OnChange func(node *tview.TreeNode)
|
||||
// OnSelect func(node *tview.TreeNode)
|
||||
}
|
||||
|
||||
func NewLayoutTreeView() *LayoutTreeView {
|
||||
view := &LayoutTreeView{
|
||||
InputCapture: blankInputCapture,
|
||||
// OnChange: blankTreeViewOnChange,
|
||||
// OnSelect: blankTreeViewOnChange,
|
||||
}
|
||||
|
||||
view.Tree = tview.NewTreeView()
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
helper "esdi/helpers"
|
||||
"esdi/tui/internal/dom"
|
||||
"esdi/tui/internal/events"
|
||||
"esdi/tui/internal/ui"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
type ManipMode int
|
||||
|
||||
const (
|
||||
moveMode ManipMode = iota
|
||||
resizeMode
|
||||
)
|
||||
|
||||
type windowManipState struct {
|
||||
Mode ManipMode
|
||||
}
|
||||
|
||||
func keyToVector(r rune) (helper.Vector, bool) {
|
||||
var mult uint16 = 1
|
||||
|
||||
// Is uppercase? For fast movement
|
||||
if r >= 'A' && r <= 'Z' {
|
||||
mult = 10
|
||||
r += 'a' - 'A'
|
||||
}
|
||||
|
||||
switch r {
|
||||
case 'h':
|
||||
return helper.Vector{DX: -mult, DY: 0}, true
|
||||
case 'j':
|
||||
return helper.Vector{DX: 0, DY: mult}, true
|
||||
case 'k':
|
||||
return helper.Vector{DX: 0, DY: -mult}, true
|
||||
case 'l':
|
||||
return helper.Vector{DX: mult, DY: 0}, true
|
||||
}
|
||||
|
||||
return helper.Vector{}, false
|
||||
}
|
||||
|
||||
func handleMovementCapture(bus *events.Bus, id int16, ev *tcell.EventKey) *tcell.EventKey {
|
||||
vec, ok := keyToVector(ev.Rune())
|
||||
if !ok {
|
||||
return ev
|
||||
}
|
||||
|
||||
bus.Emit(ui.MoveWindowEv{
|
||||
WindowID: id,
|
||||
Delta: vec,
|
||||
})
|
||||
|
||||
return ev
|
||||
}
|
||||
|
||||
func handleResizeCapture(bus *events.Bus, id int16, ev *tcell.EventKey) *tcell.EventKey {
|
||||
vec, ok := keyToVector(ev.Rune())
|
||||
if !ok {
|
||||
return ev
|
||||
}
|
||||
|
||||
bus.Emit(ui.ResizeWindowEv{
|
||||
WindowID: id,
|
||||
Delta: vec,
|
||||
})
|
||||
|
||||
return ev
|
||||
}
|
||||
|
||||
type modeHandler func(*tcell.EventKey) *tcell.EventKey
|
||||
|
||||
func (s *windowManipState) CurrentHandler(
|
||||
bus *events.Bus,
|
||||
id int16,
|
||||
) modeHandler {
|
||||
switch s.Mode {
|
||||
case moveMode:
|
||||
return func(ev *tcell.EventKey) *tcell.EventKey {
|
||||
return handleMovementCapture(bus, id, ev)
|
||||
}
|
||||
case resizeMode:
|
||||
return func(ev *tcell.EventKey) *tcell.EventKey {
|
||||
return handleResizeCapture(bus, id, ev)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func windowManipulationEvCapture(
|
||||
bus *events.Bus,
|
||||
doc *dom.DOM,
|
||||
id int16,
|
||||
state *windowManipState,
|
||||
) func(ev *tcell.EventKey) *tcell.EventKey {
|
||||
return func(ev *tcell.EventKey) *tcell.EventKey {
|
||||
switch ev.Key() {
|
||||
case tcell.KeyEscape:
|
||||
bus.Emit(ui.ChangeFocusEv{
|
||||
Target: doc.GetElemByID(LayoutToolFlexID),
|
||||
})
|
||||
return ev
|
||||
}
|
||||
|
||||
bus.Emit(ui.PrintLogEv{
|
||||
Log: fmt.Sprintf("-> IDX: %d\n", id),
|
||||
})
|
||||
|
||||
// Mode switching
|
||||
switch ev.Rune() {
|
||||
case 'r':
|
||||
state.Mode = resizeMode
|
||||
bus.Emit(ui.PrintLogEv{Log: "switched to resizeMode"})
|
||||
case 'm':
|
||||
state.Mode = moveMode
|
||||
bus.Emit(ui.PrintLogEv{Log: "switched to moveMode"})
|
||||
}
|
||||
|
||||
// Delegate the current handler input
|
||||
handler := state.CurrentHandler(bus, id)
|
||||
if handler != nil {
|
||||
return handler(ev)
|
||||
}
|
||||
|
||||
return ev
|
||||
}
|
||||
}
|
||||
|
||||
func windowManipulationTool(bus *events.Bus, doc *dom.DOM, idx int16) {
|
||||
bus.Emit(ui.PrintLogEv{Log: fmt.Sprintf("WID: %d\n", idx)})
|
||||
|
||||
// Get the ActionPages parent
|
||||
box := tview.NewBox().SetTitle("MOVE WINDOW TOOL")
|
||||
box.SetBorder(true)
|
||||
|
||||
var err error
|
||||
var boxNode *dom.UINode
|
||||
|
||||
// delete the currently existing move-window-box
|
||||
actionPages := doc.GetElemByID(LayoutToolActionPagesID).(*tview.Pages)
|
||||
actionPages.RemovePage("move-window-box")
|
||||
|
||||
boxNode = doc.GetNodeByID("move-window-box")
|
||||
if boxNode != nil {
|
||||
doc.DeleteElem(boxNode)
|
||||
}
|
||||
|
||||
boxNode, err = doc.NewUINode(
|
||||
"move-window-box",
|
||||
doc.GetElemByID(LayoutToolActionPagesID),
|
||||
box,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Create the state for this tool
|
||||
state := windowManipState{
|
||||
Mode: moveMode,
|
||||
}
|
||||
|
||||
box.SetInputCapture(windowManipulationEvCapture(bus, doc, idx, &state))
|
||||
// AddAndShowPage(actionPages, boxNode, true)
|
||||
}
|
||||
@@ -4,8 +4,6 @@ package views
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"esdi/tui/internal/dom"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
@@ -76,48 +74,48 @@ func (dl *DeviceAPIListView) AddItem(name, description string, onSelect func())
|
||||
dl.List.AddItem(name, description, 0, onSelect)
|
||||
}
|
||||
|
||||
func NewDeviceAPIView(doc *dom.DOM) (*DeviceAPIView, error) {
|
||||
func NewDeviceAPIView() (*DeviceAPIView, error) {
|
||||
// To build the main view we must set the DOM root
|
||||
mainFlex := tview.NewFlex().SetDirection(tview.FlexColumn)
|
||||
mainFlexUINode, err := doc.NewUINode(MainFlexID, nil, mainFlex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
doc.SetRoot(mainFlexUINode)
|
||||
// mainFlexUINode, err := doc.NewUINode(MainFlexID, nil, mainFlex)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// doc.SetRoot(mainFlexUINode)
|
||||
|
||||
deviceAPIList := NewDeviceAPIListView()
|
||||
apiListWindowUINode, err := doc.NewUINode(DeviceAPIListID, doc.GetRootElem(),
|
||||
deviceAPIList.List)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// apiListWindowUINode, err := doc.NewUINode(DeviceAPIListID, doc.GetRootElem(),
|
||||
// deviceAPIList.List)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
apiToolPages := NewDeviceAPIToolView()
|
||||
apiToolPagesNode, err := doc.NewUINode(APIToolPagesID, doc.GetElemByID(RightFlexID),
|
||||
apiToolPages.Pages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// apiToolPagesNode, err := doc.NewUINode(APIToolPagesID, doc.GetElemByID(RightFlexID),
|
||||
// apiToolPages.Pages)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
mainFlex.
|
||||
AddItem(apiListWindowUINode.Self, 0, 1, false).
|
||||
AddItem(apiToolPagesNode.Self, 0, 4, false)
|
||||
AddItem(deviceAPIList.List, 0, 1, false).
|
||||
AddItem(apiToolPages.Pages, 0, 4, false)
|
||||
|
||||
// Output window
|
||||
|
||||
outputWin := NewOutputWinView()
|
||||
_, err = doc.NewUINode("output-window", nil, outputWin.TextArea)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// _, err = doc.NewUINode("output-window", nil, outputWin.TextArea)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// Flex with debug window
|
||||
// --------------------------------------------------------------------------
|
||||
flexWithOutputWindow := tview.NewFlex().SetDirection(tview.FlexRow)
|
||||
flexWithOutputWindow.
|
||||
AddItem(mainFlex, 0, 5, true).
|
||||
AddItem(doc.GetElemByID(OutputPaneID), 0, 2, false)
|
||||
AddItem(outputWin.TextArea, 0, 2, false)
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
return &DeviceAPIView{
|
||||
|
||||
@@ -4,16 +4,6 @@ import (
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
// func bindOutputWindowEvents(
|
||||
// bus *events.Bus,
|
||||
// output *tview.TextView,
|
||||
// ) {
|
||||
// bus.On(ui.PrintLogEv{}, func(e any) {
|
||||
// le, _ := e.(ui.PrintLogEv)
|
||||
// fmt.Fprintf(output, le.Log)
|
||||
// })
|
||||
// }
|
||||
|
||||
type OutputWinView struct {
|
||||
TextArea *tview.TextView
|
||||
}
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"esdi/tui/internal/dom"
|
||||
"esdi/tui/internal/events"
|
||||
"esdi/tui/internal/ui"
|
||||
"os"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
// Car data lengths
|
||||
const (
|
||||
SpeedLen = 5
|
||||
@@ -22,56 +12,56 @@ const (
|
||||
streamingBoxID = "streaming-box"
|
||||
)
|
||||
|
||||
func streamingWindow(bus *events.Bus, doc *dom.DOM) {
|
||||
bus.Emit(ui.LogEv{Log: "creating streaming window"})
|
||||
|
||||
// Get the ActionPages parent
|
||||
box := tview.NewTextView()
|
||||
box.SetBorder(true).SetTitle("STREAMING")
|
||||
box.SetInputCapture(func(ev *tcell.EventKey) *tcell.EventKey {
|
||||
switch ev.Key() {
|
||||
case tcell.KeyEsc:
|
||||
// well, I really need to design the UI (as if lmao) better
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
return ev
|
||||
})
|
||||
|
||||
var err error
|
||||
var boxNode *dom.UINode
|
||||
|
||||
// delete the currently existing streaming-box
|
||||
actionPages := doc.GetElemByID(LayoutToolActionPagesID).(*tview.Pages)
|
||||
actionPages.RemovePage(streamingBoxID)
|
||||
|
||||
// Get the currently exisiting streaming box in the dom so we can delete it
|
||||
boxNode = doc.GetNodeByID(streamingBoxID)
|
||||
if boxNode != nil {
|
||||
doc.DeleteElem(boxNode)
|
||||
}
|
||||
|
||||
// Register this streaming box as an UINode
|
||||
boxNode, err = doc.NewUINode(
|
||||
streamingBoxID,
|
||||
doc.GetElemByID(LayoutToolActionPagesID),
|
||||
box,
|
||||
)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Add it to the action pages and view it
|
||||
// AddAndShowPage(actionPages, boxNode, true)
|
||||
|
||||
bus.Emit(ui.StartStreamingReqEv{})
|
||||
|
||||
bus.On(ui.StreamDataEv{}, func(e any) {
|
||||
bus.Emit(ui.RedrawEv{
|
||||
Fn: func() {
|
||||
sd := e.(ui.StreamDataEv)
|
||||
box.SetText(sd.Str)
|
||||
},
|
||||
})
|
||||
})
|
||||
func streamingWindow() {
|
||||
// bus.Emit(ui.LogEv{Log: "creating streaming window"})
|
||||
//
|
||||
// // Get the ActionPages parent
|
||||
// box := tview.NewTextView()
|
||||
// box.SetBorder(true).SetTitle("STREAMING")
|
||||
// box.SetInputCapture(func(ev *tcell.EventKey) *tcell.EventKey {
|
||||
// switch ev.Key() {
|
||||
// case tcell.KeyEsc:
|
||||
// // well, I really need to design the UI (as if lmao) better
|
||||
// os.Exit(0)
|
||||
// }
|
||||
//
|
||||
// return ev
|
||||
// })
|
||||
//
|
||||
// var err error
|
||||
// var boxNode *dom.UINode
|
||||
//
|
||||
// // delete the currently existing streaming-box
|
||||
// actionPages := doc.GetElemByID(LayoutToolActionPagesID).(*tview.Pages)
|
||||
// actionPages.RemovePage(streamingBoxID)
|
||||
//
|
||||
// // Get the currently exisiting streaming box in the dom so we can delete it
|
||||
// boxNode = doc.GetNodeByID(streamingBoxID)
|
||||
// if boxNode != nil {
|
||||
// doc.DeleteElem(boxNode)
|
||||
// }
|
||||
//
|
||||
// // Register this streaming box as an UINode
|
||||
// boxNode, err = doc.NewUINode(
|
||||
// streamingBoxID,
|
||||
// doc.GetElemByID(LayoutToolActionPagesID),
|
||||
// box,
|
||||
// )
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Add it to the action pages and view it
|
||||
// // AddAndShowPage(actionPages, boxNode, true)
|
||||
//
|
||||
// bus.Emit(ui.StartStreamingReqEv{})
|
||||
//
|
||||
// bus.On(ui.StreamDataEv{}, func(e any) {
|
||||
// bus.Emit(ui.RedrawEv{
|
||||
// Fn: func() {
|
||||
// sd := e.(ui.StreamDataEv)
|
||||
// box.SetText(sd.Str)
|
||||
// },
|
||||
// })
|
||||
// })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user