Silversonic
Posts: 34
Joined: Wed Aug 27, 2014 8:42 pm

Making output (e.g. "Hello World") center display.

Wed Mar 04, 2015 4:11 am

I'm looking to develop a C++ Program that removes what's currently on my PiTFT display and places the output (cout) at the centre of the screen.

For instance, a simple "Hello World" program called main which, when I type ./main in to the command line, removes all previous command line data and simply has "Hello World" at the centre. At the very least I can just shove the right amount of cout << "\n" but that seems a bit brute-forced.

Is there a cleaner method for this? What would be a good utility? Currently my output already centers itself horizontally, it just needs to clear out the display and center vertically. The data I want on the front screen will also be changing with time (e.g. I may want "Today is the 1st of March" on the center, then when the day changes it would change to "Today is the 2nd of March").

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Making output (e.g. "Hello World") center display.

Wed Mar 04, 2015 4:18 am

Have a look at ncurses. You will can install the library from the repository.

Code: Select all

sudo apt-get update
sudo apt-get install libncurses5-dev

Silversonic
Posts: 34
Joined: Wed Aug 27, 2014 8:42 pm

Re: Making output (e.g. "Hello World") center display.

Wed Mar 04, 2015 7:06 pm

Good package. Thanks.

Return to “C/C++”