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

Sample for re-rendering / partially updating table #156

Closed
onionhammer opened this issue Dec 4, 2020 · 12 comments
Closed

Sample for re-rendering / partially updating table #156

onionhammer opened this issue Dec 4, 2020 · 12 comments
Labels

Comments

@onionhammer
Copy link

Hi! I want to display a table with values that continually update, it would be nice to have an 'idiomatic'/documented way of doing this (apologies if this is documented somewhere, I didnt find it)

I'm currently doing this by building a new Table() for every re-render, and clearing the whole buffer every time. Is this the only way?

@onionhammer
Copy link
Author

Update: looks like you added the (incredibly awesome) Progress since I implemented using a Table; which is a much better fit for my own case. Perhaps some way of rendering borders/etc for Progress to make it look more table-like, since it aldready has columns etc. would be nice.

@aclemmensen
Copy link

I'd actually like examples of this as well and I'd prefer to not be limited to using the Progress feature. I've experimented with calling System.Console.Clear() before rendering but that results in lots of flickering. Using AnsiConsole.Console.Clear(true) has the same result, more or less, but spams the console history with each frame I'm rendering.

Is there a canonical example of how to update UIs in-place? 🙏

@onionhammer onionhammer reopened this Dec 6, 2020
@patriksvensson
Copy link
Contributor

@onionhammer @aclemmensen Updating the UI in-place is kind of out-of-scope for Spectre.Console which isn't a TUI framework, and not something that I plan to support. Sorry.

@eduherminio
Copy link
Contributor

@onionhammer @aclemmensen Updating the UI in-place is kind of out-of-scope for Spectre.Console which isn't a TUI framework, and not something that I plan to support. Sorry.

Sorry to insist on this topic @patriksvensson, but I want to make sure I didn't get you wrong.
I'm also re-rendering a Table when I 'only' want to append new rows (similar to what you do in the first part of this Star Wars example).
I guess I can try to re-implement it now with Progress (missing some table-alike look as @onionhammer pointed, though); but can you confirm that there's no other way to do it?

@onionhammer
Copy link
Author

onionhammer commented Dec 7, 2020

For the record I think Table should definitely have some way of progressively adding rows; we live in a world of fetching data asynchronously, so not having that ability really limits how/when Tables are used.

I respect you're trying to reign in the scope though.. just not sure if that's where I'd personally draw the line given how powerful Progress seems to be.

@patriksvensson
Copy link
Contributor

@eduherminio @onionhammer It's an easy problem to solve if we only think about the happy path, i.e. update the table, but when it comes to things like supporting re-rendering of tables in terminals that do not support ANSI escape codes or doing cursor updates via ANSI (i.e. GitHub Actions) it gets a bit more complicated.

Progress is a fairly simple thing and there are fallback mechanisms in place for these scenarios. I will give it some thought and see if we can solve this problem in a way that's suitable.

In the meanwhile, check out this Gist on how to do back buffer rendering in the console. This is the technique I used when creating the table video: https://gist.github.com/patriksvensson/22791f3b413c313e80d4d77c3ff2a2a2

@patriksvensson
Copy link
Contributor

@onionhammer This should now be possible to do with the 0.40.0 release. See the Live example for more information.

@HolisticDeveloper
Copy link

@patriksvensson looks like a cool update! Is it possible to update the text in an existing row? Or, failing that, to remove a row?

In my scenario, I'm counting a bunch of widgets of different types. The different types of widgets are unknown. I'd like to display live information as I count the different widgets.

For example, after the first pass, I might have 18 foos, and 7 bars. After the next pass, I'll have a total of 25 foos, 19 bars, and 3 baz. So then I'd like to update the counts and add the new row.

I was thinking of doing this in a live table but perhaps a different approach would work better.

@patriksvensson
Copy link
Contributor

patriksvensson commented Jul 3, 2021

If I were you, I would probably use a live display, but instead of updating individual parts, which is difficult since table rows are immutable (by design and good reasons), I would probably regenerate the whole table and call ctx.SetTarget(newTable).

@HolisticDeveloper
Copy link

@patriksvensson works great, although the method is UpdateTarget(), not SetTarget().

@HolisticDeveloper
Copy link

Maybe this is handled now via #544 / #546?

@patriksvensson
Copy link
Contributor

@HolisticDeveloper Yes, should be able to now. Sorry for forgetting to update this issue!

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

No branches or pull requests

5 participants