Initial commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.ohea.xyz/cursorius/tui/screens"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type model struct {
|
||||
screen tea.Model
|
||||
width int
|
||||
height int
|
||||
}
|
||||
|
||||
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.WindowSizeMsg:
|
||||
m.width = msg.Width
|
||||
m.height = msg.Height
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+c":
|
||||
return m, tea.Quit
|
||||
}
|
||||
case screens.ScreenSwitchMsg:
|
||||
// when new screen is created, send WindowSizeMsg to init size
|
||||
m.screen = msg.NewScreen
|
||||
return m, func() tea.Msg {
|
||||
return tea.WindowSizeMsg{
|
||||
Width: m.width,
|
||||
Height: m.height,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cmd tea.Cmd
|
||||
m.screen, cmd = m.screen.Update(msg)
|
||||
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
func (m model) View() string {
|
||||
return m.screen.View()
|
||||
}
|
||||
|
||||
func main() {
|
||||
initialModel := model{
|
||||
screen: screens.CreateLogin(
|
||||
// TODO: load from config file
|
||||
[]screens.CursoriusServer{
|
||||
screens.CursoriusServer{
|
||||
Name: "ohea",
|
||||
Url: "https://ci.cursorius.server",
|
||||
Token: "test",
|
||||
},
|
||||
screens.CursoriusServer{
|
||||
Name: "nohea",
|
||||
Url: "https://ci.cursoriuspreview.server",
|
||||
Token: "test",
|
||||
},
|
||||
screens.CursoriusServer{
|
||||
Name: "work",
|
||||
Url: "https://ci.acme.corp",
|
||||
Token: "test",
|
||||
},
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user