Skip to content

bug: strange whitespace in output with styles applied #187

@gabyx

Description

@gabyx

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.
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions