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

Piped and parallel options have leftover console output #566

Closed
skawaguchi-flipp opened this issue Oct 23, 2023 · 6 comments · Fixed by #647
Closed

Piped and parallel options have leftover console output #566

skawaguchi-flipp opened this issue Oct 23, 2023 · 6 comments · Fixed by #647
Labels
bug Something isn't working

Comments

@skawaguchi-flipp
Copy link

🔧 Summary

Using lefthook as described in #66 leads to leftover characters in the console. Things are otherwise working really well.

Lefthook version

1.5.2

Steps to reproduce

Using this lefthook.yml:

pre-commit:
  piped: true
  commands:
    generate-protos:
      run: buf generate
      glob: "**/*.proto"
    generate-mocks:
      run: rm -rf ./mocks && mockery
      glob: "**/*.go"
    static-checks:
      run: lefthook run static-checks
      glob: "**/*.go"

static-checks:
  parallel: true
  commands: 
    fmt:
      run: go fmt ./...
      stage_fixed: true
    tidy:
      run: go mod tidy
      stage_fixed: true
    lint:
      run: golangci-lint run ./...
      stage_fixed: true

Expected results

I expect my command prompt to be empty.

Actual results

The first two commands run with no problems. If there is only a change to a .proto file, the console is clear. However, any time static-checks runs, this is the what's in my terminal:

summary: (done in 7.27 seconds)       
✔️  generate-mocks
✔️  generate-protos
✔️  static-checks
^[]11;rgb:2222/1a1a/0f0f^[\^[[15;1R[lefthook-update 005005f] chore: some git commit message
 2 files changed, 1 insertion(+), 4 deletions(-)
% 11;rgb:2222/1a1a/0f0f5;1R

I'm not expecting my command prompt to include 11;rgb:2222/1a1a/0f0f5;1R.

Possible Solution

It looks like the git processing module is exiting early.

Logs / Screenshots

│ 🥊 lefthook v1.5.1  hook: pre-commit │
╰──────────────────────────────────────╯
┃  generate-mocks ❯ 


Generating Mocks 
rm -rf ./mocks
mockery
# mock output
Generate mocks - Done 

│  generate-protos (skip) no matching staged files
┃  static-checks ❯ 

│ [lefthook] cmd: [git rev-parse --show-toplevel]
│ [lefthook] dir: 
│ [lefthook] err: <nil>
│ [lefthook] out: /<path-to-files>
                                                           
│ [lefthook] cmd: [git rev-parse --git-path hooks]
│ [lefthook] dir: 
│ [lefthook] err: <nil>
│ [lefthook] out: .git/hooks
                          
│ [lefthook] cmd: [git rev-parse --git-path info]
│ [lefthook] dir: 
│ [lefthook] err: <nil>
│ [lefthook] out: .git/info
                         
│ [lefthook] cmd: [git rev-parse --git-dir]
│ [lefthook] dir: 
│ [lefthook] err: <nil>
│ [lefthook] out: .git
                    
╭─────────────────────────────────────────╮
│ 🥊 lefthook v1.5.1  hook: static-checks │
╰─────────────────────────────────────────╯
┃  tidy ❯ 


┃  fmt ❯ 


┃  lint ❯ 

go mod tidy
Running golangci-lint 
golangci-lint run ./...

                                      
  ────────────────────────────────────
summary: (done in 0.58 seconds)       
✔️  tidy
✔️  fmt
✔️  lint

                                      
  ────────────────────────────────────
summary: (done in 5.98 seconds)       
✔️  generate-mocks
✔️  static-checks
^[]11;rgb:2222/1a1a/0f0f^[\^[[15;1R[lefthook-update d0fd4b0] test
 1 file changed, 1 deletion(-)
 % 11;rgb:2222/1a1a/0f0f5;1R
@skawaguchi-flipp skawaguchi-flipp added the bug Something isn't working label Oct 23, 2023
@infotexture
Copy link

I'm also seeing weird control characters like �[1m, �[0m, �[2K, & �[1G in the log output:

╭──────────────────────────────────────╮
│ 🥊 lefthook v1.5.5  hook: �[1mpre-commit�[0m │
╰──────────────────────────────────────╯
┃  prettier ❯ 

samples/css/style.css�[2K�[1Gsamples/css/style.css 22ms

@jackTabsCode
Copy link

jackTabsCode commented Feb 26, 2024

Hey, I'm also experiencing this. This is my lefthook.yml:

pre-commit:
  commands:
    check:
      run: npx biome check --no-errors-on-unmatched --files-ignore-unknown=true {staged_files}

This is extremely frustrating so I'm hoping it can be fixed!

@mrexox

@mrexox
Copy link
Member

mrexox commented Feb 27, 2024

Hey! Do you only get this when you execute lefthook from within a lefthook command? Or does it also appears when having simple configuration?

What terminal emulator do you use?

Do you use tmux or some kind of multiplexer?

@mrexox
Copy link
Member

mrexox commented Feb 27, 2024

I have a temporary solution for you. You should pass use_stdin option to the commands that call lefthook themselves. Like in this example:

pre-commit:
  piped: true
  commands:
    static-checks:
      use_stdin: true
      run: lefthook run static-checks
      glob: "**/*.go"

The problem I could identify is the following: https://github.com/creack/pty module that lefthook uses to get the output adds these sequences, and I'm not sure if there's a way to fix this. However when you specify use_stdin the command is being executed without pty wrapper. I will dig into this issue in more details to fix it. But by now I only have a workaround.

@mrexox
Copy link
Member

mrexox commented Feb 27, 2024

Ok, I found the issue. Lefthook uses lipgloss.CompleteAdaptiveColor and this color adds a special sequence to detect the background. This sequence is not being captured by pty lib, so it's being printed.

I will change the colors in the next release and this issue will be fixed. Stay tuned.

@jackTabsCode
Copy link

@mrexox Hey there, thanks for looking into this! It looks like the text inserted into the prompt is fixed, but it looks like there's still some stuff being outputted. I'm not an expert with this kind of thing and am not 100% sure that it's lefthook.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants