Skip to content

Commit 470ab6a

Browse files
committed
feat: add render promt function
1 parent 0d4be8b commit 470ab6a

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

styles/color.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package styles
2+
3+
type HexColor string
4+
5+
const (
6+
White HexColor = "#FFFFFF"
7+
Cyan HexColor = "#27D8FF"
8+
Green HexColor = "#B0EE5F"
9+
Gray HexColor = "#808080"
10+
Red HexColor = "#FF5656"
11+
Black HexColor = "#000000"
12+
Yellow HexColor = "#FFBE5E"
13+
)

styles/text.go

+44-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
package styles
22

33
import (
4-
"github.com/charmbracelet/lipgloss"
5-
)
4+
"strings"
65

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"
167
)
178

189
// Text applies a hex color to a given string and returns the styled string
@@ -31,8 +22,48 @@ func Cursor(cursorChar string) string {
3122
cursorStyle := lipgloss.NewStyle().
3223
Bold(true). // Make cursor bold
3324
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
3627

3728
return cursorStyle.Render(cursorChar)
3829
}
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

Comments
 (0)