* fix(docs): respect workspace.yaml packages_dir setting (fixes #46) * fix(workspace): improve config loading logic (CR feedback) - Expand ~ before resolving relative paths in cmd_registry - Handle LoadWorkspaceConfig errors properly - Update Repo.Path when PackagesDir overrides default - Validate workspace config version - Add unit tests for workspace config loading * docs: add comments and increase test coverage (CR feedback) - Add docstrings to exported functions in pkg/cli - Add unit tests for Semantic Output (pkg/cli/output.go) - Add unit tests for CheckBuilder (pkg/cli/check.go) - Add unit tests for IPC Query/Perform (pkg/framework/core) * fix(test): fix panics and failures in php package tests - Fix panic in TestLookupLinuxKit_Bad by mocking paths - Fix assertion errors in TestGetSSLDir_Bad and TestGetPackageInfo_Bad - Fix formatting in test files * fix(test): correct syntax in services_extended_test.go * fix(ci): point coverage workflow to go.mod instead of go.work * fix(ci): build CLI before running coverage * fix(ci): run go generate for updater package in coverage workflow * fix(github): allow dry-run publish without gh CLI authentication Moves validation check after dry-run check so tests can verify dry-run behavior in CI environments.
89 lines
No EOL
1.7 KiB
Go
89 lines
No EOL
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"bytes"
|
|
"unicode"
|
|
)
|
|
|
|
// GlyphTheme defines which symbols to use.
|
|
type GlyphTheme int
|
|
|
|
const (
|
|
// ThemeUnicode uses standard Unicode symbols.
|
|
ThemeUnicode GlyphTheme = iota
|
|
// ThemeEmoji uses Emoji symbols.
|
|
ThemeEmoji
|
|
// ThemeASCII uses ASCII fallback symbols.
|
|
ThemeASCII
|
|
)
|
|
|
|
var currentTheme = ThemeUnicode
|
|
|
|
// UseUnicode switches the glyph theme to Unicode.
|
|
func UseUnicode() { currentTheme = ThemeUnicode }
|
|
|
|
// UseEmoji switches the glyph theme to Emoji.
|
|
func UseEmoji() { currentTheme = ThemeEmoji }
|
|
|
|
// UseASCII switches the glyph theme to ASCII.
|
|
func UseASCII() { currentTheme = ThemeASCII }
|
|
|
|
func glyphMap() map[string]string {
|
|
switch currentTheme {
|
|
case ThemeEmoji:
|
|
return glyphMapEmoji
|
|
case ThemeASCII:
|
|
return glyphMapASCII
|
|
default:
|
|
return glyphMapUnicode
|
|
}
|
|
}
|
|
|
|
// Glyph converts a shortcode (e.g. ":check:") to its symbol based on the current theme.
|
|
func Glyph(code string) string {
|
|
if sym, ok := glyphMap()[code]; ok {
|
|
return sym
|
|
}
|
|
return code
|
|
}
|
|
|
|
func compileGlyphs(x string) string {
|
|
if x == "" {
|
|
return ""
|
|
}
|
|
input := bytes.NewBufferString(x)
|
|
output := bytes.NewBufferString("")
|
|
|
|
for {
|
|
r, _, err := input.ReadRune()
|
|
if err != nil {
|
|
break
|
|
}
|
|
if r == ':' {
|
|
output.WriteString(replaceGlyph(input))
|
|
} else {
|
|
output.WriteRune(r)
|
|
}
|
|
}
|
|
return output.String()
|
|
}
|
|
|
|
func replaceGlyph(input *bytes.Buffer) string {
|
|
code := bytes.NewBufferString(":")
|
|
for {
|
|
r, _, err := input.ReadRune()
|
|
if err != nil {
|
|
return code.String()
|
|
}
|
|
if r == ':' && code.Len() == 1 {
|
|
return code.String() + replaceGlyph(input)
|
|
}
|
|
code.WriteRune(r)
|
|
if unicode.IsSpace(r) {
|
|
return code.String()
|
|
}
|
|
if r == ':' {
|
|
return Glyph(code.String())
|
|
}
|
|
}
|
|
} |