Documentation
¶
Overview ¶
Package utils provides common utility functions used across the OngoPlayer application.
Key Functions:
- FormatTime(): Converts seconds into a formatted MM:SS string.
- RenderBar(): Generates an ASCII progress bar for TUI usage.
- ScanFolder(): Scans a directory for supported audio files.
- Hex(): Parses a hex color string into a Gio-compatible color.NRGBA.
Dependencies:
- image/color: Used for color representation in Gio.
- os, path/filepath: Used for directory traversal and file path manipulation.
Example:
color := utils.Hex("#ff0000")
files, err := utils.ScanFolder("/music", map[string]bool{".mp3": true})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatTime ¶
FormatTime converts a duration in seconds into a formatted MM:SS string.
params:
secs: The duration in seconds.
returns:
string: Formatted time string (e.g., "3:05").
func Hex ¶
Hex parses a hexadecimal color string into an NRGBA color object used by Gio UI.
params:
hex: A hex string, either 6 characters (#RRGGBB) or 8 characters (#RRGGBBAA).
The leading "#" is optional.
returns:
color.NRGBA: The color object representing the hex string.
func RenderBar ¶
RenderBar generates an ASCII progress bar representing playback position. Primarily used for CLI or TUI output.
params:
pos: Current playback position in seconds.
dur: Total track duration in seconds.
barWidth: The character width of the progress bar.
returns:
string: The rendered ASCII progress bar.
func ScanFolder ¶
ScanFolder recursively scans a directory and extracts files that match supported extensions.
params:
dir: The directory path to scan.
supportedExts: A map of valid file extensions (e.g., {".mp3": true}).
returns:
[]string: A list of absolute file paths matching the extensions.
error: Returns if reading the directory fails.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.