Declined Tab width in Win 10

May 20, 2008
11,378
98
Syracuse, NY, USA
Windows 10's enhanced console supports setting tab positions. It's a bit cumbersome. Maybe the next TCC will wrap up a few simple tab-setting/clearing actions into a command. Here's a bit of fooling around with Win 10's ANSI. I don't know if there are console API functions to do this sort of thing.
2279
 
May 20, 2008
11,378
98
Syracuse, NY, USA
FWIW, Here's a TABWIDTH.BTM.
Code:
set width=%1
echos ^e[1G^e[s^e[3g
do i=1 to %@eval[%_columns\%width]
        echos ^eH%@repeat[%@char[160],%width]
enddo
echos ^eH^e[u

and a plugin version (not exactly the same).
Code:
INT WINAPI TABWIDTH(LPWSTR psz)
{
    DWORD w = wcstoul(psz, NULL, 10);
    if (w < 2 || wcsstr(psz, L"/?"))
    {
        Printf(L"%s\r\n", item[itabwidth].Help);
        return 0;
    }
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
    COORD dwCursor = { 0, csbi.dwCursorPosition.Y };
    // cursor to BOL, save cursor position, clear tabs (except at BOL and EOL)
    Printf(L"\x1b[G\x1b[s\x1b[3g"); 
    for (dwCursor.X = 0; dwCursor.X < csbi.dwSize.X; dwCursor.X += w)
    {
        SetConsoleCursorPosition(STD_OUT, dwCursor);
        Printf(L"\x1bH"); // set a tab position
    }
    Printf(L"\x1b[u"); // restore cursor position.
    return 0;
}

They're crude, but either will produce this in my Win 10 enhanced console.

2284
 
May 20, 2008
11,378
98
Syracuse, NY, USA
Here's more functionality and plugin code that does it.
2287


Code:
INT WINAPI TABSAT(LPWSTR psz)
{
    INT argc;
    WCHAR szUty[16], **argv = GetArgs(psz, &argc); // CommandLineToArgvW with dummy argv[0]
    DWORD dwWritten;
    WORD wWidth = 0;
    BOOL bUseWidth;

    if ( argc < 3 || !(bUseWidth = !lstrcmpi(argv[1], L"/w")) && lstrcmpi(argv[1], L"/c") || !(wWidth = (WORD) _wtoi(argv[2])) )
    {
        Printf(L"%s\r\n", item[itabsat].Help);
        goto byebye;
    }

    HANDLE hConOut = OpenConOut(); // L"CONOUT$"
    // cursor to BOL, save cursor position, clear tabs (except at BOL and EOL)
    WriteConsole(hConOut, L"\x1b[G\x1b[s\x1b[3g", 10, &dwWritten, NULL);

    if ( bUseWidth ) /* use tab width */
    {
        CONSOLE_SCREEN_BUFFER_INFO csbi;
        GetConsoleScreenBufferInfo(hConOut, &csbi);
        wsprintf(szUty, L"\x1b[%uC\x1bH", wWidth);  // cursor forward w columns and set tab
        for (WORD i = 1; i <= csbi.dwSize.X / wWidth; i += 1)
            WriteConsole(hConOut, szUty, lstrlen(szUty), &dwWritten, NULL);
    }
    else /* use specified columns */
    {
        for (INT i = 2; i < argc; i++)
        {
            wsprintf(szUty, L"\x1b[%uG\x1bH", (WORD)_wtoi(argv[i])); // cursor to named column and set tab
            WriteConsole(hConOut, szUty, lstrlen(szUty), &dwWritten, NULL);
        }
    }

    /* restore cursor position */
    WriteConsole(hConOut, L"\x1b[u", 3, &dwWritten, NULL);

    CloseHandle(hConOut);
    byebye :
    LocalFree(argv);
    return 0;
}
 
May 20, 2008
11,378
98
Syracuse, NY, USA
While that's all fine and dandy, I just discovered that such settings only last until another EXE is run in the same console (including another TCC, say in a pipe). When that happens, the tabs revert to the default every 8 characters and they stay there ... bummer!

In fact the tabs settings revert if I run notepad, but not if I START notepad (see below). Does anyone know what might be happening?
2289
 
Similar threads
Thread starter Title Forum Replies Date
Joe Caverly Launch TCC Tab with different date/time Suggestions 0
D Suggestion: VIEW option to open VIEW over tab window but not keep it there Suggestions 0
D Suggestion: Tab or button to open new tab window in horizontal group Suggestions 1
R Run new tab as Suggestions 2
Joe Caverly Tab From Batch Arguments text box Suggestions 0
A Done Put 'Open containing folder' on IDE tab for a specific document in the editor Suggestions 0
Phileosophos Save and restore tab layouts Suggestions 0
rconn In the Help tab let the user add links either to files or web pages, with an icon & label. Suggestions 0
ehab aboudaya Done Shortcut Key to switch between current active tab & command input Suggestions 0
nickles Done Make [tab] work in paths containing a %var Suggestions 3
R Done Smarter Tab Completion Suggestions 1
C TC drop-zone to add a tab Suggestions 0
C Done hover time when dragging over a tab Suggestions 5
C Declined command input separate for each tab Suggestions 6
J Done Active tab Suggestions 0
K Done Alt-Enter to toggle 'full-frame' mode for console tab in TakeCmd Suggestions 1
Charles Dye Done Startup Tabs / Tab Toolbar suggestion Suggestions 1
fishman@panix.com Declined Make it work with a new Win 10 build!!! Suggestions 1
R Interact with Win 10 ver 1809 Clipboard history Suggestions 1
R Tie-in to Win 10 x64's WSL Windows Subsystem for Linux Suggestions 76
Alpengreis Done Optional ANSI(32|64).dll for Win 10 >= Creators Update Suggestions 5
G Declined make tcc being more "4dos" and win x64 faster Suggestions 7
S Declined MONITOR commands; several @WIN...[] functions Suggestions 2

Similar threads