log icon indicating copy to clipboard operation
log copied to clipboard

ansi characters when air is used

Open basaran opened this issue 2 years ago • 16 comments

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?

basaran avatar Nov 12 '23 23:11 basaran

Run into this issue today also https://github.com/cosmtrek/air/issues/502

laupse avatar Nov 17 '23 14:11 laupse

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.

jallier avatar Nov 22 '23 00:11 jallier

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

meowgorithm avatar Nov 22 '23 02:11 meowgorithm

2. CI=true air

Thanks for the workaround

laupse avatar Nov 22 '23 08:11 laupse

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

https://github.com/charmbracelet/log/assets/98523125/0ea6e749-bc13-4ac5-82ea-8bbec7af5757

package main

import (
        "os"

        "github.com/charmbracelet/log"
)

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

laupse avatar Nov 28 '23 08:11 laupse

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

aymanbagabas avatar Nov 28 '23 15:11 aymanbagabas

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%

notdodo avatar Dec 27 '23 20:12 notdodo

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

https://github.com/cosmtrek/air/issues/533#issuecomment-1993276683

hahuang65 avatar Mar 13 '24 03:03 hahuang65

This should be handled by https://github.com/charmbracelet/log/commit/28193306e6f5a221d00a74fa6e8683ea10ae06be released in v0.4.0, closing.

aymanbagabas avatar Mar 21 '24 16:03 aymanbagabas

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 avatar Mar 23 '24 15:03 hahuang65

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

hahuang65 avatar Mar 28 '24 18:03 hahuang65

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

CI=1
CLICOLOR_FORCE=1

caarlos0 avatar Jun 24 '24 16:06 caarlos0

Also encountering the same issue in WSL2 and air

firefart avatar Jun 24 '24 19:06 firefart

Encounter is in Air with ZSH on kitty terminal

more details here

Jawkx avatar Jun 27 '24 18:06 Jawkx

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

AtomicMegaNerd avatar Nov 13 '24 15:11 AtomicMegaNerd

I get the same output dumped into my terminal when using docker compose:

github.com/charmbracelet/log v0.4.0

docker compose logs service
service-1  | 22:30:32 INFO <cmd/main.go:39> XXXXXX

➜ 10;rgb:f8f8/f8f8/f2f2;14R11;rgb:2828/2a2a/3636;14R

seanamos avatar Jan 03 '25 22:01 seanamos