You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a feature where you can set a scroll region and scroll up / down that portion of the screen. This is used in NetHack ttyrecs. See this sample code to demonstrate it:
importsysimporttime# Define helper functions to send escape sequencesdefesc(seq):
sys.stdout.write(f"\x1b[{seq}")
sys.stdout.flush()
# Clear the screenesc("2J") # CSI 2J clears the screen# Move cursor to home position (1,1)esc("H")
# Fill the terminal with some textforiinrange(1, 15):
print(f"Line {i}")
# Set a scroll region from line 2 to 10esc("2;10r")
# Pause to observe initial statetime.sleep(2)
esc("1S") # Scroll up 1 linetime.sleep(2)
# Scroll up within the scroll region# for _ in range(3):# esc("1S") # Scroll up 1 line# time.sleep(0.5)# Scroll down within the scroll region# for _ in range(2):# esc("1T") # Scroll down 1 line# time.sleep(0.5)# Reset scroll region to full screenesc("r")
And here is how you can recreate it using pyte:
importpytescreen=pyte.Screen(80, 20)
stream=pyte.Stream(screen)
asdf= [
b'\x1b[2J', # clear screenb'\x1b[H', # go to home (1, 1)
]
fordatainasdf:
stream.feed(data.decode('cp437'))
foriinrange(1, 15):
stream.feed(f"Line {i}\r\n")
# stream.do_thing()stream.feed(b"\x1b[2;10r".decode('cp437')) # Set scroll regionstream.feed(b"\x1b[2T".decode('cp437')) # Scroll down 2 linesstream.feed(b"\x1b[r".decode('cp437')) # Reset scroll regionforxinscreen.display:
print(repr(x))
There is a feature where you can set a scroll region and scroll up / down that portion of the screen. This is used in NetHack ttyrecs. See this sample code to demonstrate it:
And here is how you can recreate it using pyte:
Pyte outputs this:
As you can see nothing is scrolled.
The text was updated successfully, but these errors were encountered: