-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.go
44 lines (39 loc) · 957 Bytes
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"strings"
)
func deepCopyContent(content [][]rune) [][]rune {
newContent := make([][]rune, len(content))
for i, line := range content {
newContent[i] = make([]rune, len(line))
copy(newContent[i], line)
}
return newContent
}
func highlightSearch(text, searchTerm string) string {
if searchTerm == "" {
return text
}
highlightStyle := "\033[43m%s\033[0m" // Yellow background
parts := strings.Split(text, searchTerm)
for i := 0; i < len(parts)-1; i++ {
parts[i] += fmt.Sprintf(highlightStyle, searchTerm)
}
return strings.Join(parts, "")
}
func expandTabs(s string, tabSize int) string {
var result strings.Builder
column := 0
for _, r := range s {
if r == '\t' {
spaces := tabSize - (column % tabSize)
result.WriteString(strings.Repeat(" ", spaces))
column += spaces
} else {
result.WriteRune(r)
column++
}
}
return result.String()
}