Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Not released as a prebuilt binary yet, but it already runs. With Go 1.23+ instal
# Run straight from a clone
git clone https://github.com/rwrife/commit-sprout
cd commit-sprout
go run . # prints the current plant (an ASCII seedling for now)
go run . # renders the live plant for the repo you're in (add --no-color for plain ASCII)

# Or install the binary onto your PATH
go install github.com/rwrife/commit-sprout@latest
Expand All @@ -68,6 +68,12 @@ tagged release. Watch the repo.
3. Persist a little state (`~/.config/commit-sprout/state.json`) so the plant remembers its best
days and your streak.
4. Render ASCII. No cloud. No telemetry. We never read your code — just commit counts and times.
_(Implemented — M4. `internal/render` draws real ASCII art for every stage × health combo
(the plant visibly droops as it dries out), plus a caption block with stage, streak, last
commit, and a days-until-wilt nudge. Color is via `lipgloss`; the plain-ASCII path is used
automatically for `--no-color`, the `NO_COLOR` env var, and any non-TTY/piped output, so it
stays pipe-safe. `commit-sprout` now renders the live plant for your repo instead of a static
seedling — persisting its memory across runs arrives with M5.)_

## Tech

Expand Down
63 changes: 61 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import (
"errors"
"fmt"
"os"
"time"

"github.com/mattn/go-isatty"
"github.com/rwrife/commit-sprout/internal/gitstat"
"github.com/rwrife/commit-sprout/internal/plant"
"github.com/rwrife/commit-sprout/internal/render"
"github.com/spf13/cobra"
)
Expand All @@ -24,6 +27,9 @@ var version = "dev"
// showActivity backs the hidden --activity debug flag (M2 bridge).
var showActivity bool

// noColor backs the --no-color flag, forcing the plain-ASCII render path.
var noColor bool

// rootCmd is the base command invoked as `commit-sprout` with no subcommand.
var rootCmd = &cobra.Command{
Use: "commit-sprout",
Expand All @@ -41,11 +47,60 @@ Run with no arguments to render the current plant.`,
if showActivity {
return printActivity(cmd)
}
_, err := fmt.Fprintln(cmd.OutOrStdout(), render.Seedling())
return err
return renderPlant(cmd)
},
}

// renderPlant runs the full pipeline for the current repo: read git activity,
// compute the plant state, and render a framed ASCII plant to stdout. This is
// the real M4 default flow, replacing the M1 hard-coded seedling.
//
// State persistence (M5) is not wired yet, so a zero plant.State is used; the
// memory floor still behaves correctly from a fresh state, and M5 will load the
// remembered highest stage/streak here.
func renderPlant(cmd *cobra.Command) error {
out := cmd.OutOrStdout()

act, err := gitstat.Read("", gitstat.DefaultWindowDays)
if err != nil {
if errors.Is(err, gitstat.ErrNotARepo) {
_, perr := fmt.Fprintln(out,
"Not a git repository \u2014 nothing growing here yet. "+
"Run commit-sprout inside a repo.")
return perr
}
return err
}

now := time.Now()
ps := plant.Compute(act, plant.State{}, now)

frame := render.Frame(ps, render.Options{
Color: useColor(cmd),
Now: now,
LastCommit: act.LastCommit,
})
_, perr := fmt.Fprintln(out, frame)
return perr
}

// useColor decides whether to take the color render path. Color is disabled by
// --no-color, by the NO_COLOR environment variable (any value), and whenever
// stdout is not a terminal (piped/redirected), keeping output pipe-safe.
func useColor(cmd *cobra.Command) bool {
if noColor {
return false
}
if _, ok := os.LookupEnv("NO_COLOR"); ok {
return false
}
f, ok := cmd.OutOrStdout().(*os.File)
if !ok {
return false
}
return isatty.IsTerminal(f.Fd()) || isatty.IsCygwinTerminal(f.Fd())
}

// printActivity renders the parsed Activity for the current repo. It is a
// temporary M2 debugging aid behind the hidden --activity flag; the real
// pipeline (activity -> plant -> render) arrives in later milestones.
Expand Down Expand Up @@ -100,6 +155,10 @@ func init() {
// Match the documented interface in README/PLAN: `--version` prints version.
rootCmd.SetVersionTemplate("commit-sprout {{.Version}}\n")

// --no-color forces the plain-ASCII render path (also honored via NO_COLOR
// and automatically for non-TTY output).
rootCmd.Flags().BoolVar(&noColor, "no-color", false, "disable color output (plain ASCII)")

// Hidden M2 bridge: dump parsed git activity. Removed once M3+ consume it.
rootCmd.Flags().BoolVar(&showActivity, "activity", false, "print parsed git activity (debug)")
_ = rootCmd.Flags().MarkHidden("activity")
Expand Down
13 changes: 12 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ module github.com/rwrife/commit-sprout

go 1.23.4

require github.com/spf13/cobra v1.10.2
require (
github.com/charmbracelet/lipgloss v0.13.0
github.com/mattn/go-isatty v0.0.20
github.com/spf13/cobra v1.10.2
)

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/x/ansi v0.1.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.9 // indirect
golang.org/x/sys v0.19.0 // indirect
)
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
github.com/charmbracelet/x/ansi v0.1.4 h1:IEU3D6+dWwPSgZ6HBH+v6oUuZ/nVawMiWj5831KfiLM=
github.com/charmbracelet/x/ansi v0.1.4/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Loading
Loading