From 365b64092a768284e75165880f67f9e1375dabda Mon Sep 17 00:00:00 2001 From: Matthew Breedlove Date: Sun, 17 Aug 2025 04:12:34 -0400 Subject: [PATCH] Powerline capability, better color support, custom colors, multiple install options, Output Style widget, UI cleanup --- CLAUDE.md | 92 +- README.md | 86 +- bun.lock | 534 +++++- eslint.config.js | 159 ++ package.json | 33 +- patches/{ink+6.1.0.patch => ink+6.2.0.patch} | 0 src/ccstatusline.ts | 125 +- src/tui.tsx | 1603 ----------------- src/tui/App.tsx | 467 +++++ src/tui/components/ColorMenu.tsx | 577 ++++++ src/tui/components/ConfirmDialog.tsx | 64 + src/tui/components/GlobalOverridesMenu.tsx | 314 ++++ src/tui/components/InstallMenu.tsx | 107 ++ src/tui/components/ItemsEditor.tsx | 436 +++++ src/tui/components/LineSelector.tsx | 118 ++ src/tui/components/MainMenu.tsx | 120 ++ .../components/PowerlineSeparatorEditor.tsx | 319 ++++ src/tui/components/PowerlineSetup.tsx | 461 +++++ src/tui/components/PowerlineThemeSelector.tsx | 226 +++ src/tui/components/StatusLinePreview.tsx | 98 + src/tui/components/TerminalOptionsMenu.tsx | 230 +++ src/tui/components/TerminalWidthMenu.tsx | 177 ++ src/tui/components/index.ts | 12 + src/tui/index.tsx | 1 + src/types/ClaudeSettings.ts | 12 + src/types/ColorEntry.ts | 10 + src/types/ColorLevel.ts | 29 + src/types/FlexMode.ts | 7 + src/types/PowerlineConfig.ts | 14 + src/types/PowerlineFontStatus.ts | 4 + src/types/RenderContext.ts | 12 + src/types/Settings.ts | 70 + src/types/StatusJSON.ts | 20 + src/types/TokenMetrics.ts | 20 + src/types/Widget.ts | 54 + src/types/index.ts | 19 + src/utils/claude-settings.ts | 54 +- src/utils/colors.ts | 444 +++++ src/utils/config.ts | 247 +-- src/utils/guid.ts | 11 + src/utils/migrations.ts | 141 ++ src/utils/powerline.ts | 336 ++++ src/utils/renderer.ts | 1100 ++++++----- src/utils/terminal.ts | 107 ++ src/utils/widgets.ts | 54 + src/widgets/ContextLength.ts | 28 + src/widgets/ContextPercentage.ts | 28 + src/widgets/ContextPercentageUsable.ts | 28 + src/widgets/CustomCommand.tsx | 219 +++ src/widgets/CustomText.tsx | 91 + src/widgets/GitBranch.ts | 44 + src/widgets/GitChanges.ts | 67 + src/widgets/Model.ts | 27 + src/widgets/OutputStyle.ts | 27 + src/widgets/SessionClock.ts | 27 + src/widgets/TerminalWidth.ts | 30 + src/widgets/TokensCached.ts | 28 + src/widgets/TokensInput.ts | 28 + src/widgets/TokensOutput.ts | 28 + src/widgets/TokensTotal.ts | 28 + src/widgets/Version.ts | 27 + src/widgets/index.ts | 16 + 62 files changed, 7484 insertions(+), 2411 deletions(-) create mode 100644 eslint.config.js rename patches/{ink+6.1.0.patch => ink+6.2.0.patch} (100%) delete mode 100644 src/tui.tsx create mode 100644 src/tui/App.tsx create mode 100644 src/tui/components/ColorMenu.tsx create mode 100644 src/tui/components/ConfirmDialog.tsx create mode 100644 src/tui/components/GlobalOverridesMenu.tsx create mode 100644 src/tui/components/InstallMenu.tsx create mode 100644 src/tui/components/ItemsEditor.tsx create mode 100644 src/tui/components/LineSelector.tsx create mode 100644 src/tui/components/MainMenu.tsx create mode 100644 src/tui/components/PowerlineSeparatorEditor.tsx create mode 100644 src/tui/components/PowerlineSetup.tsx create mode 100644 src/tui/components/PowerlineThemeSelector.tsx create mode 100644 src/tui/components/StatusLinePreview.tsx create mode 100644 src/tui/components/TerminalOptionsMenu.tsx create mode 100644 src/tui/components/TerminalWidthMenu.tsx create mode 100644 src/tui/components/index.ts create mode 100644 src/tui/index.tsx create mode 100644 src/types/ClaudeSettings.ts create mode 100644 src/types/ColorEntry.ts create mode 100644 src/types/ColorLevel.ts create mode 100644 src/types/FlexMode.ts create mode 100644 src/types/PowerlineConfig.ts create mode 100644 src/types/PowerlineFontStatus.ts create mode 100644 src/types/RenderContext.ts create mode 100644 src/types/Settings.ts create mode 100644 src/types/StatusJSON.ts create mode 100644 src/types/TokenMetrics.ts create mode 100644 src/types/Widget.ts create mode 100644 src/types/index.ts create mode 100644 src/utils/colors.ts create mode 100644 src/utils/guid.ts create mode 100644 src/utils/migrations.ts create mode 100644 src/utils/powerline.ts create mode 100644 src/utils/terminal.ts create mode 100644 src/utils/widgets.ts create mode 100644 src/widgets/ContextLength.ts create mode 100644 src/widgets/ContextPercentage.ts create mode 100644 src/widgets/ContextPercentageUsable.ts create mode 100644 src/widgets/CustomCommand.tsx create mode 100644 src/widgets/CustomText.tsx create mode 100644 src/widgets/GitBranch.ts create mode 100644 src/widgets/GitChanges.ts create mode 100644 src/widgets/Model.ts create mode 100644 src/widgets/OutputStyle.ts create mode 100644 src/widgets/SessionClock.ts create mode 100644 src/widgets/TerminalWidth.ts create mode 100644 src/widgets/TokensCached.ts create mode 100644 src/widgets/TokensInput.ts create mode 100644 src/widgets/TokensOutput.ts create mode 100644 src/widgets/TokensTotal.ts create mode 100644 src/widgets/Version.ts create mode 100644 src/widgets/index.ts diff --git a/CLAUDE.md b/CLAUDE.md index 1eda233..9aeff20 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -14,77 +14,77 @@ ccstatusline is a customizable status line formatter for Claude Code CLI that di # Install dependencies bun install -# Run locally (TUI mode) -bun run src/ccstatusline.ts +# Run with patch (TUI mode) +bun run start + +# Run directly (TUI mode) +bun run statusline # Test with piped input echo '{"model":{"display_name":"Claude 3.5 Sonnet"},"transcript_path":"test.jsonl"}' | bun run src/ccstatusline.ts # Build for npm distribution -bun run build # Creates dist/ccstatusline.js +bun run build # Creates dist/ccstatusline.js with Node.js 14+ compatibility -# Test npm package locally -npm link -echo '{"model":{"display_name":"Claude 3.5 Sonnet"},"transcript_path":"test.jsonl"}' | ccstatusline +# Lint and type check +bun run lint # Runs TypeScript type checking and ESLint with auto-fix ``` ## Architecture -The project has dual runtime compatibility - it works with both Bun and Node.js: +The project has dual runtime compatibility - works with both Bun and Node.js: +### Core Structure - **src/ccstatusline.ts**: Main entry point that detects piped vs interactive mode - Piped mode: Parses JSON from stdin and renders formatted status line - Interactive mode: Launches React/Ink TUI for configuration - -- **src/tui.tsx**: React-based terminal UI using Ink for configuration interface - - Item management (add/remove/reorder status items) - - Color customization for different elements - -- **src/config.ts**: Settings management + +### TUI Components (src/tui/) +- **index.tsx**: Main TUI entry point that handles React/Ink initialization +- **App.tsx**: Root component managing navigation and state +- **components/**: Modular UI components for different configuration screens + - MainMenu, LineSelector, ItemsEditor, ColorMenu, GlobalOverridesMenu + - PowerlineSetup, TerminalOptionsMenu, StatusLinePreview + +### Utilities (src/utils/) +- **config.ts**: Settings management - Loads from `~/.config/ccstatusline/settings.json` - Handles migration from old settings format - Default configuration if no settings exist - -- **npm publishing**: Uses `--packages=external` to keep dependencies external for cross-platform compatibility +- **renderer.ts**: Core rendering logic for status lines + - Handles terminal width detection and truncation + - Applies colors, padding, and separators + - Manages flex separator expansion +- **powerline.ts**: Powerline font detection and installation +- **claude-settings.ts**: Integration with Claude Code settings.json +- **colors.ts**: Color definitions and ANSI code mapping ## Key Implementation Details -- **Cross-platform stdin reading**: Code detects Bun vs Node.js environment and uses appropriate stdin API +- **Cross-platform stdin reading**: Detects Bun vs Node.js environment and uses appropriate stdin API - **Token metrics**: Parses Claude Code transcript files (JSONL format) to calculate token usage -- **Git integration**: Uses child_process.execSync to get current branch -- **80-char limit**: Status line always formats to exactly 80 characters for Claude Code compatibility +- **Git integration**: Uses child_process.execSync to get current branch and changes +- **Terminal width management**: Three modes for handling width (full, full-minus-40, full-until-compact) - **Flex separators**: Special separator type that expands to fill available space +- **Powerline mode**: Optional Powerline-style rendering with arrow separators +- **Custom commands**: Execute shell commands and display output in status line +- **Mergeable items**: Items can be merged together with or without padding ## Bun Usage Preferences -Default to using Bun instead of Node.js. - +Default to using Bun instead of Node.js: - Use `bun ` instead of `node ` or `ts-node ` -- Use `bun test` instead of `jest` or `vitest` -- Use `bun build ` instead of `webpack` or `esbuild` -- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install` -- Use `bun run