utils

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 6 Imported by: 0

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

func FormatTime(secs float64) string

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

func Hex(hex string) color.NRGBA

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

func RenderBar(pos, dur float64, barWidth int) string

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

func ScanFolder(dir string, supportedExts map[string]bool) ([]string, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL