dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

commit 4d0197b3e80f4361415facf8e0e167518927653e
parent 665ce9b924335072c4359d19e5094b19819d084e
Author: regexghost <regexghost@protonmail.com>
Date:   Tue, 12 May 2026 21:31:34 +0100

added soundboard

Diffstat:
M.gitignore | 5+----
Mterminal-scripts/Makefile | 1+
Aterminal-scripts/soundboard/go.mod | 14++++++++++++++
Aterminal-scripts/soundboard/soundboard.go | 162+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 178 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,4 +1 @@ -panel-scripts/uptime -panel-scripts/network_down -panel-scripts/network_up -panel-scripts/cpu +terminal-scripts/soundboard/go.sum diff --git a/terminal-scripts/Makefile b/terminal-scripts/Makefile @@ -15,3 +15,4 @@ normal: mv tablealigner ${BIN}/tablealigner go build -o geohash geohash.go mv geohash ${BIN}/geohash + cd soundboard/; go1.26.2 build -o soundboard soundboard.go; mv soundboard ${BIN}/soundboard; cd .. diff --git a/terminal-scripts/soundboard/go.mod b/terminal-scripts/soundboard/go.mod @@ -0,0 +1,14 @@ +module soundboard + +go 1.24.0 + +require github.com/gdamore/tcell/v2 v2.13.9 + +require ( + github.com/gdamore/encoding v1.0.1 // indirect + github.com/lucasb-eyer/go-colorful v1.3.0 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + golang.org/x/sys v0.38.0 // indirect + golang.org/x/term v0.37.0 // indirect + golang.org/x/text v0.31.0 // indirect +) diff --git a/terminal-scripts/soundboard/soundboard.go b/terminal-scripts/soundboard/soundboard.go @@ -0,0 +1,162 @@ +package main + +import ( + "fmt" + "encoding/csv" + "github.com/gdamore/tcell/v2" + "os" + "os/exec" +) + +var styles = map[string]tcell.Style{} +var termHeight int +var termWidth int + +var homeDir string + +type sound struct { + name string + path string + key rune +} + +var sounds []sound + +var cmds []*exec.Cmd + +const CONFIG_FILE=".config/regexghost/soundboard.csv" +const SOUND_LOC=".local/share/regexghost/sounds" + +// Function to allow adding strings to screen instead of just individual runes (chars) +func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) { + row := y1 + col := x1 + for _, r := range []rune(text) { + s.SetContent(col, row, r, nil, style) + col++ + if col >= x2 { + row++ + col = x1 + } + if row > y2 { + break + } + } +} + +func errorOut(e string) { + fmt.Println(e) + os.Exit(1) +} + +func loadSounds() { + file, err := os.Open(homeDir + "/" + CONFIG_FILE) + + if err != nil { + errorOut("Error, config file not present") + } + + defer file.Close() + + reader := csv.NewReader(file) + records, err := reader.ReadAll() + + if err != nil { + errorOut("Error parsing csv file") + } + + for _, record := range records { + key := rune(record[0][0]) + newSound := sound { + name: record[1], + path: record[2], + key: key, + } + sounds = append(sounds, newSound) + fmt.Println(newSound) + } +} + +func drawSoundboard(s tcell.Screen) { + s.Clear() + drawText(s, 0, 0, 50, 10, styles["pink"], "Soundboard") + for i, soundEntry := range sounds { + line := string(soundEntry.key) + ": " + soundEntry.name + drawText(s, 0, i+2, 50, 100, styles["blue"], line) + } +} + +func playSound(path string) { + cmd := exec.Command("mpv", "--no-config", "--no-resume-playback", "--force-window=no", homeDir + "/" + SOUND_LOC + "/" + path) + cmds = append(cmds, cmd) + cmd.Start() +} + +func killSounds() { + for _, cmd := range cmds { + cmd.Process.Kill() + } +} + +func findAndPlaySound(key rune) { + for _, soundEntry := range sounds { + if soundEntry.key == key { + playSound(soundEntry.path) + } + } +} + +func main() { + homeDir, _ = os.UserHomeDir() + + loadSounds() + + s, err := tcell.NewScreen() + if err != nil { + panic(err) + } + err = s.Init() + if err != nil { + panic(err) + } + + // Create colours + blueColour := tcell.NewHexColor(0x38ffea) + pinkColour := tcell.NewHexColor(0xff76c1) + + // Use the colours to make styles and add to "styles" map + styles["white"] = tcell.StyleDefault.Background(tcell.ColorReset).Foreground(tcell.ColorReset) + styles["blue"] = tcell.StyleDefault.Background(tcell.ColorReset).Foreground(blueColour) + styles["pink"] = tcell.StyleDefault.Background(tcell.ColorReset).Foreground(pinkColour) + + s.SetStyle(styles["white"]) + s.Clear() + + quit := func() { + s.Fini() + os.Exit(0) + } + + for { + s.Show() + + drawSoundboard(s) + ev := s.PollEvent() + + switch ev := ev.(type) { + case *tcell.EventResize: + s.Sync() + case *tcell.EventKey: + if ev.Key() == tcell.KeyRune { + if ev.Rune() == 'q' { + killSounds() + quit() + } else if ev.Rune() == ' ' { + killSounds() + } else { + findAndPlaySound(ev.Rune()) + } + } + } + } +}