Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansi characters when air is used #90

Open
basaran opened this issue Nov 12, 2023 · 15 comments · Fixed by #93
Open

ansi characters when air is used #90

basaran opened this issue Nov 12, 2023 · 15 comments · Fixed by #93

Comments

@basaran
Copy link

basaran commented Nov 12, 2023

Hello,

I use air as a live reload tool during development. When the log is used, I get scrambled ansi characters on the terminal (alacritty).

Here's a recording:
https://github.com/charmbracelet/log/assets/30809170/36b68013-a03b-47e5-85aa-5f85f3058d30

Is this an air issue?

@laupse
Copy link

laupse commented Nov 17, 2023

Run into this issue today also air-verse/air#502

@jallier
Copy link

jallier commented Nov 22, 2023

I have also had this same issue, but I have 2 things to add:

  1. It only appears to affect wsl2 for me. I get the same ansi characters (plus slowdown in rebuilds in air), but only in wsl2. Running air on macos in iterm2 has no issues. I get the same behaviour using windows terminal, or the vscode built in terminal. Running without air everything works perfectly.
  2. You can disable the colour detection using CI=true air ... instead of running air directly - this will fix the slowness of rebuilding at the cost of not having coloured logs when using air.

@meowgorithm
Copy link
Member

Hey there! This looks like a side effect from background color detection upstream in termenv (cc @muesli)

@laupse
Copy link

laupse commented Nov 22, 2023

2. CI=true air

Thanks for the workaround

aymanbagabas added a commit that referenced this issue Nov 22, 2023
Don't use AdaptiveColors and use regular colors instead. This makes the
default styles _not_ use HasDarkBackground to determine the terminal
background color. HasDarkBackground will query the terminal for the
background color using `OSC 11` to determine which color to use in
AdaptiveColor.

For users who still want to use AdaptiveColors, they can supply their
own custom styles.

Fixes: #90
aymanbagabas added a commit that referenced this issue Nov 27, 2023
…lor (#93)

Don't use AdaptiveColors and use regular colors instead. This makes the
default styles _not_ use HasDarkBackground to determine the terminal
background color. HasDarkBackground will query the terminal for the
background color using `OSC 11` to determine which color to use in
AdaptiveColor.

For users who still want to use AdaptiveColors, they can supply their
own custom styles.

Fixes: #90
@laupse
Copy link

laupse commented Nov 28, 2023

Looks like the issue is still here with latest 0.3.1 release which includes the fix

2023-11-28.09-49-43.mp4
package main

import (
        "os"

        "github.com/charmbracelet/log"
)

func main() {
        log.NewWithOptions(os.Stdout, log.Options{})
        log.Info("test")
}

@aymanbagabas aymanbagabas reopened this Nov 28, 2023
@aymanbagabas
Copy link
Member

Hey there! This looks like a side effect from background color detection upstream in termenv (cc @muesli)

It looks like this is a result of querying the cursor position (CPR) CSI 6 n from termenv

@notdodo
Copy link

notdodo commented Dec 27, 2023

Hi!

I get the same result of @basaran but only when running the app inside a docker container (compiles in golang:alpine and runs in FROM scratch).

This also slows down the startup/bootstrap of the application. CI=true actually "fix" the issue about the chars but the slowdown is quite annoying.

FROM golang:alpine as app-builder
WORKDIR /go/src/app
RUN --mount=type=cache,target=/go/pkg/mod/ \
    --mount=type=bind,source=go.sum,target=go.sum \
    --mount=type=bind,source=go.mod,target=go.mod \
    go mod download -x
RUN --mount=type=cache,target=/go/pkg/mod/ \
    --mount=type=bind,target=. \
    CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -tags timetzdata -o /go/bin/my_app

FROM scratch
COPY --from=app-builder /go/bin/my_app /my_app
COPY .env /.env
COPY --from=alpine:latest /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
HEALTHCHECK NONE
ENTRYPOINT [ "/my_app" ]

output of docker run

[+] Building 1.3s (14/14) FINISHED                                                                                                                                            docker:default
 => [internal] load .dockerignore                                                                                                                                                       0.0s
 => => transferring context: 176B                                                                                                                                                       0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                    0.0s
 => => transferring dockerfile: 629B                                                                                                                                                   
[... snip ...]
 => exporting to image                                                                                                                                                                  0.0s
 => => exporting layers                                                                                                                                                                 0.0s
 => => writing image sha256:a45f84819330543d4d8d17759c2b069e6d73f88fffb10e0355accd27ea89e44d                                                                                            0.0s
 => => naming to docker.io/library/my_app                                                                                                                                                0.0s
^[]10;rgb:fcfc/fcfc/fcfc^[\^[[49;1R^[]11;rgb:2323/2626/2727^[\^[[49;36R^[]10;rgb:fcfc/fcfc/fcfc^[\^[[49;72R^[]11;rgb:2323/2626/2727^[\^[[49;108R%

@hahuang65
Copy link

It looks like this was fixed by another package similarly to @aymanbagabas fix in #93

air-verse/air#533 (comment)

@aymanbagabas
Copy link
Member

This should be handled by 2819330 released in v0.4.0, closing.

@hahuang65
Copy link

Unfortunately, this does not appear to be fixed with 0.4.0:

air --build.cmd "go build -o /tmp/bin/baz ./cmd/api" --build.bin "/tmp/bin/baz" --build.delay "100" --build.exclude_dir "" --build.include_ext "go, tpl, tmpl, html, css, scss, js, ts, sql, jpeg, jpg, gif, png, bmp, svg, webp, ico" --misc.clean_on_exit "true"

  __    _   ___
 / /\  | | | |_)
/_/--\ |_| |_| \_ v1.51.0, built with Go go1.22.1

mkdir /home/hao/Documents/Projects/baz/tmp
watching .
watching cmd
watching cmd/api
watching internal
watching internal/env
watching internal/log
watching internal/request
watching internal/response
watching internal/testhelper
watching internal/validator
watching internal/version
!exclude tmp
building...
running...
^[]10;rgb:cdcd/d6d6/f4f4^[\^[[99;1R^[]11;rgb:1e1e/1e1e/2e2e^[\^[[99;36R2024-03-23 10:56:02 INFO <api/server.go:49> starting server server="[addr=:4444]"

@hahuang65
Copy link

Considering the above ^, should I open a new ticket?

@caarlos0
Copy link
Member

FWIW a more complete workaround, with the output still having colors, is to set these 2 envs:

CI=1
CLICOLOR_FORCE=1

@caarlos0 caarlos0 reopened this Jun 24, 2024
@firefart
Copy link

Also encountering the same issue in WSL2 and air

@Jawkx
Copy link

Jawkx commented Jun 27, 2024

Encounter is in Air with ZSH on kitty terminal

more details here

Malanris pushed a commit to Malanris/plog that referenced this issue Jul 29, 2024
…lor (#93)

Don't use AdaptiveColors and use regular colors instead. This makes the
default styles _not_ use HasDarkBackground to determine the terminal
background color. HasDarkBackground will query the terminal for the
background color using `OSC 11` to determine which color to use in
AdaptiveColor.

For users who still want to use AdaptiveColors, they can supply their
own custom styles.

Fixes: charmbracelet/log#90
@AtomicMegaNerd
Copy link

I see similar junk output running in a container inside of podman.

Running container publish-md-to-confluence:local...
^[]10;rgb:caca/d3d3/f5f5^[\^[[67;1R^[]11;rgb:2424/2727/3a3a^[\^[[67;36RINFO <build/main.go:13> Welcome to md-doc-publisher

Setting the two environment variables worked to suppress the junk output.

CI=1
CLICOLOR_FORCE=1

Running the 0.4.0 release:

github.com/charmbracelet/log v0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.