Creating a real-time console display

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Adam Bertram Adam Bertram 1 year, 12 months ago.

  • Author
    Posts
  • #21001
    Profile photo of Adam Bertram
    Adam Bertram
    Participant

    Sorry I wasn't more specific in this subject but I'm not sure how to describe what I'm thinking. I want to start a project that requires a stock ticker-like output in the Powershell console. I'm not sure where to even start with this. I want to provide a layout (text, console-based output only) that will have multiple "fields". Each of these "fields" will simply be the output of a Write-Host.

    I want to run another script in parallel with this console layout that will send output from that script to this layout only by updating a specified field.

    Here's my attempt at explaining this better in a screenshot. http://screencast.com/t/IMVyifeH

    I essentially want a "ReplaceAndWrite-Host" cmdlet. Something that will replace text in a particular spot in the console and update it without any interaction.

    How would I even start this?

  • #21002
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Depending on what else is going on in that window, you can use [Console]::SetCursorPosition() followed by [Console]::Write() or ::WriteLine(). You can retrieve the current cursor position with [Console]::CursorLeft and [Console]::CursorTop , and put it back where you found it with another call to [Console]::SetCursorPosition() after drawing your stuff.

    Alternatively, you can just clear the console and re-draw your entire UI on every refresh, if you prefer. Either way, it makes me want to go play Zork again. 🙂

  • #21003
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    (The console APIs will only work properly in powershell.exe, btw. Don't expect to be able to test that in the ISE.)

  • #21004
    Profile photo of Adam Bertram
    Adam Bertram
    Participant

    Nice! Thanks as always, Dave. The [Console] object is exactly what I needed. I wasn't aware of that. Thanks!

You must be logged in to reply to this topic.