mirror of
https://github.com/wisplite/parchment.git
synced 2026-06-27 13:47:08 -05:00
fixed some ui state issues
This commit is contained in:
@@ -5,42 +5,53 @@ import (
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
func AppUI(app *tview.Application, currentFrame **tview.Frame) *tview.Frame {
|
||||
type UIState struct {
|
||||
Page string
|
||||
}
|
||||
|
||||
func AppUI(app *tview.Application, currentFrame **tview.Frame, state *UIState) *tview.Frame {
|
||||
list := tview.NewList()
|
||||
list.AddItem("CPkg Tools", "Create and unpack cpkg files for distribution", 'c', func() {
|
||||
newFrame := PackageUI(app, currentFrame)
|
||||
newFrame := PackageUI(app, currentFrame, state)
|
||||
*currentFrame = newFrame
|
||||
state.Page = "package"
|
||||
app.SetRoot(newFrame, true)
|
||||
})
|
||||
list.AddItem("Upload to Cardputer", "Creates a package and uploads it to the connected Cardputer", 'u', nil)
|
||||
frame := tview.NewFrame(list)
|
||||
frame.SetBorders(0, 0, 0, 0, 0, 0)
|
||||
frame.AddText("Parchment - v0.0.1", true, tview.AlignLeft, tcell.ColorWhite)
|
||||
frame.AddText("Searching for device...", false, tview.AlignLeft, tcell.ColorWhite)
|
||||
frame.AddText("Waiting for cardputer...", false, tview.AlignLeft, tcell.ColorWhite)
|
||||
|
||||
return frame
|
||||
}
|
||||
|
||||
func PackageUI(app *tview.Application, currentFrame **tview.Frame) *tview.Frame {
|
||||
func PackageUI(app *tview.Application, currentFrame **tview.Frame, state *UIState) *tview.Frame {
|
||||
list := tview.NewList()
|
||||
list.AddItem("Create Package", "Creates a .cpkg file in the running directory", 'c', nil)
|
||||
list.AddItem("Unpack Package", "Unpacks a chosen .cpkg file into a subdirectory", 'u', nil)
|
||||
list.AddItem("Back", "Go back to the home page", 'b', func() {
|
||||
newFrame := AppUI(app, currentFrame)
|
||||
newFrame := AppUI(app, currentFrame, state)
|
||||
*currentFrame = newFrame
|
||||
state.Page = "home"
|
||||
app.SetRoot(newFrame, true)
|
||||
})
|
||||
frame := tview.NewFrame(list)
|
||||
frame.SetBorders(0, 0, 0, 0, 0, 0)
|
||||
frame.AddText("Package Mode", true, tview.AlignLeft, tcell.ColorWhite)
|
||||
|
||||
frame.AddText("Package Tools", true, tview.AlignLeft, tcell.ColorWhite)
|
||||
frame.AddText("Waiting for cardputer...", false, tview.AlignLeft, tcell.ColorWhite)
|
||||
return frame
|
||||
}
|
||||
|
||||
func UpdateDeviceStatus(app *tview.Application, frame *tview.Frame, status string, color tcell.Color) {
|
||||
func UpdateDeviceStatus(app *tview.Application, frame *tview.Frame, state *UIState, status string, color tcell.Color) {
|
||||
app.QueueUpdateDraw(func() {
|
||||
frame.Clear()
|
||||
frame.AddText("Parchment - v0.0.1", true, tview.AlignLeft, tcell.ColorWhite)
|
||||
switch state.Page {
|
||||
case "home":
|
||||
frame.AddText("Parchment - v0.0.1", true, tview.AlignLeft, tcell.ColorWhite)
|
||||
case "package":
|
||||
frame.AddText("Package Tools", true, tview.AlignLeft, tcell.ColorWhite)
|
||||
}
|
||||
frame.AddText(status, false, tview.AlignLeft, color)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user