Jump to content
  • Advertisement
Sign in to follow this  
sAlFace

Formatting text in the console window

This topic is 4978 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to turn off the "word wrap" in the console window? (i.e. when parts of your word go to the next line because they go off the side). If not what is the best way to prevent this from happening? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I know of no way to turn off "word wrap."
What you could do, is make your own print function.

Here's a sample function


void my_print( char* word )
{
static int counter; //counts number of letters written to the console
int size=0;
while( word[size] != '\0' )
size;
counter += size;
//if the word will wrap
if( counter > 80 )
{
printf("\n");//add a new line
counter = 0;//back to the beginning
}
printf("%s",word);//now write the word to the console
}

(Note: I just wrote the above function off the top of my head, so there's probably a few syntax errors in it, but do you get the idea?)

Share this post


Link to post
Share on other sites
Quote:
Original post by sAlFace
Is there a way to turn off the "word wrap" in the console window? (i.e. when parts of your word go to the next line because they go off the side). If not what is the best way to prevent this from happening? Thanks.
  • Output the control sequence ESC[?7l. To turn wrapping back on, replace the last character with an 'h'. This is found in man CONSOLE_CODES and should work on most terminals.
  • Copy the text into an 80 char buffer (using strncpy).
  • Set the field with for the output stream (cout.width(N)) in C++

Share this post


Link to post
Share on other sites
Quote:
Original post by igni ferroque
  • Output the control sequence ESC[?7l. To turn wrapping back on, replace the last character with an 'h'. This is found in man CONSOLE_CODES and should work on most terminals.


Just to be clear, that's a lowercase ell, not numeral one.
Oh, and "man" anything will of course not work on Windows ;) So here's what a quick googling turned up about CONSOLE_CODES.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!