MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / stripLineNumbers

Function stripLineNumbers

internal/tui/log.go:502–555  ·  view source on GitHub ↗

stripLineNumbers removes line number prefixes from Read tool output. The format is: optional spaces + line number + → or tab + content

(code string)

Source from the content-addressed store, hash-verified

500// stripLineNumbers removes line number prefixes from Read tool output.
501// The format is: optional spaces + line number + → or tab + content
502func stripLineNumbers(code string) string {
503 lines := strings.Split(code, "\n")
504 var result []string
505
506 for _, line := range lines {
507 // Look for patterns like " 1→", " 10→", " 1\t", etc.
508 stripped := line
509
510 // Find the arrow or tab after the line number
511 arrowIdx := strings.Index(line, "→")
512 tabIdx := strings.Index(line, "\t")
513
514 idx := -1
515 if arrowIdx != -1 && tabIdx != -1 {
516 if arrowIdx < tabIdx {
517 idx = arrowIdx
518 } else {
519 idx = tabIdx
520 }
521 } else if arrowIdx != -1 {
522 idx = arrowIdx
523 } else if tabIdx != -1 {
524 idx = tabIdx
525 }
526
527 if idx > 0 && idx < 10 { // Line number prefix is typically short
528 // Check if everything before is spaces and digits
529 prefix := line[:idx]
530 isLineNum := true
531 hasDigit := false
532 for _, ch := range prefix {
533 if ch >= '0' && ch <= '9' {
534 hasDigit = true
535 } else if ch != ' ' {
536 isLineNum = false
537 break
538 }
539 }
540 if isLineNum && hasDigit {
541 // Skip the arrow/tab character (→ is multi-byte)
542 if line[idx] == '\t' {
543 stripped = line[idx+1:]
544 } else {
545 // → is 3 bytes in UTF-8
546 stripped = line[idx+3:]
547 }
548 }
549 }
550
551 result = append(result, stripped)
552 }
553
554 return strings.Join(result, "\n")
555}
556
557// renderStoryDone renders a story done marker.
558func (l *LogViewer) renderStoryDone(entry LogEntry) []string {

Callers 2

TestStripLineNumbersFunction · 0.85
highlightCodeMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestStripLineNumbersFunction · 0.68