77 lines
1.9 KiB
Go
77 lines
1.9 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
tea "charm.land/bubbletea/v2"
|
|
"charm.land/lipgloss/v2"
|
|
|
|
"github.com/oxpoe/tia/internal/audio"
|
|
)
|
|
|
|
// Model root sementara (T-0.2/T-0.3, Phase 0).
|
|
// Membuktikan Bubble Tea v2 (View struct, mouse, resize) + audio engine
|
|
// sebelum layout penuh Phase 1 menggantikannya.
|
|
type Model struct {
|
|
width, height int
|
|
clicks int
|
|
lastClick string
|
|
sound *audio.Engine
|
|
}
|
|
|
|
func New() Model {
|
|
return Model{
|
|
lastClick: "belum ada klik",
|
|
sound: audio.New(audio.Options{Enabled: true, Volume: 70, MuteOnSSH: true}),
|
|
}
|
|
}
|
|
|
|
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, m.height = msg.Width, msg.Height
|
|
|
|
case tea.KeyPressMsg:
|
|
switch msg.String() {
|
|
case "q", "ctrl+c", "esc":
|
|
m.sound.Play(audio.ModalClose)
|
|
return m, tea.Quit
|
|
case "j", "down", "k", "up":
|
|
m.sound.Play(audio.Navigate)
|
|
}
|
|
|
|
case tea.MouseClickMsg:
|
|
if msg.Button == tea.MouseLeft {
|
|
m.clicks++
|
|
m.lastClick = fmt.Sprintf("klik #%d di (%d, %d)", m.clicks, msg.X, msg.Y)
|
|
m.sound.Play(audio.Click)
|
|
}
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (m Model) View() tea.View {
|
|
title := lipgloss.NewStyle().
|
|
Bold(true).
|
|
Foreground(lipgloss.Color("#cba6f7")).
|
|
Render("tia — Terminal Is A My Way")
|
|
tagline := lipgloss.NewStyle().
|
|
Foreground(lipgloss.Color("#a6adc8")).
|
|
Render("Just Work · Phase 0 · skeleton TUI + audio")
|
|
box := lipgloss.NewStyle().
|
|
Border(lipgloss.RoundedBorder()).
|
|
BorderForeground(lipgloss.Color("#6c7086")).
|
|
Padding(0, 2).
|
|
Render(m.lastClick + "\n\nklik / j / k = bunyi · q = keluar")
|
|
|
|
content := fmt.Sprintf("%s\n%s\n\n%s\n\nukuran jendela: %dx%d · audio: %s",
|
|
title, tagline, box, m.width, m.height, m.sound.Status())
|
|
|
|
v := tea.NewView(content)
|
|
v.AltScreen = true
|
|
v.MouseMode = tea.MouseModeCellMotion
|
|
return v
|
|
}
|