Skip to footer content
Iron Academy Logo
C# Application
C# Application

Other Categories

Modifying Data Live On-Screen - Spectre Console Series

Tim Corey
9m 17s

Spectre.Console is a .NET library that lets you create beautiful console applications far beyond the plain black-and-white command line. In his video “Modifying Data Live On-Screen – Spectre Console Series”, Tim Corey demonstrates the Spectre Console live display feature. This feature allows you to display progress and update data on screen in real time inside your console applications.

In this article we’ll step through Tim’s video, showing where he does each thing and how he explains it.

Introduction to Live Display

Tim starts by explaining Spectre.Console and how it makes your console apps visually appealing. In this series, each lesson is a short example, and the source code is linked in the description.

He explains that this lesson focuses on how to use the live display feature to modify existing data on the screen for real-time updates. Tim also encourages viewers to subscribe and visit iamtimcorey.com for more training resources.

Creating a New Table for Data

Tim shows that he has already created a new table with the title, lessons, and hours columns. This table will be used to render course information pulled from an API.

He also introduces a record type called CourseInfo with strongly typed properties for course name, lesson count, and course length in hours. This mirrors the API structure and lets him easily output text in a strongly typed way.

The table has show footers turned on so totals can be displayed later. Tim notes that this layout is one of many arbitrary widgets Spectre supports for beautiful console applications.

Starting the Live Display

Tim uses the method AnsiConsole.Live(table).StartAsync(...) to begin the live display. He points out there’s also a non-async Start() function if you don’t need to await long running tasks.

He wraps his code in an async context so the console can refresh as new rows arrive. This demonstrates the current terminal’s capabilities to redraw output without clearing the screen.

Fetching Data and Displaying Progress

Inside the live context, Tim writes a for loop using an int index from 1 to 31 because the sample API lists 31 courses. For each index, he calls a helpers class method to fetch API data.

This helper converts the raw JSON string into a strongly typed CourseInfo object. Tim intentionally calls the API one course at a time instead of in bulk to show how display progress happens live — a great example of simulating long running tasks in a console environment.

He notes that if he had wanted just one request, he could have removed the /i in the URL, but he’s doing multiple calls “to show things coming in over time.”

Adding Rows and Updating Output

With each returned CourseInfo instance, Tim calls table.AddRow(...) to create a new row with the course’s title, lesson count, and length in hours. He uses string interpolation with the $ format and calls .ToString() where needed to convert values that are not strings.

This renders the table with new rows on each pass, showing how Spectre can update rows dynamically. He also demonstrates catching potential issues like type mismatches by being explicit about conversions.

Custom Footers and Running Totals

Next Tim shows how to add custom footers to the columns. He sets table.Columns[0].Footer to show the count of courses downloaded so far. He duplicates this for the second and third columns, but this time sums lesson counts and total hours across all courses.

By doing this, the user can see at a glance how many lessons and how many hours have accumulated. This is a real-world example of using Spectre’s controls to display value totals alongside live data.

Tim briefly “unpinned” the window so you can see the full layout as the numbers grow. He explains that footers are part of the built-in styles Spectre offers, much like borders, markup, and themes.

Refreshing the Context After Each Action

Tim emphasizes the “critical thing” about live displays: always call context.Refresh() after making changes. This ensures the terminal actually redraws your output with the new data. Without this, your rows, footers, or even different colors wouldn’t appear until the live session ends.

Debugging and Exception Handling

When he first runs the code, Tim hits an Index Out of Range exception. He walks through his mistake — miscounting the column indices (they’re 0,1,2 not 0,2,3) — and corrects it.

This is a gentle reminder that even in Spectre.Console, you should catch errors and ensure your indices and args are correct.

Spectre Console Modifying Data Live 1 related to Debugging and Exception Handling

Watching the Live Display in Action

Tim runs the corrected code and shows the live display in action: rows being added, totals updating, and the footer displaying combined values.

You can see “1,652 lessons,” “403.5 hours,” and “31 total courses” as the data streams in. This is exactly the kind of action that makes Spectre Console live display feel like a dashboard inside your current terminal.

Spectre Console Modifying Data Live 2 related to Watching the Live Display in Action

Focusing Only on the Footers

To make changes more visible, Tim comments out the row-adding code so only the footers update. This shows how even without scrolling data you can track totals live.

He also notes that Spectre automatically adjusts column width when numbers grow (for example, from 9 to 10). This is a small but powerful example of the library’s auto detection of widths and format.

Spectre Console Modifying Data Live 3 related to Focusing Only on the Footers

Beyond Tables – Arbitrary Widgets and Themes

Tim explains that the live display is not limited to tables. You can apply it to arbitrary widgets like panels, prompt user input, or even a bar chart. You can update text, highlight different colors, apply custom color coded themes, or add spinners.

He mentions you can change styles such as blue, green, or grey to match your themes, and you can even work with nested layout or widgets. This flexibility is what makes Spectre “heavily inspired” by rich console tools in other ecosystems (some even python written) but tailored for .NET.

Async vs. Sync Live Display Start

Tim clarifies why he used the async version: because he was awaiting API calls. If your updates aren’t asynchronous, you can just call Start() without await.

This choice helps you build beautiful console applications that stay responsive even with long running tasks.

Conclusion

In his video, Tim have just shown how to build a Spectre Console live display that can update, sum, and refresh data right inside the console.

This is a great foundation for prompting user input, adding widgets, or building dashboards with different colors and custom color coded themes. Combined with Spectre’s ability to easily output text, use markup, and create controls like panels or trees, you can build dynamic .NET apps right in your terminal.

Tim’s demonstration shows that with Spectre.Console you can create not only dashboards but also live updating tables, spinners, and other widgets. It’s a practical example of turning a plain console into a real-time, interactive tool — and a nice way to say “happy coding” to your users.

Hero Worlddot related to Modifying Data Live On-Screen - Spectre Console Series
Hero Affiliate related to Modifying Data Live On-Screen - Spectre Console Series

Earn More by Sharing What You Love

Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!