VirtualBox

Ignore:
Timestamp:
Sep 22, 2017 4:55:24 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
118092
Message:

VBoxManageHelp.cpp: Use RTStrmQueryTerminalWidth to get the screen width when formatting help text. Fixed bug causing it to not make progress if a word is too long compared to the screen width.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r68485 r68838  
    2424#include <iprt/buildconfig.h>
    2525#include <iprt/ctype.h>
     26#include <iprt/env.h>
    2627#include <iprt/err.h>
    2728#include <iprt/getopt.h>
     
    8687static uint32_t getScreenWidth(PRTSTREAM pStrm)
    8788{
    88     static uint32_t s_acch[2] = { 0, 0};
     89    static uint32_t s_acch[2] = { 0, 0 };
    8990    uint32_t        iWhich    = pStrm == g_pStdErr ? 1 : 0;
    9091    uint32_t        cch       = s_acch[iWhich];
     
    9293        return cch;
    9394
    94     cch = 80; /** @todo screen width IPRT API. */
     95    const char *psz = RTEnvGet("VBOXMANAGE_SCREEN_WIDTH");
     96    if (   !psz
     97        || RTStrToUInt32Full(psz, 0, &cch) != VINF_SUCCESS
     98        || cch == 0)
     99    {
     100        int rc = RTStrmQueryTerminalWidth(pStrm, &cch);
     101        if (rc == VERR_INVALID_FUNCTION)
     102        {
     103            /* It's not a console, but in case we're being piped to less/more/list
     104               we look for a console handle on the other standard output handle
     105               and standard input.  (Latter doesn't work on windows.)  */
     106            rc = RTStrmQueryTerminalWidth(pStrm == g_pStdErr ? g_pStdOut : g_pStdErr, &cch);
     107            if (rc == VERR_INVALID_FUNCTION || rc == VERR_INVALID_HANDLE)
     108                rc = RTStrmQueryTerminalWidth(g_pStdIn, &cch);
     109            if (RT_FAILURE(rc))
     110                cch = 80;
     111        }
     112    }
     113
    95114    s_acch[iWhich] = cch;
    96115    return cch;
     
    155174        {
    156175            RTStrmWrite(pStrm, g_szSpaces, cchIndent + cchHangingIndent);
    157             size_t   offLine       = cchIndent + cchHangingIndent;
    158             bool     fPendingSpace = false;
     176            size_t  offLine       = cchIndent + cchHangingIndent;
     177            bool    fPendingSpace = false;
    159178            do
    160179            {
     
    162181                size_t      cchWord  = pszSpace ? pszSpace - psz : strlen(psz);
    163182                if (   offLine + cchWord + fPendingSpace > cchMaxWidth
    164                     && offLine != cchIndent)
     183                    && offLine != cchIndent
     184                    && fPendingSpace /* don't stop before first word */)
    165185                    break;
    166186
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette