1

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?

1
  • I think you would be better of saying "can the C++ language do this alone, or do I need a library of some kind". What exactly do you mean by a Platform? A version of a C++ Compiler? A library that ships with some particular compiler? Commented Jan 28, 2011 at 18:37

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ncurses is a cross platform library, but as the question asks about if you can do this in C++ "only", perhaps the better way to say this is "you need a library of some kind, the C++ language itself doesn't provide console features, terminal emulation, and so on".
2

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.