Skip to content

refactor: replace go-colorful and x/term with stdlib#3

Merged
Jason-Adam merged 2 commits intomainfrom
refactor/drop-direct-deps-go-colorful-x-term
Mar 28, 2026
Merged

refactor: replace go-colorful and x/term with stdlib#3
Jason-Adam merged 2 commits intomainfrom
refactor/drop-direct-deps-go-colorful-x-term

Conversation

@Jason-Adam
Copy link
Copy Markdown
Owner

@Jason-Adam Jason-Adam commented Mar 28, 2026

Summary

  • Replace go-colorful direct dependency with inline RGB-to-HSL lightness calculation in isLightColor() (~6 lines of stdlib math)
  • Replace charmbracelet/x/term direct dependency with raw TIOCGWINSZ ioctl via syscall (platform-specific files: termsize_unix.go + termsize_other.go stub)
  • Both packages remain as transitive deps via lipgloss but are no longer part of our direct API surface (direct deps: 6 → 4)

Test plan

  • make check passes (fmt, vet, tests)
  • Verify powerline mode light/dark detection still works on a light terminal background
  • Verify terminal width detection works when running outside Claude Code pipe mode

🤖 Generated with Claude Code

Replace direct dependency on go-colorful with inline RGB-to-HSL
lightness calculation using stdlib image/color. Replace x/term with
a raw TIOCGWINSZ ioctl via syscall (unix) with a no-op stub for
non-unix platforms. Both packages remain as transitive deps via
lipgloss but are no longer part of our direct API surface.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 28, 2026 08:37
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces the project’s direct dependency surface by replacing two direct third-party usages (color lightness and terminal size detection) with stdlib-based implementations while keeping the packages as transitive deps via lipgloss.

Changes:

  • Replaced charmbracelet/x/term terminal size lookup with a Unix TIOCGWINSZ ioctl implementation plus a non-Unix stub.
  • Replaced go-colorful usage in light/dark background detection with an inline RGB→HSL lightness calculation.
  • Updated go.mod to drop x/term and go-colorful from direct requirements (remain indirect).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/gather/termsize_unix.go Adds Unix-only ioctl-based terminal width detection.
internal/gather/termsize_other.go Adds non-Unix stub returning 0 to trigger env-var fallback.
internal/gather/gather.go Switches terminal width detection to getTermWidth instead of term.GetSize.
go.mod Moves x/term and go-colorful from direct to indirect dependencies.
cmd/vitals/main.go Replaces go-colorful HSL lightness call with stdlib RGB-based lightness computation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Jason-Adam Jason-Adam self-assigned this Mar 28, 2026
Cover black, white, dark/light gray, mid-gray boundary (126 vs 128),
pure red, and dark blue to verify the RGB-to-HSL lightness threshold.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Jason-Adam Jason-Adam merged commit 0a495be into main Mar 28, 2026
1 check passed
@Jason-Adam Jason-Adam deleted the refactor/drop-direct-deps-go-colorful-x-term branch March 28, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants