charmbracelet / charmbracelet/log

bug: strange whitespace in output with styles applied

Open
#187 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
3.4k
Forks
103
PR merge metrics
No merged PRs in 30d

Description

### Description

The following style setup produces weird empty long whitespace lines (which mangle very bad in the terminal)
**when the `l.SetStyle()` is applied (if outcommented it behaves without weird white-spaces till column 350 approx)**

- Note: this not a terminal issue. The output in the text file is the same when you pipe it etc.

```go
package main

import (
"os"
"time"

"github.com/charmbracelet/lipgloss"
chlog "github.com/charmbracelet/log"
)

func getStyles() *chlog.Styles {
styles := chlog.DefaultStyles()

styles.Message = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#1b4796", Dark: "#58A6FF"})

styles.Levels[chlog.DebugLevel] = lipgloss.NewStyle().
SetString("DEBUG").
Padding(0, 1, 0, 1).
Background(lipgloss.Color("#00e6ff")).
Foreground(lipgloss.Color("0")).Bold(true)

styles.Levels[chlog.InfoLevel] = lipgloss.NewStyle().
SetString("INFO").
Padding(0, 1, 0, 1).
Background(lipgloss.Color("#00c41a")).
Foreground(lipgloss.Color("0")).Bold(true)

styles.Levels[chlog.WarnLevel] = lipgloss.NewStyle().
SetString("WARN").
Padding(0, 1, 0, 1).
Background(lipgloss.Color("#ff7400")).
Foreground(lipgloss.Color("0")).Bold(true)

styles.Levels[chlog.ErrorLevel] = lipgloss.NewStyle().
SetString("ERROR").
Padding(0, 1, 0, 1).
Background(lipgloss.Color("#ff0000")).
Foreground(lipgloss.Color("0")).Bold(true)

styles.Prefix = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#007399", Dark: "#44b5c3"}).
Italic(true)

styles.Caller = lipgloss.NewStyle().Italic(true)

styles.Key = lipgloss.NewStyle().
Foreground(lipgloss.AdaptiveColor{Light: "#007399", Dark: "#44b5c3"}).
Bold(true)

return styles
}

func main() {
l := chlog.NewWithOptions(
os.Stderr, chlog.Options{
ReportCaller: false,
ReportTimestamp: true,
TimeFormat: time.TimeOnly,
})

styles := getStyles()
l.SetStyles(styles)

s := `
2 errors occurred:
* Runner 'custodian::manifest-ytt' for target 'custodian-manifests::manifest' failed.
* command failed: '["kbld" "-f" "-" "--imgpkg-lock-output" "/persist/repos/custodian/tools/deploy/manifests/.output/build/manifests/local-development/.imgpkg/images.yaml"]',
- cwd: '/persist/repos/custodian/tools/deploy/manifests/.output/build/manifests/local-development',
- env: ["... same as calling proc. ..."],
- exit: 1,
- stderr:
| kbld: Error:
| - Resolving image 'contract-manager': GET https://index.docker.io/v2/library/contract-manager/manifests/latest: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:library/contract-manager Type:repository]]
|
`

l.Infof("Error occurred: '%s", s)
}
```

Resultin in:

Image

### Version

0.4.2

### Environment

nixos, wezterm

Contributor guide

Open the contributing guide

Research direction

Start by running the provided Go reproducer with l.SetStyles and l.Infof, comparing its output with styles disabled and with the version stated in the report. Trace the styled output path and add a regression check for the long whitespace lines; done means the multiline message remains correctly formatted when styles are applied.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.