Skip to content

Migration to Charm V2 libs - #5

Merged
DotoPototo merged 51 commits into
betafrom
migration
May 28, 2026
Merged

DotoPototo merged 51 commits into
betafrom
migration

Conversation

@DotoPototo

Copy link
Copy Markdown
Owner

Breaking Changes

  • Charm v2 imports. Replace github.com/charmbracelet/{bubbletea, bubbles, lipgloss} with charm.land/{bubbletea, bubbles, lipgloss}/v2. Model.View() now returns tea.View; use the new Model.Render() string to compose into a larger view.
  • Styles grouped into a Styles struct. Eleven individual public style fields (ValidCommandStyle, MatchHighlightStyle, SelectedRowStyle, etc.) are gone. Customize via bc.SetStyles(styles) / bc.Styles().
  • KeyMap is now a first-class public type. Override bindings via bc.SetKeyMap(km) / bc.KeyMap().
  • Model.Err privatized. Use bc.Error().
  • Completion and Argument interfaces unexported. They were never implementable externally (unexported methods); external extension will land via a future CompletionProvider API.
  • ArgumentType is now exported (previously argumentType). All existing constants (StringArgument, etc.) are unchanged.
  • Short flags must be a single ASCII letter. -1, -?, -é etc. are no longer valid. Use a long or PowerShell flag for non-letter names.
  • SelectedCommandMsg shape unchanged, but the wrapped error is now a typed *ValidationError.
  • History trimming corrected. Previously trimmed the wrong end of the buffer; now correctly retains the newest entries.
  • HistoryLimit <= 0 disables history. Previously undefined.

Added

  • Functional options. New(commands, width, opts ...Option) with 14 With* constructors: WithHistoryLimit, WithHistoryFilePath, WithPlaceholder, WithWidth, WithCompletionRows, WithCompletionsPosition, WithCompletionsOffset, WithIndentCompletions, WithAutotrim, WithScrollbar, WithBorderScroll, WithIcons, WithKeyMap, WithStyles, WithDescriptions.
  • Styles / KeyMap accessors for grouped configuration.
  • Model.Value() and Model.ValidationError() read-only state accessors for host integration.
  • Model.Error() error replaces the old Err field; clears on each successful operation.
  • Model.Error() error replaces the old Err field; clears on each successful operation.
  • Structured validation errors. *ValidationError exposes a ValidationErrorKind so hosts can route on errors.As without parsing error strings. Nine kinds: InvalidCommand, UnknownFlag, MalformedFlag, MissingFlagValue, InvalidArgumentValue, MissingPositionalArgument, UnexpectedArgument, PathNotFound, UnclosedQuote.
  • ShowDescriptions option. Hide the description column on completion rows.
  • Default placeholder. New models start with Enter command... — configurable via WithPlaceholder / SetPlaceholder.
  • Atomic history file writes. Save now goes through a temp file + rename, so a crash mid-write can't corrupt history.
  • Fuzz tests for tokenize, validateCommandInput, and getCompletions with a seed corpus covering empty input, quote variants, multi-byte runes, emoji, and tabs.
  • GitHub Actions CI: gofmt, go vet, race tests, and example build on every PR.

Updated

  • Unified tokenizer. splitInput, containsFlag/containsShortFlag/containsLongFlag, and command/subcommand detection all go through a single tokenize() that understands quotes. The whole parser/completion/validation stack now sees the same parse of any input.
  • ANSI/grapheme-aware width and truncation. Column sizing and description truncation use lipgloss.Width / ansi.Truncate; CJK, emoji, accented characters, and ANSI-styled content all lay out correctly.
  • Icon width-aware column sizing. Multi-cell icons (🐛) no longer mess up the title column.
  • Render is now side-effect free. Validation styling moved from Render into Update; Render calls are idempotent.
  • Layout safer on narrow terminals. New/SetWidth clamp width to ≥ 1, getCompletionsWidth respects narrow terminals (no more "60-cell completion box in a 20-cell terminal").
  • Completion offset accounts for the textinput prompt. Removes the pre-existing TODO about offset alignment under wrapping.
  • Scrollbar rendering extracted to a pure function with safety guards against zero height/total.
  • Stronger command/flag definition validation. Command.Validate() now rejects nil pointers, duplicate sibling names, duplicate flag aliases, duplicate positional argument names, the SubCommands + PositionalArguments combination, and whitespace in command names. Flag.Validate() rejects ---bodied short flags, whitespace in long/PowerShell flag bodies, and invalid ArgumentType values.
  • Negative-number flag values supported. --depth -1 and --threshold -0.5 now validate for IntArgument and FloatArgument flags.
  • Persistent flag value detection works on subcommands. Previously the value parsers ignored persistent flags inherited from parent commands.
  • Combined short flags resolve to the last char's flag. Matches the validation rule that only the last char in -xyz can be value-taking.

Bug Fixes

  • Fixed history trim direction — was dropping the newest entry on overflow.
  • Fixed file handle leak in SetHistoryFilePath (the os.Create result was never closed).
  • Fixed silent history save failures on submit — errors now surface via Model.Error().
  • Fixed splitPositionArgsAndFlags double-appending the same token when one of multiple flags matched.
  • Fixed long-flag detection missing end-of-input flags (git commit --amend with no trailing space).
  • Fixed command/subcommand detection matching inside quoted argument values.
  • Fixed validateCommandInput modulo panic when terminal width was 0.
  • Fixed validation MalformedFlag errors being swallowed by the long-flag fallback path.
  • Fixed empty history files producing a JSON EOF error on load.
  • Fixed resetModel leaving stale completionHolder, showAll, filteredHistory, lastInput, and validationErr across submits — caused the "tab on empty → enter → tab again" stale-state bug.
  • Fixed text input not displaying placeholder beyond the first character in v2 (needed SetWidth propagation to the embedded textinput).
  • Fixed space-key reset behavior. tea.KeyPressMsg.String() returns "space" in v2, which broke the old len(msg.String()) > 1 guard.

Documentation

  • README rewritten for v2: imports, View() tea.View, options at construction time, grouped Styles, KeyMap customization, history file setup, command validation rules, persistent flag behavior, PowerShell flag constraints, filesystem validation behavior, input parsing rules, concurrency note, intentional non-goals.
  • Godoc added on every exported identifier; package-level overview in doc.go.
  • BoolArgument now correctly documented as a presence flag (no value follows).

Internal

  • Tokenizer foundation in parse.go with a token struct carrying Raw/Unquoted/byte offsets/Quoted/Closed metadata.
  • History persistence moved to its own history.go.
  • bubblecomplete.go slimmed by ~30%.
  • TestCommands privatized (was leaking as public API); example now has its own demoCommands fixture.
  • Example re-unified into the root Go module — go run ./example works from the repo root.

DotoPototo added 30 commits May 27, 2026 11:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 33 changed files in this pull request and generated 2 comments.

Comment thread bubblecomplete.go Resolved
Comment thread validation.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 33 changed files in this pull request and generated 4 comments.

Comment thread render.go Resolved
Comment thread history.go Resolved
Comment thread styles.go Resolved
Comment thread render_test.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 33 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

render.go:284

  • calculateCompletionsOffset can return a negative offset when the completion box is wider than the terminal (e.g., long completion names). That negative value is passed into lipgloss.Margin, which can lead to incorrect layout and may panic depending on lipgloss internals. Clamp the overflow-adjusted offset to >= 0.
	offset += m.CompletionsOffset
	if offset+lipgloss.Width(completions) > m.width {
		offset = m.width - lipgloss.Width(completions) - 2
	}

Comment thread history.go Resolved
Comment thread example/main.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 29 out of 33 changed files in this pull request and generated 2 comments.

Comment thread validation.go Resolved
Comment thread validation.go Resolved
@socket-security

socket-security Bot commented May 28, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcharm.land/​bubbletea/​v2@​v2.0.699100100100100
Updatedgithub.com/​charmbracelet/​x/​ansi@​v0.4.1 ⏵ v0.11.799 -1100100100100
Addedcharm.land/​bubbles/​v2@​v2.1.0100100100100100
Addedcharm.land/​lipgloss/​v2@​v2.0.3100100100100100

View full report

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread history.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 30 out of 34 changed files in this pull request and generated no new comments.

@DotoPototo
DotoPototo merged commit 80bce8c into beta May 28, 2026
6 checks passed
@DotoPototo
DotoPototo deleted the migration branch May 28, 2026 12:52
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