1
1
package styles
2
2
3
3
import (
4
- "github.com/charmbracelet/lipgloss"
5
- )
4
+ "strings"
6
5
7
- type HexColor string
8
-
9
- const (
10
- White HexColor = "#FFFFFF"
11
- Cyan HexColor = "#27D8FF"
12
- Green HexColor = "#B0EE5F"
13
- Gray HexColor = "#808080"
14
- Red HexColor = "#FF5656"
15
- Black HexColor = "#000000"
6
+ "github.com/charmbracelet/lipgloss"
16
7
)
17
8
18
9
// Text applies a hex color to a given string and returns the styled string
@@ -31,8 +22,48 @@ func Cursor(cursorChar string) string {
31
22
cursorStyle := lipgloss .NewStyle ().
32
23
Bold (true ). // Make cursor bold
33
24
Reverse (true ). // Reverse the foreground and background colors
34
- Background (lipgloss .Color (string (Black ))). // White background
35
- Foreground (lipgloss .Color (string (White ))) // Black foreground
25
+ Background (lipgloss .Color (string (Black ))). // Black background
26
+ Foreground (lipgloss .Color (string (White ))) // White foreground
36
27
37
28
return cursorStyle .Render (cursorChar )
38
29
}
30
+
31
+ type PromptStatus string
32
+
33
+ const (
34
+ Empty PromptStatus = "empty"
35
+ Completed PromptStatus = "completed"
36
+ Question PromptStatus = "question"
37
+ Information PromptStatus = "information"
38
+ )
39
+
40
+ var (
41
+ QuestionMark string = Text ("? " , Cyan )
42
+ CorrectMark string = Text ("✓ " , Green )
43
+ InformationMark string = Text ("i " , Cyan )
44
+ )
45
+
46
+ // RenderPrompt highlights phrases in the text if they match any phrase in the highlights list
47
+ func RenderPrompt (text string , highlights []string , status PromptStatus ) string {
48
+ prompt := ""
49
+ switch status {
50
+ case Question :
51
+ prompt += QuestionMark
52
+ case Completed :
53
+ prompt += CorrectMark
54
+ case Information :
55
+ prompt += InformationMark
56
+ }
57
+
58
+ // Iterate over each highlight phrase and replace it in the text
59
+ for _ , highlight := range highlights {
60
+ if strings .Contains (text , highlight ) {
61
+ // Apply Cyan color to the matching highlight
62
+ coloredHighlight := BoldText (highlight , Cyan )
63
+ text = strings .ReplaceAll (text , highlight , coloredHighlight )
64
+ }
65
+ }
66
+
67
+ // Return the prompt with the highlighted text
68
+ return prompt + text
69
+ }
0 commit comments