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

[REQUEST] Transient type/helper #3045

Closed
kfsone opened this issue Jul 20, 2023 · 3 comments
Closed

[REQUEST] Transient type/helper #3045

kfsone opened this issue Jul 20, 2023 · 3 comments

Comments

@kfsone
Copy link

kfsone commented Jul 20, 2023

How would you improve Rich?

Add a container/type called Transient for non-live, disposable text regions. Ideally, it would have a max_lines value beyond which it might delete or hide earlier lines.

What problem does it solve for you?

Rich comes very close to solving this problem, but so far all the approaches I've seen for implementing this with the current rich api involve an unfortunate and large intrusion into the participating code.

Given the following:

--> Running CMake
-- CMake yadda
-- CMake foo
-- CMake bar
-- | Compiler foo
-- | Linker bar
--< CMake Ran: 3.1s
--> Running Ninja
-- Ninja working
-- [1/3] compile
-- [2/3] or compile not
-- [3/3] there is no error
--< Ninja Ran: 1.7s
--> Translating
-- Translation
-- in
-- progress
-- cookies
-- eaten
--< Translated: 5.4s

I would want to be able to do something like:

console = Console()

# This section will collapse to one line" --* Ran CMake: n.nns"
with Transient() console=console) as outer_tr, Timer() as build_timer, Status("Building"):
  with Transient(console=outer_tr.console) as inner_tr:
    with Timer() as cmake_timer, Status("Running CMake", console=inner_tr.console):
      run_cmake()
      inner_tr.replacement("== Ran CMake: {cmake_timer():.2f}s")
  with Transient(console=outer_tr.console) as inner_tr:
    with Timer() as ninja_timer, Status("Running Ninja", console=inner_tr.console):
      run_ninja()
      inner_tr.replacement("== Ran Ninja: {ninja_timer():.2f}s")
  outer_tr.replacement("== Built: {build_timer():.2f}s")
...

Would iterate thru these appearances:

/ Building
/ Running CMake
- Building
-- CMake yadda
- Running CMake
\ Building

...

-- CMake yadda
-- CMake foo
-- CMake bar
-- | Compiler foo
-- | Linker bar
\ Running CMake
| Building
== Ran CMake: 3.1s
/ Building
== Ran CMake: 3.1s
/ Running Ninja
- Building

...

== Ran CMake: 3.1s
-- Ninja working
-- [1/3] compile
-- [2/3] or compile not
-- [3/3] there is no error
\ Running Ninja
| Building
== Ran CMake: 3.1s
== Ran Ninja: 1.7s
/ Building
== Built: 4.9s

And when the whole finishes, only the final "replacement" and any logged lines would be visible.

@github-actions
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

I don’t have any plans to add such a feature. Perhaps you can implement it in an external library.

@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