Skip to content

fix for Nx1 sized Terminal#10209

Closed
FoamyGuy wants to merge 1 commit into
adafruit:mainfrom
FoamyGuy:allow_Nx1_terminal
Closed

fix for Nx1 sized Terminal#10209
FoamyGuy wants to merge 1 commit into
adafruit:mainfrom
FoamyGuy:allow_Nx1_terminal

Conversation

@FoamyGuy
Copy link
Copy Markdown
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

@FoamyGuy
Copy link
Copy Markdown
Collaborator Author

FoamyGuy commented Apr 1, 2025

I'm going to close this and make it against 9.2.x instead.

@FoamyGuy FoamyGuy closed this Apr 1, 2025
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.

1 participant