From 75c834256407434a47d1558c6b4b5acca3ebe10c Mon Sep 17 00:00:00 2001 From: Russ Egan Date: Tue, 7 Jan 2025 20:30:17 -0600 Subject: [PATCH] Adds a new "Dim" theme Makes attribute values and keys a little darker to make the messages pop more. Addresses issue #9 Signed-off-by: Russ Egan --- handler_test.go | 16 +++++++++++++--- theme.go | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/handler_test.go b/handler_test.go index eb09629..f5f6d95 100644 --- a/handler_test.go +++ b/handler_test.go @@ -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 @@ -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, @@ -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:] @@ -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()) + } } } }) diff --git a/theme.go b/theme.go index 8d1290f..377c7e0 100644 --- a/theme.go +++ b/theme.go @@ -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(), + } +}