开发者

How to create split screen console output?

开发者 https://www.devze.com 2023-02-07 20:45 出处:网络
I would like to be able to channel two text streams to a single console window with a vertical split view. The ideal solution would be if I could simply write to two different std::ostream objects.开发

I would like to be able to channel two text streams to a single console window with a vertical split view. The ideal solution would be if I could simply write to two different std::ostream objects. 开发者_运维百科

The reason I need it is to compare the output of two different versions of a program. I know there are simple workarounds like redirecting to file and using a diff program to view the differences. But that doesn't matter because this project is mostly just for fun.

I'm not sure however how to achieve this. Suppose that the left half has writtten 20 lines of output ahead of the right half. How do I move the cursor up to write the right half?

Can anyone give me some pointers on how to get started? Can this be done in pure C++ or do I need platform specific features?


This cannot be done using "pure c++" alone. You will need additional, potentially platform specific, libraries to implement the behavior you desire. For example, look at the ncurses library.


You can probably find some open source code in the olde terminal apps for text chat which did the same with a horizontal split.

Go back far enough and you will find usage of ansi escape sequences.

Writing something new ncurses is probably the way to go.

As an aside I reckon the diff/merge tool from tortoise is preatty good, from usage it really shows that simply putting code next to each other is probably not enough to make a useful eyeball comparison. You really get alot from the colourising and extra value add of the computer finding the differences for you.


Jlib may help.

A console library capable of colored input and output. Includes user definable menus, ASCII character windows, save/restore a screen worth of characters, 256 console color combinations, and a smart coloring.

0

精彩评论

暂无评论...
验证码 换一张
取 消