Skip to content

Commit b1e1b07

Browse files
committed
Add colored text for user and Otto messages in chat and config options for colors
1 parent 2e45581 commit b1e1b07

File tree

7 files changed

+73
-7
lines changed

7 files changed

+73
-7
lines changed

cmd/chat.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ No code context is passed in this mode. Emulates web chat.`,
4747

4848
client := openai.NewClient(conf.APIKey)
4949

50-
fmt.Println("Otto: Hello! I am Otto. Use Ctrl+C to exit at any time.")
50+
utils.PrintColoredText("Otto: ", "#008080")
51+
fmt.Println("Hello! I am Otto. Use Ctrl+C to exit at any time.")
5152

5253
for {
53-
question, err := utils.Input("You: ")
54+
question, err := utils.InputWithColor("You: ", "#007bff")
5455
if err != nil {
5556
log.Error(err)
5657
os.Exit(1)
5758
}
5859

59-
fmt.Print("Otto: ")
60+
utils.PrintColoredText("Otto: ", "#008080")
6061

6162
log.Debugf("Adding question '%s' to context...", question)
6263

cmd/config.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ GitHub Token Generation: https://github.com/settings/tokens
3939
}
4040

4141
// if none of the config options are provided, print a warning
42-
if apiKey == "" && model == "" && ghToken == "" {
42+
if apiKey == "" && model == "" && ghToken == "" && userColor == "" && ottoColor == "" {
4343
log.Warn("No configuration options provided")
4444
os.Exit(0)
4545
}
@@ -67,6 +67,18 @@ GitHub Token Generation: https://github.com/settings/tokens
6767
c.GHToken = ghToken
6868
}
6969

70+
// if the userColor is provided, set it
71+
if userColor != "" {
72+
fmt.Println("Setting user color...")
73+
c.UserColor = userColor
74+
}
75+
76+
// if the ottoColor is provided, set it
77+
if ottoColor != "" {
78+
fmt.Println("Setting Otto color...")
79+
c.OttoColor = ottoColor
80+
}
81+
7082
// save the config
7183
err = c.Save()
7284
if err != nil {
@@ -87,4 +99,8 @@ func init() {
8799
configCmd.Flags().StringVarP(&model, "model", "m", "", "Model to use for documentation")
88100
// set gh token
89101
configCmd.Flags().StringVarP(&ghToken, "ghtoken", "t", "", "GitHub token to use for documentation")
90-
}
102+
// set user color
103+
configCmd.Flags().StringVarP(&userColor, "userColor", "u", "", "User color for configuration")
104+
// set otto color
105+
configCmd.Flags().StringVarP(&ottoColor, "ottoColor", "o", "", "Otto color for configuration")
106+
}

cmd/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
2+
Copyright © 2023 Chandler <chandler@chand1012.dev>
33
*/
44
package cmd
55

cmd/vars.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ var model string
3434
var apiKey string
3535
var ghToken string
3636
var remote string
37+
var userColor string
38+
var ottoColor string
3739

3840
var issuePRNumber int
3941
var useComments bool

pkg/config/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type Config struct {
1313
Model string `json:"model"`
1414
GHToken string `json:"gh_token"`
1515
Signature string `json:"signature"`
16+
UserColor string `json:"user_color"`
17+
OttoColor string `json:"otto_color"`
1618
}
1719

1820
// also returns the path to the config file
@@ -47,6 +49,8 @@ func createIfNotExists() (string, error) {
4749
Model: "gpt-3.5-turbo",
4850
GHToken: "",
4951
Signature: "Created by [OttoDocs 🦦](https://ottodocs.chand1012.dev/)",
52+
UserColor: "#87CEEB",
53+
OttoColor: "#1BFFE4",
5054
}
5155
err = json.NewEncoder(file).Encode(blankConfig)
5256
if err != nil {
@@ -113,4 +117,4 @@ func Save(c *Config) error {
113117
}
114118

115119
return json.NewEncoder(file).Encode(c)
116-
}
120+
}

pkg/utils/color_text.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package utils
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/charmbracelet/lipgloss"
7+
)
8+
9+
// PrintColoredText prints the given text in the specified CSS color code using fmt.Print.
10+
func PrintColoredText(text, cssColorCode string) {
11+
// Create a new Lipgloss style with a foreground color
12+
style := lipgloss.NewStyle().Foreground(lipgloss.Color(cssColorCode))
13+
14+
// Style the input text
15+
styledText := style.Render(text)
16+
17+
// Print the styled text to the terminal without a newline
18+
fmt.Print(styledText)
19+
}
20+
21+
// PrintColoredTextLn prints the given text in the specified CSS color code using fmt.Println.
22+
func PrintColoredTextLn(text, cssColorCode string) {
23+
// Create a new Lipgloss style with a foreground color
24+
style := lipgloss.NewStyle().Foreground(lipgloss.Color(cssColorCode))
25+
26+
// Style the input text
27+
styledText := style.Render(text)
28+
29+
// Print the styled text to the terminal with a newline
30+
fmt.Println(styledText)
31+
}

pkg/utils/input.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,15 @@ func Input(prompt string) (string, error) {
1818

1919
return strings.TrimSpace(input), nil
2020
}
21+
22+
func InputWithColor(prompt, cssColorCode string) (string, error) {
23+
PrintColoredText(prompt, cssColorCode)
24+
25+
reader := bufio.NewReader(os.Stdin)
26+
input, err := reader.ReadString('\n')
27+
if err != nil {
28+
return "", err
29+
}
30+
31+
return strings.TrimSpace(input), nil
32+
}

0 commit comments

Comments
 (0)