More work associated with the new TUI - must recover old repl tho

This commit is contained in:
2026-01-08 18:57:55 +00:00
parent 54e1f3b424
commit 56ce6bc58d
22 changed files with 935 additions and 194 deletions
+1 -1
View File
@@ -1,8 +1,8 @@
package cmd package cmd
import ( import (
"esdi/esdi"
"esdi/logger" "esdi/logger"
esdi "esdi/oldEsdi"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
+1 -1
View File
@@ -1,8 +1,8 @@
package cmd package cmd
import ( import (
"esdi/esdi"
"esdi/logger" "esdi/logger"
esdi "esdi/oldEsdi"
// "github.com/ESilva15/goirsdk" // "github.com/ESilva15/goirsdk"
+95 -92
View File
@@ -1,103 +1,106 @@
package cmd package cmd
import ( import (
"esdi/peripheral" "esdi/t"
"fmt"
"strconv"
repl "github.com/ESilva15/ESgoRepl"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// func replCmdAction(cmd *cobra.Command, args []string) {
// r := repl.NewREPL(repl.REPLCfg{
// PS1: "\rESDI > ",
// })
//
// perClerk := peripheral.NewPeripheralDeviceClerk()
//
// discoverDevicesREPLCmd := repl.Command{
// Name: "discover",
// Usage: "discovers connected devices",
// Action: func(r *repl.REPL, args []string) error {
// err := perClerk.FindDevices()
// if err != nil {
// return err
// }
//
// return nil
// },
// }
//
// listDevicesREPLCmd := repl.Command{
// Name: "list",
// Usage: "lists connected devices",
// Action: func(r *repl.REPL, args []string) error {
// _ = perClerk.ListDevices()
//
// return nil
// },
// }
//
// listDeviceAPIREPLCmd := repl.Command{
// Name: "v-api",
// Usage: "shows API of a device - pass its ID",
// Action: func(r *repl.REPL, args []string) error {
// // We should add this to the REPL instead
// if len(args) < 1 {
// return fmt.Errorf("requires at least on argument")
// }
//
// // First and only argument should be the ID of the device we want to use
// targetID, err := strconv.ParseInt(args[0], 10, 0)
// if err != nil {
// return err
// }
//
// err = perClerk.ListDeviceAPI(uint8(targetID))
// if err != nil {
// fmt.Println("failed to view device API: ", err.Error())
// }
//
// return nil
// },
// }
//
// runDeviceAPIREPLCmd := repl.Command{
// Name: "v-run",
// Usage: "runs a funcion of a device - pass its ID and function name",
// Action: func(r *repl.REPL, args []string) error {
// // We should add this to the REPL instead
// if len(args) < 3 {
// return fmt.Errorf("requires at least on argument")
// }
//
// // First and only argument should be the ID of the device we want to use
// targetID, err := strconv.ParseInt(args[0], 10, 0)
// if err != nil {
// return err
// }
//
// fnName := args[1]
// fnArgs := args[2:]
//
// err = perClerk.RunDeviceFunction(uint8(targetID), fnName, fnArgs)
// if err != nil {
// return err
// }
//
// return nil
// },
// }
//
// r.RegisterCMD(discoverDevicesREPLCmd)
// r.RegisterCMD(listDevicesREPLCmd)
// r.RegisterCMD(listDeviceAPIREPLCmd)
// r.RegisterCMD(runDeviceAPIREPLCmd)
//
// r.Start()
// r.Close()
// }
func replCmdAction(cmd *cobra.Command, args []string) { func replCmdAction(cmd *cobra.Command, args []string) {
r := repl.NewREPL(repl.REPLCfg{ // repl.Run()
PS1: "\rESDI > ", // tui.Run()
}) // teatui.Run()
t.Run()
perClerk := peripheral.NewPeripheralDeviceClerk()
discoverDevicesREPLCmd := repl.Command{
Name: "discover",
Usage: "discovers connected devices",
Action: func(r *repl.REPL, args []string) error {
err := perClerk.FindDevices()
if err != nil {
return err
}
return nil
},
}
listDevicesREPLCmd := repl.Command{
Name: "list",
Usage: "lists connected devices",
Action: func(r *repl.REPL, args []string) error {
_ = perClerk.ListDevices()
return nil
},
}
listDeviceAPIREPLCmd := repl.Command{
Name: "v-api",
Usage: "shows API of a device - pass its ID",
Action: func(r *repl.REPL, args []string) error {
// We should add this to the REPL instead
if len(args) < 1 {
return fmt.Errorf("requires at least on argument")
}
// First and only argument should be the ID of the device we want to use
targetID, err := strconv.ParseInt(args[0], 10, 0)
if err != nil {
return err
}
err = perClerk.ListDeviceAPI(uint8(targetID))
if err != nil {
fmt.Println("failed to view device API: ", err.Error())
}
return nil
},
}
runDeviceAPIREPLCmd := repl.Command{
Name: "v-run",
Usage: "runs a funcion of a device - pass its ID and function name",
Action: func(r *repl.REPL, args []string) error {
// We should add this to the REPL instead
if len(args) < 3 {
return fmt.Errorf("requires at least on argument")
}
// First and only argument should be the ID of the device we want to use
targetID, err := strconv.ParseInt(args[0], 10, 0)
if err != nil {
return err
}
fnName := args[1]
fnArgs := args[2:]
err = perClerk.RunDeviceFunction(uint8(targetID), fnName, fnArgs)
if err != nil {
return err
}
return nil
},
}
r.RegisterCMD(discoverDevicesREPLCmd)
r.RegisterCMD(listDevicesREPLCmd)
r.RegisterCMD(listDeviceAPIREPLCmd)
r.RegisterCMD(runDeviceAPIREPLCmd)
r.Start()
r.Close()
} }
// removeLabelCmd represents the removeLabel command // removeLabelCmd represents the removeLabel command
+14 -92
View File
@@ -1,92 +1,14 @@
// Package esdi will have the domain logic for our desktop interface // Package esdi
package esdi package esdi
import ( import "esdi/peripheral"
"esdi/sources/iracing"
"log" type ESDI struct {
"os" PeripheralClerk *peripheral.PeripheralDeviceClerk
"time" }
"github.com/ESilva15/goirsdk" func NewESDI() *ESDI {
"github.com/tarm/serial" return &ESDI{
) PeripheralClerk: peripheral.NewPeripheralDeviceClerk(),
}
type ESDI struct { }
SerialConfig *serial.Config
SerialConn *serial.Port
irsdk *goirsdk.IBT
data SimulationData
dataPacket DataPacket
// Source GameSource
}
func (e *ESDI) Close() {
err := e.SerialConn.Close()
if err != nil {
log.Fatalf("couldn't close serial connection: %v", err)
}
}
func ESDIInit(port string, baud int) (ESDI, error) {
sConfig := &serial.Config{
Name: port,
Baud: baud,
ReadTimeout: time.Millisecond * 1000,
}
// Open the serial port
sPort, err := serial.OpenPort(sConfig)
if err != nil {
return ESDI{}, err
}
// return ESDI{sConfig, sPort, nil}, nil
return ESDI{sConfig, sPort, nil, SimulationData{}, DataPacket{}}, nil
// return ESDI{nil, nil, nil, SimulationData{}, DataPacket{}}, nil
}
func RunLiveTelemetry(port string, output string, session string) {
esdi, err := ESDIInit(port, 115200)
if err != nil {
log.Fatalf("Failed to get Desktop Interface: %v", err)
}
// irsdk, err := iracing.Init(nil, outputFile, sessionFile)
// if err != nil {
// log.Fatalf("Failed to create iRacing interface: %v", err)
// }
irsdk, err := goirsdk.Init(nil, output, session)
if err != nil {
log.Fatalf("Failed to create irsdk instance: %v\n", err)
}
esdi.irsdk = irsdk
esdi.telemetry()
}
func RunOfflineTelemetry(port string, input string, output string, session string) {
esdi, err := ESDIInit(port, 115200)
if err != nil {
log.Fatalf("Failed to get Desktop Interface: %v", err)
}
file, err := os.Open(input)
if err != nil {
log.Fatalf("Failed to open IBT file: %v", err)
}
irsdk, err := iracing.Init(file, output, session)
if err != nil {
log.Fatalf("Failed to create iRacing interface: %v", err)
}
// irsdk, err := goirsdk.Init(file, outFile, sessionFile)
// if err != nil {
// log.Fatalf("Failed to create irsdk instance: %v\n", err)
// }
esdi.irsdk = irsdk.SDK
esdi.telemetry()
}
+23 -3
View File
@@ -3,17 +3,37 @@ module esdi
go 1.25.5 go 1.25.5
require ( require (
github.com/ESilva15/ESgoRepl v0.1.0
github.com/ESilva15/gobngsdk v0.0.2 github.com/ESilva15/gobngsdk v0.0.2
github.com/ESilva15/goirsdk v0.2.0 github.com/ESilva15/goirsdk v0.2.0
github.com/charmbracelet/bubbletea v1.3.10
github.com/gdamore/tcell/v2 v2.8.1
github.com/rivo/tview v0.42.0
github.com/spf13/cobra v1.8.1 github.com/spf13/cobra v1.8.1
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
golang.org/x/term v0.38.0
) )
require ( require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
github.com/charmbracelet/lipgloss v1.1.0 // indirect
github.com/charmbracelet/x/ansi v0.10.1 // indirect
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/gdamore/encoding v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.29.0 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/text v0.19.0 // indirect golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )
+112 -5
View File
@@ -1,14 +1,52 @@
github.com/ESilva15/ESgoRepl v0.1.0 h1:hOVcRBfdP8Yw1kLr2tFoM3SetV7vxFswKjzfAtq8UgM=
github.com/ESilva15/ESgoRepl v0.1.0/go.mod h1:O2JQMyEgHy0zf9UvzvLNvp2w95T2uazc3torrzRmG9Y=
github.com/ESilva15/gobngsdk v0.0.2 h1:N6stNOE14Wg80BAZMFu/Qd9Qa/J0DmExCfdPoDf7lco= github.com/ESilva15/gobngsdk v0.0.2 h1:N6stNOE14Wg80BAZMFu/Qd9Qa/J0DmExCfdPoDf7lco=
github.com/ESilva15/gobngsdk v0.0.2/go.mod h1:cKLaZRgM0tGGXDvosaSjHnxeyC5Y6rg7zCLqEUJnOzw= github.com/ESilva15/gobngsdk v0.0.2/go.mod h1:cKLaZRgM0tGGXDvosaSjHnxeyC5Y6rg7zCLqEUJnOzw=
github.com/ESilva15/goirsdk v0.2.0 h1:zmtYyH3ayGRcDfzzLrJmEpX6zdmCHTUqbs4tnV2hXmI= github.com/ESilva15/goirsdk v0.2.0 h1:zmtYyH3ayGRcDfzzLrJmEpX6zdmCHTUqbs4tnV2hXmI=
github.com/ESilva15/goirsdk v0.2.0/go.mod h1:5borQbw+L4fe9b58JFHRHZwrzz0sMVAteuYbRnFOc0Q= github.com/ESilva15/goirsdk v0.2.0/go.mod h1:5borQbw+L4fe9b58JFHRHZwrzz0sMVAteuYbRnFOc0Q=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw=
github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/x/ansi v0.10.1 h1:rL3Koar5XvX0pHGfovN03f5cxLbCF2YvLeyz7D2jVDQ=
github.com/charmbracelet/x/ansi v0.10.1/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=
github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=
github.com/gdamore/tcell/v2 v2.8.1 h1:KPNxyqclpWpWQlPLx6Xui1pMk8S+7+R37h3g07997NU=
github.com/gdamore/tcell/v2 v2.8.1/go.mod h1:bj8ori1BG3OYMjmb3IklZVWfZUJ1UBQt9JXrOCOhGWw=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/rivo/tview v0.42.0 h1:b/ftp+RxtDsHSaynXTbJb+/n/BxDEi+W3UfF5jILK6c=
github.com/rivo/tview v0.42.0/go.mod h1:cSfIYfhpSGCjp3r/ECJb+GKS7cGJnqV8vfjQPwoXyfY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
@@ -16,10 +54,79 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q=
golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+92
View File
@@ -0,0 +1,92 @@
// Package esdi will have the domain logic for our desktop interface
package esdi
import (
"esdi/sources/iracing"
"log"
"os"
"time"
"github.com/ESilva15/goirsdk"
"github.com/tarm/serial"
)
type ESDI struct {
SerialConfig *serial.Config
SerialConn *serial.Port
irsdk *goirsdk.IBT
data SimulationData
dataPacket DataPacket
// Source GameSource
}
func (e *ESDI) Close() {
err := e.SerialConn.Close()
if err != nil {
log.Fatalf("couldn't close serial connection: %v", err)
}
}
func ESDIInit(port string, baud int) (ESDI, error) {
sConfig := &serial.Config{
Name: port,
Baud: baud,
ReadTimeout: time.Millisecond * 1000,
}
// Open the serial port
sPort, err := serial.OpenPort(sConfig)
if err != nil {
return ESDI{}, err
}
// return ESDI{sConfig, sPort, nil}, nil
return ESDI{sConfig, sPort, nil, SimulationData{}, DataPacket{}}, nil
// return ESDI{nil, nil, nil, SimulationData{}, DataPacket{}}, nil
}
func RunLiveTelemetry(port string, output string, session string) {
esdi, err := ESDIInit(port, 115200)
if err != nil {
log.Fatalf("Failed to get Desktop Interface: %v", err)
}
// irsdk, err := iracing.Init(nil, outputFile, sessionFile)
// if err != nil {
// log.Fatalf("Failed to create iRacing interface: %v", err)
// }
irsdk, err := goirsdk.Init(nil, output, session)
if err != nil {
log.Fatalf("Failed to create irsdk instance: %v\n", err)
}
esdi.irsdk = irsdk
esdi.telemetry()
}
func RunOfflineTelemetry(port string, input string, output string, session string) {
esdi, err := ESDIInit(port, 115200)
if err != nil {
log.Fatalf("Failed to get Desktop Interface: %v", err)
}
file, err := os.Open(input)
if err != nil {
log.Fatalf("Failed to open IBT file: %v", err)
}
irsdk, err := iracing.Init(file, output, session)
if err != nil {
log.Fatalf("Failed to create iRacing interface: %v", err)
}
// irsdk, err := goirsdk.Init(file, outFile, sessionFile)
// if err != nil {
// log.Fatalf("Failed to create irsdk instance: %v\n", err)
// }
esdi.irsdk = irsdk.SDK
esdi.telemetry()
}
View File
+78
View File
@@ -2,15 +2,20 @@ package devices
import ( import (
"fmt" "fmt"
"os"
"strconv" "strconv"
"unicode/utf8"
helper "esdi/helpers" helper "esdi/helpers"
"esdi/peripheral/types" "esdi/peripheral/types"
"golang.org/x/term"
) )
const ( const (
newWindowCMDID types.Command = 3 newWindowCMDID types.Command = 3
destroyWindowCMDID types.Command = 4 destroyWindowCMDID types.Command = 4
moveWindowCMDID types.Command = 5
) )
var ( var (
@@ -68,6 +73,13 @@ var CDashDisplay = Device{
ArgCheck: destroyWindowArgCheck, ArgCheck: destroyWindowArgCheck,
Fn: destroyWindow, Fn: destroyWindow,
}, },
"move-window": {
Identifier: moveWindowCMDID,
Name: "move-window",
Desc: "moves a window by its ID",
ArgCheck: moveWindowArgCheck,
Fn: moveWindow,
},
}, },
} }
@@ -154,3 +166,69 @@ func destroyWindow(dCMD *DeviceCMD, args []string) (types.Command, []byte, error
return dCMD.GetIdentifier(), bytes, nil return dCMD.GetIdentifier(), bytes, nil
} }
func moveWindowArgCheck(args []string) error {
if len(args) != 1 {
return fmt.Errorf("wrong parameters, got %d, want %d. "+
"Command asks for: winID", len(args), 1)
}
return nil
}
func moveWindow(dCMD *DeviceCMD, args []string) (types.Command, []byte, error) {
// Create an interactive mode to move the window or whatever
fd := int(os.Stdin.Fd())
oldState, err := term.MakeRaw(fd)
if err != nil {
return dCMD.GetIdentifier(), []byte{}, err
}
defer term.Restore(fd, oldState)
buf := make([]byte, 8)
// var buffer []byte
for {
var stop = false
// We read the input on stdin and capture all types of inputs!
n, err := os.Stdin.Read(buf)
if err != nil {
return dCMD.GetIdentifier(), []byte{}, err
}
data := buf[:n]
if len(data) <= 0 {
continue
}
if data[0] == 0x1b {
continue
}
r, _ := utf8.DecodeRune(data)
if r == utf8.RuneError {
return dCMD.GetIdentifier(), []byte{}, err
}
switch r {
case 'q':
stop = true
case 'h':
fmt.Printf("←")
case 'l':
fmt.Printf("→")
case 'k':
fmt.Printf("↑")
case 'j':
fmt.Printf("↓")
}
if stop {
break
}
}
return dCMD.GetIdentifier(), []byte{}, fmt.Errorf("do nothing")
}
+89
View File
@@ -0,0 +1,89 @@
package repl
import (
"fmt"
"strconv"
)
type Command struct {
Name string
Usage string
ArgCheck func(args []string) error
Action func(args []string) error
}
var (
discoverDevicesREPLCmd = repl.Command{
Name: "discover",
Usage: "discovers connected devices",
Action: func(r *repl.REPL, args []string) error {
err := perClerk.FindDevices()
if err != nil {
return err
}
return nil
},
}
listDevicesREPLCmd = repl.Command{
Name: "list",
Usage: "lists connected devices",
Action: func(r *repl.REPL, args []string) error {
_ = perClerk.ListDevices()
return nil
},
}
listDeviceAPIREPLCmd = repl.Command{
Name: "v-api",
Usage: "shows API of a device - pass its ID",
Action: func(r *repl.REPL, args []string) error {
// We should add this to the REPL instead
if len(args) < 1 {
return fmt.Errorf("requires at least on argument")
}
// First and only argument should be the ID of the device we want to use
targetID, err := strconv.ParseInt(args[0], 10, 0)
if err != nil {
return err
}
err = perClerk.ListDeviceAPI(uint8(targetID))
if err != nil {
fmt.Println("failed to view device API: ", err.Error())
}
return nil
},
}
runDeviceAPIREPLCmd = repl.Command{
Name: "v-run",
Usage: "runs a funcion of a device - pass its ID and function name",
Action: func(r *repl.REPL, args []string) error {
// We should add this to the REPL instead
if len(args) < 3 {
return fmt.Errorf("requires at least on argument")
}
// First and only argument should be the ID of the device we want to use
targetID, err := strconv.ParseInt(args[0], 10, 0)
if err != nil {
return err
}
fnName := args[1]
fnArgs := args[2:]
err = perClerk.RunDeviceFunction(uint8(targetID), fnName, fnArgs)
if err != nil {
return err
}
return nil
},
}
)
+62
View File
@@ -0,0 +1,62 @@
package repl
import (
esdi "esdi/esdi"
tea "github.com/charmbracelet/bubbletea"
)
type model struct {
esdi *esdi.ESDI
mov string
}
func initialMode() model {
return model{
esdi: esdi.NewESDI(),
}
}
func (m model) Init() tea.Cmd {
return nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "ctrl+c", "q":
return m, tea.Quit
case "left", "h":
// Go left
m.mov = msg.String()
case "down", "j":
// Go down
m.mov = msg.String()
case "up", "k":
// Go up
m.mov = msg.String()
case "right", "l":
// Go right
m.mov = msg.String()
}
}
return m, nil
}
func (m model) View() string {
s := "What should we buy at the market?\n\n"
s += m.mov + "\n"
return s
}
func Run() error {
p := tea.NewProgram(initialMode())
if _, err := p.Run(); err != nil {
return err
}
return nil
}
+106
View File
@@ -0,0 +1,106 @@
// 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)
}
}
+13
View File
@@ -0,0 +1,13 @@
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)
}
+103
View File
@@ -0,0 +1,103 @@
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)
}
+20
View File
@@ -0,0 +1,20 @@
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
}
+126
View File
@@ -0,0 +1,126 @@
// 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
}
func Run() error {
// Prepare the UI here
newTui := NewTUI()
return newTui.Start()
}