rename color constants

This commit is contained in:
2026-03-11 21:14:56 +01:00
parent 2157425b24
commit 454e625ef3
11 changed files with 88 additions and 88 deletions

View File

@@ -53,26 +53,26 @@ func (m *Menu) Dispatch(s *Session, key string) {
// Render returns the rendered menu string
func (m *Menu) Render(p *Printer, lang T, username string) string {
headerLine := strings.Repeat("═", W)
l1 := p.PadLine(fmt.Sprintf(" %s%s%s %s@%s%s", YL, m.title, R, GY, username, R), W)
l1 := p.PadLine(fmt.Sprintf(" %s%s%s %s@%s%s", COLOR_YELLOW, m.title, COLOR_RESET, COLOR_GRAY, username, COLOR_RESET), W)
var rows []string
for i := 0; i < len(m.items); i += 2 {
if i+1 < len(m.items) {
left := p.PadLine(fmt.Sprintf(" %s[%s]%s %s", m.items[i].Color, m.items[i].Key, R, m.items[i].Label), W/2)
right := p.PadLine(fmt.Sprintf(" %s[%s]%s %s", m.items[i+1].Color, m.items[i+1].Key, R, m.items[i+1].Label), W/2)
left := p.PadLine(fmt.Sprintf(" %s[%s]%s %s", m.items[i].Color, m.items[i].Key, COLOR_RESET, m.items[i].Label), W/2)
right := p.PadLine(fmt.Sprintf(" %s[%s]%s %s", m.items[i+1].Color, m.items[i+1].Key, COLOR_RESET, m.items[i+1].Label), W/2)
rows = append(rows, left+right)
} else {
rows = append(rows, p.PadLine(fmt.Sprintf(" %s[%s]%s %s", m.items[i].Color, m.items[i].Key, R, m.items[i].Label), W))
rows = append(rows, p.PadLine(fmt.Sprintf(" %s[%s]%s %s", m.items[i].Color, m.items[i].Key, COLOR_RESET, m.items[i].Label), W))
}
}
var sb strings.Builder
sb.WriteString(fmt.Sprintf("\n%s╔%s╗%s\n", WH, headerLine, R))
sb.WriteString(fmt.Sprintf("%s║%s%s║%s\n", WH, l1, WH, R))
sb.WriteString(fmt.Sprintf("%s╠%s╣%s\n", WH, headerLine, R))
sb.WriteString(fmt.Sprintf("\n%s╔%s╗%s\n", COLOR_WHITE, headerLine, COLOR_RESET))
sb.WriteString(fmt.Sprintf("%s║%s%s║%s\n", COLOR_WHITE, l1, COLOR_WHITE, COLOR_RESET))
sb.WriteString(fmt.Sprintf("%s╠%s╣%s\n", COLOR_WHITE, headerLine, COLOR_RESET))
for _, row := range rows {
sb.WriteString(fmt.Sprintf("%s║%s%s║%s\n", WH, row, WH, R))
sb.WriteString(fmt.Sprintf("%s║%s%s║%s\n", COLOR_WHITE, row, COLOR_WHITE, COLOR_RESET))
}
sb.WriteString(fmt.Sprintf("%s╚%s╝%s\n%s", WH, headerLine, R, lang["Choice"]))
sb.WriteString(fmt.Sprintf("%s╚%s╝%s\n%s", COLOR_WHITE, headerLine, COLOR_RESET, lang["Choice"]))
return sb.String()
}

View File

@@ -12,17 +12,17 @@ import (
// ANSI color codes
const (
R = "\033[0m"
B = "\033[1m"
DIM = "\033[2m"
CY = "\033[1;36m"
YL = "\033[1;33m"
GR = "\033[1;32m"
RD = "\033[1;31m"
MG = "\033[1;35m"
WH = "\033[1;37m"
BL = "\033[1;34m"
GY = "\033[0;37m"
COLOR_RESET = "\033[0m"
COLOR_BOLD = "\033[1m"
COLOR_DIM = "\033[2m"
COLOR_CYAN = "\033[1;36m"
COLOR_YELLOW = "\033[1;33m"
COLOR_GREEN = "\033[1;32m"
COLOR_RED = "\033[1;31m"
COLOR_MAGENTA = "\033[1;35m"
COLOR_WHITE = "\033[1;37m"
COLOR_BLUE = "\033[1;34m"
COLOR_GRAY = "\033[0;37m"
)
// W is the default terminal width
@@ -94,7 +94,7 @@ func (p *Printer) ReadLine() (string, error) {
}
func (p *Printer) Pause(lang T) {
p.Send(fmt.Sprintf("\r\n%s [ %s ]%s ", GY, lang["Pause"], R))
p.Send(fmt.Sprintf("\r\n%s [ %s ]%s ", COLOR_GRAY, lang["Pause"], COLOR_RESET))
p.ReadLine()
}
@@ -122,14 +122,14 @@ func (p *Printer) BoxHeader(title string, color string) {
inner := strings.Repeat(" ", padding) + title + strings.Repeat(" ", W-2-titleLen-padding)
p.Send(fmt.Sprintf(
"\n%s%s%s\n%s║%s %s%s%s %s║%s\n%s%s%s\n",
color, line, R,
color, R, B, inner, R, color, R,
color, line, R,
color, line, COLOR_RESET,
color, COLOR_RESET, COLOR_BOLD, inner, COLOR_RESET, color, COLOR_RESET,
color, line, COLOR_RESET,
))
}
func (p *Printer) HR(char string, color string) {
p.Send(fmt.Sprintf("%s%s%s", color, strings.Repeat(char, W), R))
p.Send(fmt.Sprintf("%s%s%s", color, strings.Repeat(char, W), COLOR_RESET))
}
func (p *Printer) FmtDate(s string) string {

View File

@@ -73,8 +73,8 @@ func (b *BBS) handleClient(conn net.Conn) {
// Telnet negotiation (IAC WILL ECHO, IAC WILL SGA, IAC WONT LINEMODE)
printer.Send("\xff\xfb\x01\xff\xfb\x03\xff\xfe\x22")
printer.Send(CY + b.config.Banner + R)
printer.Send(fmt.Sprintf("\n%s%s%s ", WH, lang["AskName"], R))
printer.Send(COLOR_CYAN + b.config.Banner + COLOR_RESET)
printer.Send(fmt.Sprintf("\n%s%s%s ", COLOR_WHITE, lang["AskName"], COLOR_RESET))
username, err := printer.ReadLine()
if err != nil {
@@ -98,7 +98,7 @@ func (b *BBS) handleClient(conn net.Conn) {
b.state.Mu.Unlock()
}()
printer.Send(fmt.Sprintf("\r\n%s%s%s\r\n", GR, fmt.Sprintf(lang["Greeting"], WH, username, GR), R))
printer.Send(fmt.Sprintf("\r\n%s%s%s\r\n", COLOR_GREEN, fmt.Sprintf(lang["Greeting"], COLOR_WHITE, username, COLOR_GREEN), COLOR_RESET))
session := &Session{
State: b.state,
@@ -118,6 +118,6 @@ func (b *BBS) handleClient(conn net.Conn) {
}
if session.Quit {
printer.Send(fmt.Sprintf("\r\n%s%s%s\r\n\r\n", RD, fmt.Sprintf(lang["Goodbye"], username), R))
printer.Send(fmt.Sprintf("\r\n%s%s%s\r\n\r\n", COLOR_RED, fmt.Sprintf(lang["Goodbye"], username), COLOR_RESET))
}
}