rockorager / libvaxis

a modern tui library written in zig
https://rockorager.github.io/libvaxis/
MIT License
463 stars 32 forks source link

Question: Saving output of alt_screen #106

Closed JustinBraben closed 1 week ago

JustinBraben commented 1 week ago

For my project zbonsai, I would like to be able to print the finished product to the screen and give back control of the terminal afterwards.

Currently my project draws to the alt_screen, then waits for a Ctrl + C to leave the program.

Is there some way I could:

  1. Save a copy of everything from some final frame of the alt_screen to a buffer
  2. Deinitialize/cleanup the vaxis app
  3. Print the copy to the screen, then deinitialize/cleanup the copy

Using the library, buffers, or otherwise?

rockorager commented 1 week ago

There are two ways I think this might work:

  1. You could try exiting the alt screen and doing another render. I think that should work.
  2. You could try exiting the alt screen and calling vx.prettyPrint(tty.anyWriter);. I believe this should also work.

If neither of these work, I would love to figure out a solution for this use case with you. Let me know if there are issues you see with either of those options!

-- Tim

JustinBraben commented 1 week ago
  1. You could try exiting the alt screen and calling vx.prettyPrint(tty.anyWriter);. I believe this should also work.

This worked quite painlessly. Thanks!

// If -p flag passed to program, print the tree to terminal after completion
if (self.args.printTree) {
    try self.vx.exitAltScreen(self.tty.anyWriter());
    try self.vx.prettyPrint(self.tty.anyWriter());
}