bczsalba / pytermgui

Python TUI framework with mouse support, modular widget system, customizable and rapid terminal markup language and more!
https://ptg.bczsalba.com
MIT License
2.25k stars 56 forks source link

[BUG] Hyperlink are not correctly displayed #107

Closed leonard-IMBERT closed 1 year ago

leonard-IMBERT commented 1 year ago

Describe the bug

Hyperlink are not correctly displayed

To Reproduce

Here is a reproducible example:

import pytermgui as ptg

with ptg.WindowManager() as manager:

    windowBody = ptg.Window(
            """
            Hello there

            This is just some test with an [~https://google.com]hyperlink[/~] just right here

            And some other test.
            """
    )

    manager.add(windowBody)

Expected behavior

Expecting to have a window with

            Hello there

            This is just some test with an hyperlink just right here

            And some other test.

displayed

Screenshots

image

Here is the result I got

System information

image

Possible cause It seems that the hyperlink tag are not correctly rendered by ptg

Possible solution

The issue should be around here from what I understand

leonard-IMBERT commented 1 year ago

Ok, from what I see, when reaching this line (end of parsing) It tries to parse the clear token /~ but because /~ is not in the CLEARERS object, it will raise a MarkupSyntaxError appending /~ to the list of unknown aliases making it displayed

leonard-IMBERT commented 1 year ago

The one line problem come from the height being too small, my bad. But the PlainToken just before the link is not displayed. If some style is applied to it, it appear

Example code

v1

import pytermgui as ptg

with ptg.WindowManager() as manager:

    windowBody = ptg.Window(
            """
            Hello there

            This is just some test with an
            [~https://google.com]hyperlink[/~] just right here

            This is some other text with an other example [~https://example.com]here[/~]

            And some other test.
            """,
            height=50,
            width=80,
    )

v2

import pytermgui as ptg

with ptg.WindowManager() as manager:

    windowBody = ptg.Window(
            """
            Hello there

            [bold]This is just some test with an[/]
            [~https://google.com]hyperlink[/~] just right here

            This is some other text with an other example [~https://example.com]here[/~]

            And some other test.
            """,
            height=50,
            width=80,
    )

    manager.add(windowBody)

Results

v1

image

v2

image

leonard-IMBERT commented 1 year ago

The root of the problem seem to come from tokenize_ansi (called from Label.print() which call ptg.break_line)

bczsalba commented 1 year ago

Fixed by #108 (thanks!)