Merge pull request '[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/cli/RFC.md fully. Find features des...' (#87) from agent/read---spec-code-core-go-cli-rfc-md-full into dev
All checks were successful
Security Scan / security (push) Successful in 18s
All checks were successful
Security Scan / security (push) Successful in 18s
This commit is contained in:
commit
3ce53ed394
5 changed files with 61 additions and 13 deletions
|
|
@ -18,8 +18,9 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
colorEnabled = true
|
||||
colorEnabledMu sync.RWMutex
|
||||
colorEnabled = true
|
||||
colorEnabledMu sync.RWMutex
|
||||
asciiDisabledColors bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -48,6 +49,18 @@ func ColorEnabled() bool {
|
|||
func SetColorEnabled(enabled bool) {
|
||||
colorEnabledMu.Lock()
|
||||
colorEnabled = enabled
|
||||
if enabled {
|
||||
asciiDisabledColors = false
|
||||
}
|
||||
colorEnabledMu.Unlock()
|
||||
}
|
||||
|
||||
func restoreColorIfASCII() {
|
||||
colorEnabledMu.Lock()
|
||||
if asciiDisabledColors {
|
||||
colorEnabled = true
|
||||
asciiDisabledColors = false
|
||||
}
|
||||
colorEnabledMu.Unlock()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,6 +86,31 @@ func TestUseASCII_Good(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestUseUnicodeAndEmojiRestoreColorsAfterASCII(t *testing.T) {
|
||||
restoreThemeAndColors(t)
|
||||
|
||||
SetColorEnabled(true)
|
||||
UseASCII()
|
||||
if ColorEnabled() {
|
||||
t.Fatal("UseASCII should disable colors")
|
||||
}
|
||||
|
||||
UseUnicode()
|
||||
if !ColorEnabled() {
|
||||
t.Fatal("UseUnicode should restore colors after ASCII mode")
|
||||
}
|
||||
|
||||
UseASCII()
|
||||
if ColorEnabled() {
|
||||
t.Fatal("UseASCII should disable colors again")
|
||||
}
|
||||
|
||||
UseEmoji()
|
||||
if !ColorEnabled() {
|
||||
t.Fatal("UseEmoji should restore colors after ASCII mode")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRender_NilStyle_Good(t *testing.T) {
|
||||
var s *AnsiStyle
|
||||
got := s.Render("test")
|
||||
|
|
|
|||
|
|
@ -20,15 +20,24 @@ const (
|
|||
var currentTheme = ThemeUnicode
|
||||
|
||||
// UseUnicode switches the glyph theme to Unicode.
|
||||
func UseUnicode() { currentTheme = ThemeUnicode }
|
||||
func UseUnicode() {
|
||||
currentTheme = ThemeUnicode
|
||||
restoreColorIfASCII()
|
||||
}
|
||||
|
||||
// UseEmoji switches the glyph theme to Emoji.
|
||||
func UseEmoji() { currentTheme = ThemeEmoji }
|
||||
func UseEmoji() {
|
||||
currentTheme = ThemeEmoji
|
||||
restoreColorIfASCII()
|
||||
}
|
||||
|
||||
// UseASCII switches the glyph theme to ASCII and disables colors.
|
||||
func UseASCII() {
|
||||
currentTheme = ThemeASCII
|
||||
SetColorEnabled(false)
|
||||
colorEnabledMu.Lock()
|
||||
asciiDisabledColors = true
|
||||
colorEnabledMu.Unlock()
|
||||
}
|
||||
|
||||
func glyphMap() map[string]string {
|
||||
|
|
|
|||
|
|
@ -291,6 +291,14 @@ func TestChooseMulti_Good_EmptyWithoutDefaultReturnsNone(t *testing.T) {
|
|||
assert.Empty(t, vals)
|
||||
}
|
||||
|
||||
func TestChooseMulti_Good_EmptyIgnoresDefaultIndex(t *testing.T) {
|
||||
SetStdin(strings.NewReader("\n"))
|
||||
defer SetStdin(nil)
|
||||
|
||||
vals := ChooseMulti("Pick", []string{"a", "b", "c"}, WithDefaultIndex[string](1))
|
||||
assert.Empty(t, vals)
|
||||
}
|
||||
|
||||
func TestChoose_Good_Filter(t *testing.T) {
|
||||
SetStdin(strings.NewReader("ap\n2\n"))
|
||||
defer SetStdin(nil)
|
||||
|
|
@ -368,12 +376,12 @@ func TestChooseMulti_Good_CommasAndRanges(t *testing.T) {
|
|||
assert.Equal(t, []string{"a", "b", "d"}, vals)
|
||||
}
|
||||
|
||||
func TestChooseMulti_Good_DefaultIndex(t *testing.T) {
|
||||
func TestChooseMulti_Good_DefaultIndexIgnored(t *testing.T) {
|
||||
SetStdin(strings.NewReader("\n"))
|
||||
defer SetStdin(nil)
|
||||
|
||||
vals := ChooseMulti("Pick", []string{"a", "b", "c"}, WithDefaultIndex[string](1))
|
||||
assert.Equal(t, []string{"b"}, vals)
|
||||
assert.Empty(t, vals)
|
||||
}
|
||||
|
||||
func TestSetStdin_Good_ResetNil(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -479,13 +479,6 @@ func ChooseMulti[T any](prompt string, items []T, opts ...ChooseOption[T]) []T {
|
|||
promptHint("Filter cleared.")
|
||||
continue
|
||||
}
|
||||
if idx, ok := defaultVisibleIndex(visible, cfg.defaultN); ok {
|
||||
return []T{items[idx]}
|
||||
}
|
||||
if cfg.defaultN >= 0 {
|
||||
promptHint("Default selection is not available in the current list. Narrow the list or choose another number.")
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue