Skip to content

feat(prompt): SegmentId::Vcs native segment — wire the #292 git2 renderer into the segments engine (1.4.1) - #332

Merged
caomengxuan666 merged 1 commit into
masterfrom
feat/vcs-native-segment
Oct 14, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
feat/vcs-native-segment

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #331. Milestone: 1.4.1 (owner ruling 2026-10-14; no GitHub milestone object exists on the repo, noted here per issue title).

What

The oh-my-niu bundle's prompts/segments.toml declares [segments.git] id = "vcs"; the segments engine had no Vcs variant — a socket with no power. This lands the native segment:

Performance (scope 4)

Tests (scope 3/5)

  • from_name matrix: vcs/git/VCS/Git/GIT/v-c-s/v_c_s → Vcs; near-misses (gitstatus, vc, gitbash) stay None. Updates the Interactive startup hangs on host-side async git-status thread; remove built-in git prompt + theme stack (owner decision) #145-era assertion that "vcs" resolves to None.
  • Render matrix (windows-gated, git2 is a target dep): non-repo → empty; clean → bare branch; dirty → branch*; detached → 7-char SHA.
  • Colour: vcs_colour contract unit test + end-to-end ANSI assertion (cyan \x1b[36m clean / yellow \x1b[33m dirty through render_left).
  • Bundle contract: OH_MY_NIU_SEGMENTS_TOML pins a verbatim mirror of the bundle's prompts/segments.toml; every declared id resolves natively and every shipped preset element resolves through the name→id map. oh_my_niu_git_segment_resolves_under_name_and_id walks the shipped lean preset's "git" element to SegmentId::Vcs (preset integration).

Bundle side

Companion oh-my-niu PR: unixwin/oh-my-niu#11 (docs/CHANGELOG marking the socket live; all shipped presets already carry git, all themes already declare [git_clean]/[git_dirty] — no format change needed, lean documented as the showcase preset).

Validation

  • cargo fmt --check --all: clean.
  • RUSTFLAGS=-D warnings cargo check -p niubash-runtime --all-targets: clean.
  • RUSTFLAGS=-D warnings cargo check -p niubash-runtime --target x86_64-unknown-linux-gnu: clean (unix acceptance line).
  • cargo test -p niubash-runtime --lib: 516 passed, 0 failed (includes the 8 git_prompt tests and 25 prompt_segments tests — 12 new/updated for Vcs).
  • Local cargo clippy -D warnings is noisy from clippy 1.99 crate-wide drift (96 pre-existing hits, CI has no clippy gate); the only hit in touched files is pre-existing untouched code (prompt_segments.rs render_right .map(|s| style_segment(s))).

…erer into the segments engine (closes #331)

The oh-my-niu bundle's prompts/segments.toml declares
[segments.git] id = vcs; the segments engine had no Vcs variant —
a socket with no power. This lands the native segment for 1.4.1:

- SegmentId::Vcs; from_name accepts vcs (the native id) and git
  (the bundle segment name), case/separator-insensitive as before.
- Rendering goes through #292's in-process git2 renderer:
  git_prompt::branch_segment is now pub. branch / branch* / short-SHA
  detached, empty outside a repository. Zero child processes on the
  prompt path (niubash#145 red line; #604 measured PS1-embedded
  $(...) at ~100x native cost). Off-Windows the segment renders
  empty, matching the gitbash style's template fallback there.
- Colour contract from the oh-my-niu themes: [git_clean] cyan,
  [git_dirty] yellow, keyed off the renderer's dirty star, applied
  regardless of preset (detached SHA renders clean-cyan, #292 style).
- Perf: segment render p50 <= 10ms asserted (21-sample median,
  10x headroom); measured warm p50 2.38ms / p90 2.47ms on the dev
  box, consistent with #292's 2.5ms.
- Contract tests pin a verbatim mirror of the bundle's
  prompts/segments.toml: every declared id resolves natively and
  every shipped preset element resolves through the name->id map
  (the lean preset's git lands on SegmentId::Vcs).
@caomengxuan666
caomengxuan666 merged commit 57a5373 into master Oct 14, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the feat/vcs-native-segment branch October 14, 2026 00:02
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.

[feature][1.4.1] SegmentId::Vcs native prompt segment - wire the 2.5ms git2 renderer into the segments engine (oh-my-niu bundle already declares it)

1 participant