Skip to content

Commit

Permalink
Adds a new "Dim" theme
Browse files Browse the repository at this point in the history
Makes attribute values and keys a little darker to make the messages pop more.  Addresses issue phsym#9

Signed-off-by: Russ Egan <[email protected]>
  • Loading branch information
Russ Egan authored and ansel1 committed Jan 8, 2025
1 parent d4a3eec commit 75c8342
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
16 changes: 13 additions & 3 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func TestThemes(t *testing.T) {
for _, theme := range []Theme{
NewDefaultTheme(),
NewBrightTheme(),
NewDimTheme(),
} {
t.Run(theme.Name(), func(t *testing.T) {
level := slog.LevelInfo
Expand All @@ -292,6 +293,7 @@ func TestThemes(t *testing.T) {
timeFormat := time.Kitchen
index := -1
toIndex := -1
var lastField []byte
h := NewHandler(&buf, &HandlerOptions{
AddSource: true,
TimeFormat: timeFormat,
Expand All @@ -309,6 +311,7 @@ func TestThemes(t *testing.T) {
bufBytes = bufBytes[toIndex:]
index = bytes.IndexByte(bufBytes, '\x1b')
AssertNotEqual(t, -1, index)
lastField = bufBytes[:index]
toIndex = index + len(ResetMod)
AssertEqual(t, ResetMod, ANSIMod(bufBytes[index:toIndex]))
bufBytes = bufBytes[toIndex:]
Expand Down Expand Up @@ -352,9 +355,16 @@ func TestThemes(t *testing.T) {
checkANSIMod(t, "AttrKey", theme.AttrKey())
}

// AttrValue
if theme.AttrValue() != "" {
checkANSIMod(t, "AttrValue", theme.AttrValue())
if string(lastField) == "error=" {
// AttrValueError
if theme.AttrValueError() != "" {
checkANSIMod(t, "AttrValueError", theme.AttrValueError())
}
} else {
// AttrValue
if theme.AttrValue() != "" {
checkANSIMod(t, "AttrValue", theme.AttrValue())
}
}
}
})
Expand Down
17 changes: 17 additions & 0 deletions theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,20 @@ func NewBrightTheme() Theme {
levelDebug: ToANSICode(),
}
}

func NewDimTheme() Theme {
return ThemeDef{
name: "Dim",
timestamp: ToANSICode(BrightBlack),
source: ToANSICode(Bold, BrightBlack),
message: ToANSICode(Bold),
messageDebug: ToANSICode(),
attrKey: ToANSICode(Blue),
attrValue: ToANSICode(Gray),
attrValueError: ToANSICode(Bold, Red),
levelError: ToANSICode(Red),
levelWarn: ToANSICode(Yellow),
levelInfo: ToANSICode(Green),
levelDebug: ToANSICode(),
}
}

0 comments on commit 75c8342

Please sign in to comment.