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

[BUG] Syntax content is dedented and stripped in GitHub Actions #3500

Closed
2 tasks done
AAriam opened this issue Sep 25, 2024 · 8 comments
Closed
2 tasks done

[BUG] Syntax content is dedented and stripped in GitHub Actions #3500

AAriam opened this issue Sep 25, 2024 · 8 comments

Comments

@AAriam
Copy link

AAriam commented Sep 25, 2024

Describe the bug

from rich.console import Console
from rich.panel import Panel
from rich.syntax import Syntax

yaml_syntax = """
test: true
examples:
    ex1: 1
    ex2: 2
"""
code_panel = Panel(Syntax(yaml_syntax, lexer="yaml"))
console = Console(force_terminal=True)
console.print(code_panel)

Works fine in a terminal:

Screenshot 2024-09-25 at 17 07 19

But not on GitHub Actions:

Tip

When force_terminal is not set for Console, the problem is solved, but then of course you don't get any syntax highlighting!

Screenshot 2024-09-25 at 17 07 54

Note

The panel is just there to better illustrate the issue; the results are the same without it.

Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

This isn't a Rich issue. You might want to raise it with Github?

@AAriam
Copy link
Author

AAriam commented Sep 25, 2024

Hi @willmcgugan,

Thanks for your time and the great work!
Do you maybe have an idea what exactly is happening there?

@willmcgugan
Copy link
Collaborator

If I were to guess. It looks like it interpreting the output as HTML, which will collapse spaces.

@AAriam
Copy link
Author

AAriam commented Sep 25, 2024

So, basically what's happening is that GitHub Actions ignores any whitespace-only segment that is enclosed by two ANSI sequences, or one ANSI and the end of line:

Sample workflow to reproduce:

on: workflow_dispatch
jobs:
  test-ansi:
    runs-on: ubuntu-latest
    steps:
      - shell: python
        run: |
          print("The following must print a red line but it does not:")
          print("\033[48;2;255;0;0m                                  ")
          
          print("It only prints the line if it has a non-space character:")
          print("\033[48;2;255;0;0m               X                  ")
          
          print("Leading spaces are normally respected:")
          print("                        \033[48;2;255;0;0m     X    ")
          
          print("But not when they are enclosed by ANSI code:")
          print("\033[48;2;255;0;0m                       \033[0m  X ")
          
          print(
            "Basically, all segments containing only spaces are ignored "
            "when enclosed between two ANSI sequences, "
            "or one ANSI sequence and the end of the line:"
          )
          print("\033[48;2;255;0;0m         \033[48;2;0;255;0m           \033[48;2;0;0;255m          ")

Output:
Screenshot 2024-09-25 at 23 04 55

Thanks for the reply @willmcgugan; I opened a ticket with GitHub.

@AAriam AAriam closed this as completed Sep 25, 2024
Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

@willmcgugan
Copy link
Collaborator

Nice sleuthing. Do you have a link to the issue? I’d like to follow it.

@AAriam
Copy link
Author

AAriam commented Sep 25, 2024

I opened an issue at https://support.github.com/contact/bug-report, the issue is at https://support.github.com/ticket/3019506, but I think its only accessible by me?

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

No branches or pull requests

2 participants