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

[BUG] Status erases existing terminal lines after displaying new lines #3011

Closed
2 tasks done
ofek opened this issue Jun 29, 2023 · 8 comments
Closed
2 tasks done

[BUG] Status erases existing terminal lines after displaying new lines #3011

ofek opened this issue Jun 29, 2023 · 8 comments

Comments

@ofek
Copy link
Contributor

ofek commented Jun 29, 2023

Describe the bug

import time
from rich.console import Console

def main():
    console = Console()
    status = console.status('')

    status.start()
    status.update('running\n\nextra\ncontext')
    time.sleep(2)
    status.stop()

    status.start()
    status.update('running again')
    time.sleep(2)
    status.stop()

if __name__ == '__main__':
    main()

Platform

Click to expand
❯ C:\Users\ofek\AppData\Local\Programs\Python\Python311\python.exe -m pip freeze | rg rich==
rich==13.4.2
❯ C:\Users\ofek\AppData\Local\Programs\Python\Python311\python.exe -m rich.diagnose
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=199 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 43                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = True                                                          │
│       is_jupyter = False                                                         │
│      is_terminal = True                                                          │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=199, height=43),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=199,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=43,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=199, height=43)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 199                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭── <class 'rich._windows.WindowsConsoleFeatures'> ───╮
│ Windows features available.                         │
│                                                     │
│ ╭─────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │
│ ╰─────────────────────────────────────────────────╯ │
│                                                     │
│ truecolor = True                                    │
│        vt = True                                    │
╰─────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': None,                  │
│     'COLORTERM': None,             │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Windows"
@Textualize Textualize deleted a comment from github-actions bot Jun 29, 2023
@willmcgugan
Copy link
Collaborator

I think the issue is in starting and stopping the status multiple times. It was only intended to be started once.

This seems to give the intended result:

import time
from rich.console import Console

def main():
    console = Console()
    with console.status('') as status:

        status.update('running\nextra\ncontext')
        time.sleep(2)

        status.update('running again')
        time.sleep(2)

@ofek
Copy link
Contributor Author

ofek commented Jun 29, 2023

Is there a way to support that? My application has a global status object that is set up based on config that multiple callers can borrow to use

@willmcgugan
Copy link
Collaborator

It may be. Status ultimately uses the Live class. It probably wouldn't be too much work to make start and stop repeatable.

@ofek
Copy link
Contributor Author

ofek commented Jun 29, 2023

That would be really awesome if that was possible to make our use case work!

@ofek
Copy link
Contributor Author

ofek commented Aug 25, 2023

Has there been any update on this?

@willmcgugan
Copy link
Collaborator

Afraid not. Busy on the Textual side. Could you give me an example of The API you would expect?

@ofek
Copy link
Contributor Author

ofek commented Aug 28, 2023

I'm going to close this now actually, here is the BorrowedStatus class that I soon will be using everywhere https://github.com/pypa/hatch/pull/949/files#diff-85342eb0efd7b5266a2c9ba75e9ca76c5fe9e61f276a724855907c3e6e0bd56e

Thank you!

@ofek ofek closed this as completed Aug 28, 2023
@github-actions
Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants