embeded templates
This commit is contained in:
parent
bf78461bbb
commit
9e4d1a6a28
18 changed files with 63 additions and 58 deletions
11
embed/templates/tui/model.go.tmpl
Normal file
11
embed/templates/tui/model.go.tmpl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package tui
|
||||
|
||||
import tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
type model struct {
|
||||
count int
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
10
embed/templates/tui/run.go.tmpl
Normal file
10
embed/templates/tui/run.go.tmpl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package tui
|
||||
|
||||
import tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
func Run() error {
|
||||
p := tea.NewProgram(model{})
|
||||
_, err := p.Run()
|
||||
return err
|
||||
}
|
||||
|
||||
18
embed/templates/tui/update.go.tmpl
Normal file
18
embed/templates/tui/update.go.tmpl
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package tui
|
||||
|
||||
import tea "github.com/charmbracelet/bubbletea"
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "q", "ctrl+c":
|
||||
return m, tea.Quit
|
||||
case "up":
|
||||
m.count++
|
||||
case "down":
|
||||
m.count--
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
7
embed/templates/tui/view.go.tmpl
Normal file
7
embed/templates/tui/view.go.tmpl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package tui
|
||||
|
||||
import "fmt"
|
||||
|
||||
func (m model) View() string {
|
||||
return "Counter: " + fmt.Sprintf("%d", m.count) + "\n[↑/↓ to change, q to quit]"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue