Commit dab63839 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Simplify ConsoleWidth() and implement it for real on Win32

parent dc31c77a
...@@ -1868,34 +1868,21 @@ static void PauseConsole( void ) ...@@ -1868,34 +1868,21 @@ static void PauseConsole( void )
*****************************************************************************/ *****************************************************************************/
static int ConsoleWidth( void ) static int ConsoleWidth( void )
{ {
int i_width = 80; unsigned i_width = 80;
#ifndef WIN32 #ifndef WIN32
char buf[20]; FILE *file = popen( "stty size 2>/dev/null", "r" );
char *psz_parser = NULL; if (file != NULL)
FILE *file = NULL;
int i_ret;
file = popen( "stty size 2>/dev/null", "r" );
if( file )
{ {
i_ret = fread( buf, 1, 20, file ); if (fscanf (file, "%*u %u", &i_width) <= 0)
if( i_ret > 0 ) i_width = 80;
{
buf[19] = '\0';
psz_parser = strchr( buf, ' ' );
if( psz_parser )
{
i_ret = atoi( psz_parser + 1 );
if( i_ret >= 80 )
{
i_width = i_ret;
}
}
}
pclose( file ); pclose( file );
} }
#else
CONSOLE_SCREEN_BUFFER_INFO buf;
if (GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &buf))
i_width = buf.dwSize.X;
#endif #endif
return i_width; return i_width;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment