-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from braheezy/player-tui
feat: Add TUI for play command
- Loading branch information
Showing
13 changed files
with
547 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cmd | ||
|
||
import "github.com/charmbracelet/bubbles/key" | ||
|
||
type helpKeyMap struct { | ||
togglePlay key.Binding | ||
quit key.Binding | ||
} | ||
|
||
var helpsKeys = helpKeyMap{ | ||
togglePlay: key.NewBinding( | ||
key.WithKeys(" ", "p"), | ||
key.WithHelp("space/p", "play/pause"), | ||
), | ||
quit: key.NewBinding( | ||
key.WithKeys("q", "esc", "ctrl+c"), | ||
key.WithHelp("q/esc", "quit"), | ||
), | ||
} | ||
|
||
func (k helpKeyMap) ShortHelp() []key.Binding { | ||
return []key.Binding{k.togglePlay, k.quit} | ||
} | ||
func (k helpKeyMap) FullHelp() [][]key.Binding { | ||
return [][]key.Binding{ | ||
{k.togglePlay}, // first column | ||
{k.quit}, // second column | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cmd | ||
|
||
import "io" | ||
|
||
// NewQOAAudioReader creates a new QOAAudioReader instance. | ||
func NewQOAAudioReader(data []int16) *QOAAudioReader { | ||
return &QOAAudioReader{ | ||
data: data, | ||
pos: 0, | ||
} | ||
} | ||
|
||
// QOAAudioReader is a custom io.Reader that reads from QOA audio data. | ||
type QOAAudioReader struct { | ||
data []int16 | ||
pos int | ||
} | ||
|
||
func (r *QOAAudioReader) Read(p []byte) (n int, err error) { | ||
samplesToRead := len(p) / 2 | ||
|
||
if r.pos >= len(r.data) { | ||
// Return EOF when there is no more data to read | ||
return 0, io.EOF | ||
} | ||
|
||
if samplesToRead > len(r.data)-r.pos { | ||
samplesToRead = len(r.data) - r.pos | ||
} | ||
|
||
for i := 0; i < samplesToRead; i++ { | ||
sample := r.data[r.pos] | ||
p[i*2] = byte(sample & 0xFF) | ||
p[i*2+1] = byte(sample >> 8) | ||
r.pos++ | ||
} | ||
|
||
return samplesToRead * 2, nil | ||
} | ||
|
||
func (r *QOAAudioReader) SamplesPlayed() int { | ||
return r.pos | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import "github.com/charmbracelet/lipgloss" | ||
|
||
const ( | ||
padding = 4 | ||
maxWidth = 60 | ||
qoaRed = "#7b2165" | ||
qoaPink = "#dd81c7" | ||
black = "#191724" | ||
) | ||
|
||
var ( | ||
statusStyle = lipgloss.NewStyle(). | ||
Italic(true). | ||
Padding(1, 1). | ||
Foreground(lipgloss.Color(qoaPink)) | ||
) |
Oops, something went wrong.