WIP layout

trunk
vilmibm 2023-06-11 19:48:45 -04:00
parent 80fad75a59
commit 2003843965
1 changed files with 64 additions and 5 deletions

69
main.go
View File

@ -17,21 +17,80 @@ const (
) )
type UI struct { type UI struct {
Mode string Mode string
App *tview.Application App *tview.Application
Fields []Field
// UI things
Pages *tview.Pages
TopFlex *tview.Flex
Field *tview.Box
FieldBar *tview.Flex
BottomBar *tview.Pages
ExInput *tview.InputField
ExOutput *tview.TextView
} }
func (ui *UI) handleInput(event *tcell.EventKey) *tcell.EventKey { func (ui *UI) handleInput(event *tcell.EventKey) *tcell.EventKey {
return nil switch ui.Mode {
case NormalMode:
case ExMode:
case FocusedMode:
case SearchMode:
default:
panic("mode?")
}
return event
}
type Field struct {
Name string
Selected bool
} }
func newUI() *UI { func newUI() *UI {
app := tview.NewApplication() app := tview.NewApplication()
ui := UI{ ui := UI{
Mode: NormalMode, Mode: NormalMode,
App: app, App: app,
Fields: []Field{{"scratch", true}, {"test", false}},
Pages: tview.NewPages(),
TopFlex: tview.NewFlex(),
Field: tview.NewBox(),
FieldBar: tview.NewFlex(),
BottomBar: tview.NewPages(),
ExInput: tview.NewInputField(),
ExOutput: tview.NewTextView(),
} }
app.SetInputCapture(ui.handleInput) app.SetInputCapture(ui.handleInput)
ui.TopFlex.SetDirection(tview.FlexRow)
ui.TopFlex.AddItem(ui.Field, 0, 20, true)
ui.TopFlex.AddItem(ui.FieldBar, 0, 1, false)
ui.TopFlex.AddItem(ui.BottomBar, 1, -1, false)
ui.Pages.AddPage("main", ui.TopFlex, true, true)
ui.BottomBar.AddPage("output", ui.ExOutput, true, true)
ui.BottomBar.AddPage("input", ui.ExInput, false, false)
fmt.Fprintln(ui.ExOutput, "porphyry has started. :q to quit")
ui.FieldBar.SetDirection(tview.FlexColumn)
app.SetBeforeDrawFunc(func(_ tcell.Screen) bool {
ui.FieldBar.Clear()
for _, f := range ui.Fields {
t := tview.NewTextView().SetTextStyle(tcell.StyleDefault.Bold(f.Selected))
t.SetMaxLines(1)
t.SetBorder(true)
fmt.Fprintf(t, f.Name)
ui.FieldBar.AddItem(t, 0, 1, false)
}
return false
})
app.SetRoot(ui.Pages, true)
return &ui return &ui
} }