Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 12, 2010, 7:55:04 AM (14 years ago)
Author:
adrfried
Message:

Improve getTerminalSize

Width and height never get 0 anymore, this fixes a bug with a division
by zero in a special terminal reporting zero width.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/command/IOConsolePOSIX.cc

    r7287 r7422  
    319319    void IOConsole::getTerminalSize()
    320320    {
     321        this->terminalWidth_  = 0;
     322        this->terminalHeight_ = 0;
     323
    321324#ifdef TIOCGSIZE
    322325        struct ttysize win;
     
    325328            this->terminalWidth_  = win.ts_cols;
    326329            this->terminalHeight_ = win.ts_lines;
    327             return;
    328330        }
    329331#elif defined TIOCGWINSZ
     
    333335            this->terminalWidth_  = win.ws_col;
    334336            this->terminalHeight_ = win.ws_row;
    335             return;
    336         }
    337 #else
    338         const char* s = getenv("COLUMNS");
    339         this->terminalWidth_  = s ? strtol(s, NULL, 10) : 80;
    340         s = getenv("LINES");
    341         this->terminalHeight_ = s ? strtol(s, NULL, 10) : 24;
    342         return;
     337        }
    343338#endif
    344         this->terminalWidth_  = 80;
    345         this->terminalHeight_ = 24;
     339
     340        const char* s;
     341        if (!this->terminalWidth_ && (s = getenv("COLUMNS")))
     342            this->terminalWidth_  = strtol(s, NULL, 10);
     343        if (!this->terminalWidth_)
     344            this->terminalWidth_ = 80;
     345        if (!this->terminalHeight_ && (s = getenv("LINES")))
     346            this->terminalHeight_ = strtol(s, NULL, 10);
     347        if (!this->terminalHeight_)
     348            this->terminalHeight_ = 24;
    346349    }
    347350
Note: See TracChangeset for help on using the changeset viewer.