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

Feature request: support for SGR subparameters #179

Open
jfly opened this issue Oct 8, 2024 · 0 comments
Open

Feature request: support for SGR subparameters #179

jfly opened this issue Oct 8, 2024 · 0 comments

Comments

@jfly
Copy link

jfly commented Oct 8, 2024

pyte current supports setting foreground/background color, but it only supports ; delimited parameters. My understanding is that this is a legacy of xterm mis-interpreting some ancient specification:

In other words, there are 2 ways set the foreground color of text (this applies to other SGR parameters, I'm just picking foreground color to be concrete):

  1. echo -e "\x1b[38:5:5mfoo\x1b[mbar": Uses colons to delimit context/subparameters
  2. echo -e "\x1b[38;5;5mfoo\x1b[mbar": Uses semicolons. Creates ambiguity between parameters and context/subparameters. Discouraged.

Let's see how pyte handles these things. Here's my test script:

test.py
import sys
import pyte

def show_chars(screen: pyte.Screen, properties: list[str]):
    for line in range(screen.lines):
        for column in range(screen.columns):
            char = screen.buffer[line][column]
            if char.data != " ":
                props = { prop: getattr(char, prop) for prop in properties }
                pretty_props = ", ".join(f"{k}={v}" for k, v in props.items())
                print(f"{char.data}\t{pretty_props}")

screen = pyte.Screen(columns=30, lines=5)
stream = pyte.Stream(screen)

stream.feed(sys.argv[1])
show_chars(screen, properties=['fg'])

pyte 0.8.2

semicolon delimited

This works as expected:

$ python test.py $'\x1b[38;5;5mfoo\x1b[mbar'
f	fg=cd00cd
o	fg=cd00cd
o	fg=cd00cd
b	fg=default
a	fg=default
r	fg=default

colon delimited

pyte does not "understand" the colors, and even worse, there's unnecessary spew
printed. The spew will be addressed by my upcoming changes for
#178.

$ python test.py $'\x1b[38:5:5mfoo\x1b[mbar'
5	fg=default
:	fg=default
5	fg=default
m	fg=default
f	fg=default
o	fg=default
o	fg=default
b	fg=default
a	fg=default
r	fg=default
@jfly jfly changed the title Feature request: support for SGR parameters with colon delimited context Feature request: support for SGR subparameters Oct 8, 2024
jfly added a commit to jfly/pyte that referenced this issue Oct 8, 2024
This fixes selectel#178.

Before, we assumed that CSI parameters are only integers. However, that
caused us to barf in weird ways when presented with CSI parameters that
contain `:`-delimited subparameters.

This update to the parsing code causes us to parse those subparameters,
and then immediately discard them. That may seem kind of weird, but I'm
laying the groundwork for a followup change to the SGR handling code to
actually be aware of subparameters
(selectel#179). I just didn't want to
muddy this diff with that change as well.
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

No branches or pull requests

1 participant