erste tests
This commit is contained in:
109
pipewiresetup/pipewiresetup.go
Normal file
109
pipewiresetup/pipewiresetup.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
type Styles struct {
|
||||
BorderColor lipgloss.Color
|
||||
title lipgloss.Style
|
||||
InputField lipgloss.Style
|
||||
quitText lipgloss.Style
|
||||
}
|
||||
|
||||
func DefaultStyles() *Styles {
|
||||
s := new(Styles)
|
||||
s.BorderColor = lipgloss.Color("36")
|
||||
s.InputField = lipgloss.NewStyle().BorderForeground(s.BorderColor).BorderStyle(lipgloss.NormalBorder()).Padding(1).Width(80)
|
||||
s.title = lipgloss.NewStyle().MarginLeft(2)
|
||||
s.quitText = lipgloss.NewStyle().Margin(1, 0, 2, 4)
|
||||
return s
|
||||
}
|
||||
|
||||
type model struct {
|
||||
Width int
|
||||
Height int
|
||||
SampleRate int
|
||||
BufferSize int
|
||||
SampleRateField textinput.Model
|
||||
BufferSizeField textinput.Model
|
||||
input int
|
||||
styles *Styles
|
||||
}
|
||||
|
||||
func New() *model {
|
||||
styles := DefaultStyles()
|
||||
SampleRateField := textinput.New()
|
||||
SampleRateField.Placeholder = "44100, 48000, 96000"
|
||||
BufferSizeField := textinput.New()
|
||||
BufferSizeField.Placeholder = "32, 64, 128, 256, 512, 1024, 2048"
|
||||
SampleRateField.Focus()
|
||||
return &model{
|
||||
SampleRate: 44100,
|
||||
BufferSize: 512,
|
||||
input: 0,
|
||||
SampleRateField: SampleRateField,
|
||||
BufferSizeField: BufferSizeField,
|
||||
styles: styles,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
return m, nil
|
||||
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+c":
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m model) View() string {
|
||||
if m.Width == 0 {
|
||||
return "loading..."
|
||||
} else {
|
||||
return lipgloss.Place(
|
||||
m.Width,
|
||||
m.Height,
|
||||
lipgloss.Center,
|
||||
lipgloss.Center,
|
||||
lipgloss.JoinVertical(
|
||||
lipgloss.Center,
|
||||
"Samplerate:",
|
||||
m.styles.InputField.Render(m.SampleRateField.View()),
|
||||
"BufferSize:",
|
||||
m.styles.InputField.Render(m.BufferSizeField.View()),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return "hello world"
|
||||
}
|
||||
|
||||
func main() {
|
||||
f, err := tea.LogToFile("debug.log", "debug")
|
||||
if err != nil {
|
||||
log.Fatalf("err: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
m := New()
|
||||
p := tea.NewProgram(m, tea.WithAltScreen())
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user