chalk

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 14 Imported by: 0

README

chalk

Task-oriented I/O helper for Golang CLI. It wires together flag-driven input/output routing (local filesystem, S3, stdin/stdout) with a live terminal progress UI so you can focus on the processing logic.

Features

  • Resolves input from a local directory (-I ./path), an S3 bucket (-I s3://bucket), explicit file arguments, or stdin
  • Resolves output to a local directory (-O ./path), an S3 bucket (-O s3://bucket), a single file (-o out.txt), or stdout
  • Renders a live progress tree with elapsed timers, spinner, and per-task pass/fail status

Quick Start

package main

import (
  "context"

  "github.com/fogfish/chalk"
)

func process(ctx context.Context, path string, r io.Reader, w io.Writer) error {
  chalk.Task(path)

  chalk.SubTask("read")
  // ... read from fs
  chalk.SubDone()

  chalk.SubTask("transform")
  // ... do work
  chalk.SubDone()

  chalk.Done()
  return nil
}

func main() {
  chalk.Start(process)
}

Run it:

mytool -I ./input -O ./output
mytool -I s3://my-bucket -O s3://out-bucket
cat file.txt | mytool

License

See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Done

func Done()

Done marks the current task as successfully completed.

func Fail

func Fail(err error)

Fail marks the current task as failed.

func Panic

func Panic(err error)

Panic prints a fatal error, fails all pending tasks, and exits with code 1.

func Printf added in v0.0.4

func Printf(format string, args ...any)

Printf prints a formatted, multi-line message indented under the current task.

func Start

func Start(f spool.Spooler)

Start wires up the default Reporter, parses flags, and runs the provided Spooler. It is the main entry-point for CLI tools built on this library.

func Task

func Task(level int, label string, args ...any)

Task begins a new task at the given nesting level. Any active tasks at the same or deeper level are auto-completed first.

Types

type Reporter

type Reporter struct {
	// contains filtered or unexported fields
}

Reporter manages classical terminal output with a live spinner for the active task and a scrolling history of completed / failed tasks above it.

func NewReporter

func NewReporter() *Reporter

NewReporter creates a Reporter that writes to stderr.

func (*Reporter) Done

func (r *Reporter) Done()

Done marks the current (innermost) task as successfully completed.

func (*Reporter) Fail

func (r *Reporter) Fail(err error)

Fail marks the current (innermost) task as failed. err is printed as an indented paragraph beneath the task line.

func (*Reporter) Printf added in v0.0.4

func (r *Reporter) Printf(format string, args ...any)

Printf prints a formatted, multi-line message indented one level deeper than the current task. The spinner is stopped for the duration of the write and restarted afterwards so the output line does not get overwritten.

func (*Reporter) Quit

func (r *Reporter) Quit()

Quit stops the spinner and marks all remaining tasks as done. Call this when all work has been completed.

func (*Reporter) Task

func (r *Reporter) Task(level int, label string, args ...any)

Task begins a new task at the given nesting level. Any currently active tasks at the same or deeper level are automatically completed before the new task starts, which simplifies error handling — callers do not need to guarantee a matching Done/Fail on every code path.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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