Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rich Console Status Visual Bug #1578

Open
Labels
bug pythonPull requests that update Python code
@ShiftPoster

Description

Description

Using the Cmd.p* output methods from while a rich status spinner is running causes the messages to merge on the terminal.

Environment

  • Windows 11
  • Windows Terminal Version: 1.23.20211.0
  • Python 3.12.2
  • cmd2-3.2.0

Steps to Reproduce

import time
from argparse import Namespace
from cmd2 import Cmd, with_category
from rich.console import Console
TEST_CATAGORY: str = "Test Commands"
console = Console()
class MyCmd(Cmd):
  @with_category(TEST_CATAGORY)
  def do_exemplar(self, args: Namespace):
    """This is what the status is expected to look like."""
    with console.status("Working!"):
      for _ in range(10):
        console.log("console.log: Hello from cmd!")
        time.sleep(0.1)
  @with_category(TEST_CATAGORY)
  def do_problem(self, args: Namespace):
    """Demonstrate the problem."""
    with console.status("Working!"):
      for _ in range(10):
        self.pwarning("pwarning: Hello from cmd!")
        time.sleep(0.1)
if __name__ == "__main__":
  MyCmd().cmdloop()
Image

Solutions

I did some digging into rich and cmd2 and could not find a way to insert my own console instance into the cmd2.Cmd for use with the print methods (cmd2.Cmd.p*). If there is an obvious solution, please let me know. I have been a long time user of this package and the new changes integrating rich are very exciting.

One possible fix would be to not create a new console object for each call to the print methods. I am not really sure how easy that will be to change or maintain. There could be a console attribute for the cmd2.Cmd class or cmd2 could manage a global console object like how rich does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug pythonPull requests that update Python code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /