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

fix REPL terminal garbled characters upon code.py finished #6077

Merged
merged 1 commit into from
Feb 21, 2022

Conversation

kmatch98
Copy link
Collaborator

This PR is to resolve the garbled characters observed in:
#6076 (comment)

Test code for standard use of the REPL:

for i in range(3):
    print("hello world!")

Test code for resizing the REPL. I just see one minor weirdness when using the resized REPL and then code.py finishes running. If there is no serial connection, whenever the code is done running and it resets back to the REPL, the "Code is done running." is not shown. There is just a black screen with Blinka.

If there is a serial connection, it shows the next lines "Autoreload is on....". To avoid this, the last line of your code you can add display.show(None). Alternately, we could rearrange the sequence of when "Code is done running." is printed so that it occurs after the REPL is reset.

import board
import displayio
import supervisor
import time


display=board.DISPLAY

# Create a bitmap with two colors
bitmap1 = displayio.Bitmap(display.width//4, display.height//4 - 10, 2)

# Create a two color palette
palette1 = displayio.Palette(2)
palette1[0] = 0xff00ff
palette1[1] = 0xffffff

# Create a TileGrid using the Bitmap and Palette
tile_grid1 = displayio.TileGrid(bitmap1, pixel_shader=palette1)


# Create a bitmap with two colors
bitmap2 = displayio.Bitmap(display.width//4, display.height//4 - 10, 2)

# Create a two color palette
palette2 = displayio.Palette(2)
palette2[0] = 0x00ffff
palette2[1] = 0xffffff

# Create a TileGrid using the Bitmap and Palette
tile_grid2 = displayio.TileGrid(bitmap2, pixel_shader=palette2)
tile_grid2.x=display.width//4

# Create a bitmap with two colors
bitmap3 = displayio.Bitmap(display.width//4, display.height//4 - 10, 2)

# Create a two color palette
palette3 = displayio.Palette(2)
palette3[0] = 0xffff00
palette3[1] = 0xffffff

# Create a TileGrid using the Bitmap and Palette
tile_grid3 = displayio.TileGrid(bitmap3, pixel_shader=palette3)
tile_grid3.x=2*display.width//4

# Create a Group
mygroup = displayio.Group()

print()
print()
print()
print("REPL control test: Taking control of REPL group")
time.sleep(3)


# clear the display to the REPL 
display.show(None)
splash = board.DISPLAY.root_group # this gets the current root_group, the REPL

# Note: You must "display.show" your own group before adding the splash to your own group.
# Reason: When displaying the normal REPL (for example with display.show(None), the splash
# group is already in a group that is displayed.  To remove the splash from the displayed group,
# you first have to display.show some other group, doing that will remove the splash from its group
# and allow you to append it to your own group. 
display.show(mygroup)

# resize the supervisor.splash group pixel dimensions, make it half the display height.
supervisor.reset_terminal(display.width//2, display.height//2)

# relocate the supervisor.splash group on the display, moving it half-way down the display
splash.x=display.width//2
splash.y=display.height//2
print("Resize and move the splash screen")

# append the supervisor.splash group to the displayed group.
mygroup.append(splash)
time.sleep(2)

# demonstrate how print statements scroll on the REPL/console display
print("Add some prints to show terminal scrolling:")
time.sleep(0.3)
for i in range(6):
    print("Line: {}".format(i))
    time.sleep(0.3)
time.sleep(1.5)

# Add bitmap rectangles to the display group
print("Add some displayio bitmap rectangles:")
time.sleep(1)

# Add the TileGrid to the Group
print("Add a pink rect.")
mygroup.append(tile_grid1)
time.sleep(0.5)
print("Add a cyan rect.")
mygroup.append(tile_grid2)
time.sleep(0.5)
print("Add a yellow rect.")
mygroup.append(tile_grid3)
time.sleep(0.5)

# print some more lines to show the console text scrolling, with 
# the bitmaps shown on the upper half of the display
for i in range(6):
    print("Another line feed: {}!".format(i))
    time.sleep(0.3)
time.sleep(3)
print("Ending the code")
time.sleep(1)

### If there is no serial connection, just the Blinka remains after the code is done.

### Have to reset the display to show(None) to see the "Code done running." text.
# display.show(None)

Copy link
Collaborator

@FoamyGuy FoamyGuy 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 to me. Tested successfully on PyPortal. The following scenarios all appear to be working as intended:

code.py without while True and doesn't raise an exception

code.py that does raise an exception (it remains visible)

code.py that contains screen splitting and doesn't have a loop. (screen split works normally and terminal returns to normal full size after code.py completes)

REPL executing code that raises an error. (error is visible but scrolls off the top as expected if you keep running more things)

REPL split screen and returning back to normal with ctrl+D

Thanks for working on this fix @kmatch98!

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Tested and works for me as well. Thanks!

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.

3 participants