Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@ module github.com/some-programs/pipmix
go 1.27

require (
charm.land/bubbletea/v2 v2.1.2
charm.land/lipgloss/v2 v2.1.1
github.com/charmbracelet/ultraviolet v0.0.0-20261119151026-8ecbcf0e188c
github.com/charmbracelet/x/ansi v0.11.10
github.com/charmbracelet/x/term v0.2.2
github.com/godbus/dbus/v5 v5.2.4
github.com/muesli/cancelreader v0.2.2
github.com/pelletier/go-toml/v2 v2.4.3
github.com/peterbourgon/ff/v3 v3.4.0
)

require (
github.com/charmbracelet/colorprofile v0.4.3 // indirect
github.com/charmbracelet/ultraviolet v0.0.0-20261119151026-8ecbcf0e188c // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/charmbracelet/x/termios v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.11.0 // indirect
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
github.com/lucasb-eyer/go-colorful v1.4.1 // indirect
github.com/mattn/go-runewidth v0.0.31 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v1.3.1 // indirect
golang.org/x/sync v0.25.0 // indirect
Expand Down
15 changes: 0 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
charm.land/bubbletea/v2 v2.1.2-0.20261112134521-6b30ecf3280d h1:vUXQwg+Wu2W/j3meguShWTWeKGgeKOrmbIpX+K37yVA=
charm.land/bubbletea/v2 v2.1.2-0.20261112134521-6b30ecf3280d/go.mod h1:xWHeyxIX9/wiFU2kgPW04ojOZyTzrWf+8lGjUCaftiU=
charm.land/bubbletea/v2 v2.1.2 h1:vB3XAcHhLB2gR3HOHpwO3lHB3nbvaowIgL3e5x/DUZo=
charm.land/bubbletea/v2 v2.1.2/go.mod h1:xWHeyxIX9/wiFU2kgPW04ojOZyTzrWf+8lGjUCaftiU=
charm.land/lipgloss/v2 v2.1.1 h1:F+vKWis9Kz3MFRsbICSDFtT1ZwVL+8f+36Dtg+OpKwc=
charm.land/lipgloss/v2 v2.1.1/go.mod h1:k79y/56yThpkJvbwyrcHr8MyZF42e84Q5fW9Ibu6LFc=
github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o=
github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w=
github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q=
github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q=
github.com/charmbracelet/ultraviolet v0.0.0-20261023060817-a45b7c86333f h1:D2JpB65eehsnkEwEG401dMBSNYtTDgvKXZZSl7ZCxWI=
github.com/charmbracelet/ultraviolet v0.0.0-20261023060817-a45b7c86333f/go.mod h1:aJDVk+WOVM1K04rdc/71PMPoUGfjxjhvXfP3Pjz1Zio=
github.com/charmbracelet/ultraviolet v0.0.0-20261119151026-8ecbcf0e188c h1:izHJ6cjHd9HGtre1J+c/+QE3rQZ2t4EZH6BqykQbpjc=
github.com/charmbracelet/ultraviolet v0.0.0-20261119151026-8ecbcf0e188c/go.mod h1:aJDVk+WOVM1K04rdc/71PMPoUGfjxjhvXfP3Pjz1Zio=
github.com/charmbracelet/x/ansi v0.11.9 h1:kIrqLBxtTVbLyyHO2Evoi93EjQo1mylWmpNEsfPxXAM=
github.com/charmbracelet/x/ansi v0.11.9/go.mod h1:DG/hpOnaI2QJ/KMMqLL2h0KVhluuJLazf8973P+Vy5w=
github.com/charmbracelet/x/ansi v0.11.10 h1:GjcX3+rAk+8wDX/jY0XwrZstxkjRcLkYU3TvwzZWiRA=
github.com/charmbracelet/x/ansi v0.11.10/go.mod h1:DG/hpOnaI2QJ/KMMqLL2h0KVhluuJLazf8973P+Vy5w=
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I=
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY=
Expand All @@ -36,7 +22,6 @@ github.com/mattn/go-runewidth v0.0.31 h1:1oCV4ReTlosDBc6rYRw5cL8S/4y8iv5oRl4SJ5I
github.com/mattn/go-runewidth v0.0.31/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml/v2 v2.4.3 h1:GTRvJQutkOSftxIFD5xw9aepkYNuPWmVJpffdDPYVpY=
github.com/pelletier/go-toml/v2 v2.4.3/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/peterbourgon/ff/v3 v3.4.0 h1:QBvM/rizZM1cB0p0lGMdmR7HxZeI/ZrBWB4DqLkMUBc=
Expand Down
87 changes: 87 additions & 0 deletions internal/pipmix/frame_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package pipmix

import (
"fmt"
"testing"

"github.com/some-programs/pipmix/internal/pulse"
"github.com/some-programs/pipmix/internal/pw"
"github.com/some-programs/pipmix/internal/tui"
)

// benchMixer returns a mixer on the playback tab of a w×h terminal with
// more streams than fit, all metered.
func benchMixer(w, h int) mixer {
snap := testSnapshot()
for i := range 20 {
snap.Nodes = append(snap.Nodes, pw.Node{ID: uint32(100 + i), Class: pw.Playback, Name: fmt.Sprint("n", i), Title: fmt.Sprint("Player ", i), Channels: stereo(0.5)})
}
m := newMixer(pw.NewClient(nil), nil, pulse.NewMeter(nil, 0), quitKeys(), defaultOptions())
m.snap = snap
m.fill = make(map[uint32][]float64)
for _, n := range snap.Nodes {
m.fill[n.ID] = make([]float64, len(n.Channels))
}
m.setSize(w, h)
m.refocus()
m.setTab(tabPlayback)
return m
}

// setBenchLevels moves every meter, keeping them below the faders.
func setBenchLevels(m *mixer, i int) {
for id, levels := range m.fill {
for ch := range levels {
levels[ch] = float64((int(id)*13+ch*29+i*7)%100) / 250
}
}
}

type countWriter struct{ n int }

func (w *countWriter) Write(p []byte) (int, error) {
w.n += len(p)
return len(p), nil
}

// BenchmarkFrameMeters measures a frame in which only the meters moved.
func BenchmarkFrameMeters(b *testing.B) {
m := benchMixer(200, 50)
g := tui.NewGrid(0, 0)
var w countWriter
s := tui.NewScreen(&w)
m.draw(g)
if err := s.Flush(g); err != nil {
b.Fatal(err)
}
w.n = 0
i := 0
for b.Loop() {
setBenchLevels(&m, i)
i++
m.drawMeters(g)
if err := s.Flush(g); err != nil {
b.Fatal(err)
}
}
b.ReportMetric(float64(w.n)/float64(b.N), "bytes/frame")
}

// BenchmarkFrameFull measures a frame after an event, which redraws the
// whole screen.
func BenchmarkFrameFull(b *testing.B) {
m := benchMixer(200, 50)
g := tui.NewGrid(0, 0)
var w countWriter
s := tui.NewScreen(&w)
i := 0
for b.Loop() {
setBenchLevels(&m, i)
i++
m.draw(g)
if err := s.Flush(g); err != nil {
b.Fatal(err)
}
}
b.ReportMetric(float64(w.n)/float64(b.N), "bytes/frame")
}
77 changes: 35 additions & 42 deletions internal/pipmix/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,65 @@ import (
"slices"
"strings"

"charm.land/lipgloss/v2"
"github.com/charmbracelet/x/ansi"

"github.com/some-programs/pipmix/internal/tui"
)

var (
helpSectionStyle = lipgloss.NewStyle().Bold(true)
helpRuleStyle = ansi.Style{}.Underline(true).UnderlineColor(ansi.BrightBlack)
helpSectionStyle = tui.Style{Attrs: tui.Bold}
helpRuleStyle = tui.Style{Attrs: tui.Underline, UnderlineColor: tui.BrightBlack}
)

const helpGap = 3

type helpLine struct {
text string
rule bool // underlined separator at the end of a binding
text string
style tui.Style
rule bool // underlined separator at the end of a binding
}

// helpLines formats the current tab's help into columns fitting width and height.
func (m *mixer) helpLines(width, height int) []string {
// helpColumns arranges the current tab's help into columns fitting width
// and height.
func (m *mixer) helpColumns(width, height int) [][]helpLine {
var blocks [][]helpLine
for _, s := range m.tabSections() {
blocks = append(blocks, helpBlock(s, width))
}
columns := arrangeColumns(blocks, width, height)
lines := make([]string, tallest(columns))
for i := range lines {
var b strings.Builder
return arrangeColumns(blocks, width, height)
}

// scrollHelp scrolls the help by delta lines, within its length.
func (m *mixer) scrollHelp(delta int) {
h := m.listHeight()
n := tallest(m.helpColumns(m.width, h))
m.helpOff = max(0, min(m.helpOff+delta, n-h))
}

// drawHelp draws the visible lines of the help into the h rows of the list.
func (m *mixer) drawHelp(g *tui.Grid, h int) {
columns := m.helpColumns(m.width, h)
widths := make([]int, len(columns))
for c, col := range columns {
widths[c] = columnWidth(col)
}
for i := m.helpOff; i < min(tallest(columns), m.helpOff+h); i++ {
p := g.Pen(0, listTop+i-m.helpOff, m.width)
for c, col := range columns {
if c > 0 {
b.WriteString(strings.Repeat(" ", helpGap))
p.Repeat(" ", helpGap, plain)
}
var line helpLine
if i < len(col) {
line = col[i]
}
text := fit(line.text, columnWidth(col))
st, pad := line.style, plain
if line.rule {
text = helpRuleStyle.Styled(text)
st, pad = helpRuleStyle, helpRuleStyle
}
b.WriteString(text)
p.Fit(line.text, widths[c], st, pad)
}
lines[i] = fit(b.String(), width)
}
return lines
}

// scrollHelp scrolls the help by delta lines, within its length.
func (m *mixer) scrollHelp(delta int) {
h := m.listHeight()
n := len(m.helpLines(m.width, h))
m.helpOff = max(0, min(m.helpOff+delta, n-h))
}

// helpView renders the visible lines of the help.
func (m *mixer) helpView(width, height int) []string {
lines := m.helpLines(width, height)
end := min(len(lines), m.helpOff+height)
return lines[min(m.helpOff, end):end]
}

func tallest(columns [][]helpLine) int {
Expand Down Expand Up @@ -97,7 +99,7 @@ func helpBlock(s section, width int) []helpLine {
}
}
textIndent := len(indent) + keysWidth + 2
lines := []helpLine{{text: helpSectionStyle.Render(ansi.Truncate(s.title, width, "…"))}}
lines := []helpLine{{text: ansi.Truncate(s.title, width, "…"), style: helpSectionStyle}}
for _, b := range s.bindings {
inputs := b.inputs()
text := strings.Split(ansi.Wrap(b.help, max(1, width-textIndent), ""), "\n")
Expand All @@ -110,7 +112,7 @@ func helpBlock(s section, width int) []helpLine {
if r < len(text) {
line += strings.Repeat(" ", textIndent-ansi.StringWidth(line)) + text[r]
}
lines = append(lines, helpLine{ansi.Truncate(line, width, "…"), r == rows-1})
lines = append(lines, helpLine{text: ansi.Truncate(line, width, "…"), rule: r == rows-1})
}
}
return lines
Expand Down Expand Up @@ -160,12 +162,3 @@ func arrangeColumns(blocks [][]helpLine, width, height int) [][]helpLine {
}
return best
}

// fit truncates or pads s to width cells.
func fit(s string, width int) string {
if width <= 0 {
return ""
}
s = ansi.Truncate(s, width, "…")
return s + strings.Repeat(" ", max(0, width-ansi.StringWidth(s)))
}
Loading