question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Screen re-/storing

See original GitHub issue

I’ve been playing around with rich as of late and I am really enjoying it. 👍 But there is one thing I wish was also in this wonderful chuck of code and that would be the ability to programmatically store and restore the terminal view (Like how less and other common commandline utilities do). I’ve got a somewhat working version of a decorator that I am using in my current project which I think some other people might find fairly useful. 😉

from contextlib import contextmanager
import subprocess

@contextmanager
def second_screen():
    try:
        r_code, s_code = (
            subprocess.getoutput(
                r"infocmp -1 | grep 'rmcup\|smcup' | sed 's/.*=\(.*\),/\1/'"
            )
            .replace("\\E", "\033")
            .split("\n")
        )
        try:
            print(s_code + "\033[0;0H", end="")
            yield
        finally:
            print(r_code, end="")
            return
    except:
        yield

I tried my hand at making it work with multiple different terminals by using infocmp to findout the proper escape sequence.

I am unsure if this is something that is considered inside the scope of this library, but imho I think it would by a great addition. I think the best way to integrate this into the API would be to add it as a member of the Console-class to enable the following usage:

from rich.console import Console

console = Console()

with console.second_screen():
    console.print("It works!", style="bold green")

EDIT: For me the escape sequences turn out to be:

s_code = '\033[?1049h\033[22;0;0t'
r_code = '\033[?1049l\033[23;0;0t'

So switch to secondary/primary buffer and re-/store icon and window title from/to stack respectively.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
willmcgugancommented, Nov 30, 2020

Closing this to tidy issues, but keeping a note of it.

1reaction
willmcgugancommented, Jun 9, 2020

I’d probably not bother with legacy windows now that there is the option of the new Windows Terminal. Unless there is a low cost compatibility layer, like colorama.

Let me know what your research turns up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature Request] Remember and Restore Window Location ...
I have a Surface Book that I use in laptop mode (3k screen) and in a docked mode on my desk (2 -...
Read more >
Feature Request - Restoring a database — Redgate forums
Hi, Can I log a feature request for sql backup. ... 1) That if a restore job fails that you can resubmit it...
Read more >
Restore Skip Button to Messages Screen - Forums - OwnerRez
Can we please have the skip button back in the messages screen? The new screen adds time to regular tasks. and it is...
Read more >
Windows 365 feature requests - Microsoft Tech Community
Currently non-admin users can only restart their own Cloud PCs from the external web portal. They lack the right to restart within the...
Read more >
Feature Request: layouts restore when restarting · Issue #743 ...
When restarting system or Amethyst, it will start from the first layout in the configuration again. since Mac will try reopening the applications, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found