Skip to content

Commit 5509c04

Browse files
committed
chore: remove unused test exports and dead shell-highlight/theme/upstream helpers
1 parent 99721c7 commit 5509c04

9 files changed

Lines changed: 9 additions & 291 deletions

‎internal/tui/diff_viewer_test.go‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -332,23 +332,6 @@ func TestDiffViewerFallsBackForOversizedSourceLine(t *testing.T) {
332332
}
333333
}
334334

335-
func TestDiffViewerSyntaxHighlighterKeepsSpans(t *testing.T) {
336-
requireDiffViewerTrueColor(t)
337-
styled, ok := highlightCodeForPathWithSpans(
338-
[]string{"func greet(name string) string { return \"new\" }"},
339-
"example.go",
340-
200,
341-
zeroTheme.addLine.GetBackground(),
342-
[]highlightSpan{{line: 0, start: 39, end: 44, background: zeroTheme.addLineWord.GetBackground()}},
343-
)
344-
if !ok || len(styled) != 1 {
345-
t.Fatalf("highlightCodeForPathWithSpans = %#v, %v", styled, ok)
346-
}
347-
if !strings.Contains(styled[0], "46;101;77") {
348-
t.Fatalf("highlighted span lost its word-diff background: %q", styled[0])
349-
}
350-
}
351-
352335
func TestDiffViewerHighlightsEachFileWithItsOwnPath(t *testing.T) {
353336
requireDiffViewerTrueColor(t)
354337
rawLines := []string{

‎internal/tui/syntax_highlight.go‎

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -206,111 +206,6 @@ func highlightCodeForPath(code []string, path string, measure int, bg color.Colo
206206
return highlightCodeWithLexer(cachedLexerForPath(path), code, measure, bg)
207207
}
208208

209-
// highlightShellCommand styles a one-line command for a tool-card heading.
210-
// Command output is deliberately left untouched: it may be structured data,
211-
// prose, or terminal control text rather than shell source.
212-
func highlightShellCommand(command string) (string, bool) {
213-
if command == "" {
214-
return "", false
215-
}
216-
lexer := cachedLexer("bash")
217-
if lexer == nil {
218-
return "", false
219-
}
220-
iterator, err := lexer.Tokenise(nil, command)
221-
if err != nil {
222-
return "", false
223-
}
224-
var builder strings.Builder
225-
expectingCommand := true
226-
for _, token := range iterator.Tokens() {
227-
if token.Type == chroma.Text || token.Type == chroma.TextWhitespace {
228-
builder.WriteString(highlightShellText(token.Value, &expectingCommand))
229-
continue
230-
}
231-
builder.WriteString(tokenStyle(token.Type).Render(token.Value))
232-
if token.Type.InCategory(chroma.Operator) || (token.Type.InCategory(chroma.Punctuation) && strings.ContainsAny(token.Value, ";|")) {
233-
expectingCommand = true
234-
}
235-
}
236-
return builder.String(), true
237-
}
238-
239-
func highlightShellText(text string, expectingCommand *bool) string {
240-
var builder strings.Builder
241-
for start := 0; start < len(text); {
242-
end := start
243-
space := text[start] == ' ' || text[start] == '\t'
244-
for end < len(text) {
245-
isSpace := text[end] == ' ' || text[end] == '\t'
246-
if isSpace != space {
247-
break
248-
}
249-
end++
250-
}
251-
part := text[start:end]
252-
if space {
253-
builder.WriteString(part)
254-
start = end
255-
continue
256-
}
257-
258-
clean := strings.Trim(part, "\"'")
259-
style := tokenStyle(chroma.Text)
260-
switch {
261-
case isShellControlOperator(clean):
262-
style = tokenStyle(chroma.Operator)
263-
*expectingCommand = true
264-
case *expectingCommand:
265-
style = tokenStyle(chroma.NameFunction)
266-
*expectingCommand = isShellCommandWrapper(clean)
267-
case strings.HasPrefix(clean, "-"):
268-
style = tokenStyle(chroma.NameAttribute)
269-
case isShellNumber(clean):
270-
style = tokenStyle(chroma.LiteralNumber)
271-
case looksLikeShellPath(clean):
272-
style = tokenStyle(chroma.LiteralString)
273-
}
274-
builder.WriteString(style.Render(part))
275-
start = end
276-
}
277-
return builder.String()
278-
}
279-
280-
func isShellControlOperator(value string) bool {
281-
switch value {
282-
case "&&", "||", "|", ";":
283-
return true
284-
default:
285-
return false
286-
}
287-
}
288-
289-
func isShellCommandWrapper(value string) bool {
290-
switch value {
291-
case "sudo", "env", "command", "time", "xargs":
292-
return true
293-
default:
294-
return false
295-
}
296-
}
297-
298-
func isShellNumber(value string) bool {
299-
if value == "" {
300-
return false
301-
}
302-
for _, r := range value {
303-
if r < '0' || r > '9' {
304-
return false
305-
}
306-
}
307-
return true
308-
}
309-
310-
func looksLikeShellPath(value string) bool {
311-
return strings.HasPrefix(value, "./") || strings.HasPrefix(value, "../") || strings.HasPrefix(value, "/") || strings.HasPrefix(value, "~/") || strings.Contains(value, "/")
312-
}
313-
314209
// highlightSpan overlays a background on a rune range in one source line while
315210
// retaining the lexer-selected foreground. Diff rendering uses it to keep the
316211
// precise changed word visible inside a syntax-highlighted add/delete row.
@@ -320,10 +215,6 @@ type highlightSpan struct {
320215
background color.Color
321216
}
322217

323-
func highlightCodeForPathWithSpans(code []string, path string, measure int, bg color.Color, spans []highlightSpan) ([]string, bool) {
324-
return highlightCodeWithLexerAndSpans(cachedLexerForPath(path), code, measure, bg, spans)
325-
}
326-
327218
// highlightCodeForPathWithLineBackgrounds applies syntax highlighting to a
328219
// single source unit while preserving a distinct background for every source
329220
// line. The diff viewer uses one lexer pass per hunk so multiline syntax keeps

‎internal/tui/syntax_highlight_test.go‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func TestDiffSyntaxKeepsThemeColorOverDiffSurface(t *testing.T) {
125125
}
126126
}
127127

128-
func TestInlineCodeAndShellCommandsUseTheActiveSyntaxPalette(t *testing.T) {
128+
func TestInlineCodeUsesTheActiveSyntaxPalette(t *testing.T) {
129129
previous := zeroTheme
130130
defer func() { zeroTheme = previous }()
131131
_, zeroTheme = themeForMode("nord", true)
@@ -134,26 +134,6 @@ func TestInlineCodeAndShellCommandsUseTheActiveSyntaxPalette(t *testing.T) {
134134
if want := inlineCodeStyle().Render("gofmt"); !strings.Contains(inline, want) {
135135
t.Fatalf("inline code should use the active palette:\n%s", inline)
136136
}
137-
138-
command, ok := highlightShellCommand("gofmt -w calculator.go && go run . divide 9 2")
139-
if !ok {
140-
t.Fatal("bash command should have a cached syntax lexer")
141-
}
142-
if plain := ansiPattern.ReplaceAllString(command, ""); plain != "gofmt -w calculator.go && go run . divide 9 2" {
143-
t.Fatalf("command highlight changed visible command to %q", plain)
144-
}
145-
if !strings.Contains(command, "\x1b[") {
146-
t.Fatalf("shell command should be syntax styled, got %q", command)
147-
}
148-
for token, style := range map[string]lipgloss.Style{
149-
"gofmt": tokenStyle(chroma.NameFunction),
150-
"-w": tokenStyle(chroma.NameAttribute),
151-
"9": tokenStyle(chroma.LiteralNumber),
152-
} {
153-
if want := style.Render(token); !strings.Contains(command, want) {
154-
t.Fatalf("shell token %q should use its semantic style:\n%s", token, command)
155-
}
156-
}
157137
}
158138

159139
func styleForegroundHex(t *testing.T, style lipgloss.Style) string {

‎internal/tui/theme.go‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,6 @@ func colorChannel(value float64) int {
345345
return int(value*255 + 0.5)
346346
}
347347

348-
// buildSystemTheme is the dark-terminal default for package-level render helpers
349-
// and tests. The running TUI resolves the matching contrast direction through
350-
// buildSystemThemeForTerminal.
351-
func buildSystemTheme() tuiTheme {
352-
return buildSystemThemeForTerminal(true)
353-
}
354-
355348
// buildSystemThemeForTerminal preserves the terminal canvas and its foreground
356349
// color. It uses ANSI role colors for semantic cues and confines fixed local
357350
// surfaces to selected and diff rows, so those states remain visible even in

‎internal/tui/word_diff_test.go‎

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package tui
22

33
import (
4-
"fmt"
54
"strings"
65
"testing"
76

8-
"charm.land/lipgloss/v2"
97
"github.com/alecthomas/chroma/v2"
108
)
119

@@ -102,64 +100,3 @@ func TestMixedDiffSyntaxHighlightsCodeOnBothSides(t *testing.T) {
102100
t.Fatalf("mixed diff context code must retain syntax colors, got:\n%s", joined)
103101
}
104102
}
105-
106-
func TestSystemThemeKeepsSyntaxOnAnAddedLineBand(t *testing.T) {
107-
previous := zeroTheme
108-
defer func() { zeroTheme = previous }()
109-
zeroTheme = buildSystemTheme()
110-
111-
diff := strings.Join([]string{
112-
"--- /dev/null",
113-
"+++ b/main.go",
114-
"@@ -0,0 +1,2 @@",
115-
"+package main",
116-
"+func main() {}",
117-
}, "\n")
118-
body := diffCardBody(diff, 80, cardRenderOptions{bodyCap: 20})
119-
joined := strings.Join(body.lines, "\n")
120-
if !styleHasLocalBackground(zeroTheme.addLine) {
121-
t.Fatal("system-theme added code must use a local line background")
122-
}
123-
if want := tokenStyle(chroma.Keyword).Background(zeroTheme.addLine.GetBackground()).Render("package"); !strings.Contains(joined, want) {
124-
t.Fatalf("system-theme added code must retain syntax highlighting, got:\n%s", joined)
125-
}
126-
if !styleHasLocalBackground(zeroTheme.onSel(zeroTheme.ink)) {
127-
t.Fatal("system-theme selected rows must use a local selection background")
128-
}
129-
}
130-
131-
func TestSystemThemeUsesMutedLocalSurfaceColors(t *testing.T) {
132-
theme := buildSystemTheme()
133-
for _, test := range []struct {
134-
name string
135-
style lipgloss.Style
136-
want string
137-
}{
138-
{"added diff", theme.addLine, "#212922"},
139-
{"deleted diff", theme.delLine, "#3c170f"},
140-
{"selection", theme.onSel(theme.ink), "#2b2f2d"},
141-
} {
142-
if got := styleBackgroundHex(t, test.style); got != test.want {
143-
t.Errorf("%s background = %s, want %s", test.name, got, test.want)
144-
}
145-
}
146-
}
147-
148-
func styleHasLocalBackground(style lipgloss.Style) bool {
149-
background := style.GetBackground()
150-
if background == nil {
151-
return false
152-
}
153-
_, noColor := background.(lipgloss.NoColor)
154-
return !noColor
155-
}
156-
157-
func styleBackgroundHex(t *testing.T, style lipgloss.Style) string {
158-
t.Helper()
159-
background := style.GetBackground()
160-
if background == nil {
161-
t.Fatal("style has no background")
162-
}
163-
r, g, b, _ := background.RGBA()
164-
return fmt.Sprintf("#%02x%02x%02x", r>>8, g>>8, b>>8)
165-
}

‎internal/update/replace_windows.go‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,6 @@ func openRecoveryCopy(path string) (*os.File, error) {
255255

256256
var renameRecoveryFileByHandle = renameOpenFile
257257

258-
// clearOldBinaryPreserved models the operator accepting the installed binary
259-
// by deleting the recovery marker. The recovery copy itself remains preserved.
260-
func clearOldBinaryPreserved(oldPath string) {
261-
_ = os.Remove(oldPath + oldBinaryPreservedSuffix)
262-
}
263-
264258
// oldBinaryPreserved reports whether a failed restore marked oldPath as the last
265259
// known-good binary.
266260
//

‎internal/update/stage_promote_windows_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func TestPromoteRefusesWhileRecoveryCopyIsMarked(t *testing.T) {
255255

256256
// Clearing the marker is the operator accepting the installed binary; the
257257
// next promotion proceeds normally without destroying the recovery copy.
258-
clearOldBinaryPreserved(oldPath)
258+
_ = os.Remove(oldPath + oldBinaryPreservedSuffix)
259259
stubRandomStagingSuffix(t, "deadbeef")
260260
if err := installBinary(sourcePath, targetPath); err != nil {
261261
t.Fatalf("installBinary after the operator cleared the marker: %v", err)
@@ -333,7 +333,7 @@ func TestPreflightRefusesWhenRecoveryMarkerIsDeletedButTrustedRecordRemains(t *t
333333
t.Fatalf("trusted records = %+v, want one unresolved entry", queue.Records)
334334
}
335335

336-
clearOldBinaryPreserved(recoveryPath)
336+
_ = os.Remove(recoveryPath + oldBinaryPreservedSuffix)
337337
if oldBinaryPreserved(recoveryPath) {
338338
t.Fatal("marker deletion did not take effect")
339339
}
@@ -427,7 +427,7 @@ func TestPreflightRefusesWhenRecordWriteFailsAndRecoveryMarkerIsDeleted(t *testi
427427
}
428428
}
429429

430-
clearOldBinaryPreserved(asidePath)
430+
_ = os.Remove(asidePath + oldBinaryPreservedSuffix)
431431
if oldBinaryPreserved(asidePath) {
432432
t.Fatal("marker deletion did not take effect")
433433
}

‎internal/zerogit/zerogit.go‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,39 +1100,6 @@ func UpstreamRef(ctx context.Context, cwd, branch string, runGit Runner) string
11001100
return strings.TrimSpace(out)
11011101
}
11021102

1103-
// HasUpstream reports whether branch has a published upstream tracking the same
1104-
// branch name on a remote (the relationship `git push -u <remote> <branch>`
1105-
// records). ensureFeatureBranch consults this when it is called again with a
1106-
// non-default current branch: a generated branch that just lost a
1107-
// force-with-lease race against a concurrent creator is left checked out
1108-
// locally without that relationship, so a retry must not treat it the same as
1109-
// an ordinary, already-published feature branch and drop the nonexistence
1110-
// lease.
1111-
//
1112-
// An inherited upstream to a different branch (branch.autoSetupMerge=inherit
1113-
// copies origin/main onto a new user/slug) is not publication state and reports
1114-
// false. Any failure to resolve the upstream (including "no upstream
1115-
// configured") also reports false so the caller keeps requiring the lease.
1116-
func HasUpstream(ctx context.Context, cwd, branch string, runGit Runner) (bool, error) {
1117-
branch = strings.TrimSpace(branch)
1118-
if branch == "" {
1119-
return false, nil
1120-
}
1121-
ref := UpstreamRef(ctx, cwd, branch, runGit)
1122-
if ref == "" {
1123-
return false, nil
1124-
}
1125-
// rev-parse --abbrev-ref prints "<remote>/<branch>". Both remote names
1126-
// (e.g. team/upstream) and branch names (e.g. user/slug) may contain
1127-
// slashes, so verify that the upstream ref ends with "/" + branch and
1128-
// has a non-empty remote prefix.
1129-
suffix := "/" + branch
1130-
if strings.HasSuffix(ref, suffix) && len(ref) > len(suffix) {
1131-
return true, nil
1132-
}
1133-
return false, nil
1134-
}
1135-
11361103
// UpstreamRemote returns the configured upstream remote name for branch (e.g. "origin"),
11371104
// or "" if no upstream is configured. This alone is not proof of publication:
11381105
// branch.autoSetupMerge=inherit copies branch.<name>.remote from the source

0 commit comments

Comments
 (0)