chalk

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 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 top-level task as completed (strikethrough).

func Fail

func Fail(err error)

Fail marks the current top-level task as failed.

func Panic

func Panic(err error)

func Start

func Start(f spool.Spooler)

func SubDone

func SubDone()

SubDone marks the current subtask as completed (strikethrough).

func SubFail

func SubFail(err error)

SubFail marks the current subtask as failed.

func SubTask

func SubTask(label string)

SubTask begins a new sub-item under the current top-level task.

func Task

func Task(label string)

Task begins a new top-level task entry.

Types

type Reporter

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

Reporter drives the BubbleTea progress UI. Call Run() in the main goroutine and send progress events from a background goroutine.

func NewReporter

func NewReporter() *Reporter

NewReporter creates and wires a Reporter with a running BubbleTea program.

func (*Reporter) Done

func (r *Reporter) Done()

Done marks the current top-level task as completed (strikethrough).

func (*Reporter) Fail

func (r *Reporter) Fail(err error)

Fail marks the current top-level task as failed.

func (*Reporter) Quit

func (r *Reporter) Quit()

Quit tears down the BubbleTea program. Call this after all work is done.

func (*Reporter) Run

func (r *Reporter) Run() error

Run starts the BubbleTea event loop (blocking). Call this from main.

func (*Reporter) SubDone

func (r *Reporter) SubDone()

SubDone marks the current subtask as completed (strikethrough).

func (*Reporter) SubFail

func (r *Reporter) SubFail(err error)

SubFail marks the current subtask as failed.

func (*Reporter) SubTask

func (r *Reporter) SubTask(label string)

SubTask begins a new sub-item under the current top-level task.

func (*Reporter) Task

func (r *Reporter) Task(label string)

Task begins a new top-level task entry.

Jump to

Keyboard shortcuts

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