Skip to content

fix for Nx1 sized Terminal #10210

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

Merged
merged 1 commit into from
Apr 1, 2025
Merged

Conversation

FoamyGuy
Copy link
Collaborator

@FoamyGuy FoamyGuy commented Apr 1, 2025

This forum post https://forums.adafruit.com/viewtopic.php?p=1051479#p1051479 reports an exception raised by the code from this learn guide: https://learn.adafruit.com/infinite-text-adventure/overview.

The code is attempting to create a Terminal instance with height 1 https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Zorque_Text_Game_openai/code.py#L106-L111

The current validation of width and height >=2 was added here: #7892 but the actual implementation used differs subtly from what the referenced issue had asked for

Terminal should verify that the tilegrid is more than 1x1 and raise an exception if not.

The current implementation also raises an exception in the Nx1 case which is what the learn guide is doing.

This PR changes the validation to multiply width and height first so that we are validating the total area rather than each axis size independently.

I tested on a PyPortal Titano successfully with this code:

import supervisor
import terminalio
import displayio

bbox = terminalio.FONT.get_bounding_box()
main_group = displayio.Group(scale=1)
display = supervisor.runtime.display
display.root_group = main_group

palette = displayio.Palette(2)
palette[0] = 0x444444
palette[1] = 0xFFFFFF

def terminal_label(text, width_in_chars, palette, x, y):
    label = displayio.TileGrid(terminalio.FONT.bitmap, pixel_shader=palette,
                               width=width_in_chars, height=1, tile_width=bbox[0],
                               tile_height=bbox[1])
    label.x = x
    label.y = y
    term = terminalio.Terminal(label, terminalio.FONT)
    term.write(f"{text}")
    return label

main_group.append(terminal_label("Hello World"*2, display.width // bbox[0], palette, 2,2))

while True:
    pass

I also verified that 1x1 does still raise an exception

@dhalbert dhalbert requested a review from tannewt April 1, 2025 14:54
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

@tannewt tannewt merged commit 376e3ba into adafruit:9.2.x Apr 1, 2025
538 checks passed
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

Successfully merging this pull request may close these issues.

2 participants