Sign in to follow this  
sAlFace

Formatting text in the console window

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this