Ultradefrag displays output differently on conhost and windows terminal. #20333

Closed
opened 2026-01-31 07:10:38 +00:00 by claunia · 5 comments
Owner

Originally created by @kotenok2000 on GitHub (Aug 4, 2023).

Windows Terminal version

1.17.11461.0

Windows build number

[Version 10.0.22621.1992]

Other Software

Ultradefrag https://sourceforge.net/projects/ultradefrag/files/stable-release/7.1.4

Steps to reproduce

Install Ultradefrag.
Run udefrag -a --all -v -m in windows terminal

Expected Behavior

https://github.com/microsoft/terminal/assets/8822292/fd62f580-67dd-4b13-a96c-58cf75350476

Actual Behavior

https://github.com/microsoft/terminal/assets/8822292/ac2a9c7c-aade-467d-9137-05c2cbafa6f9

Originally created by @kotenok2000 on GitHub (Aug 4, 2023). ### Windows Terminal version 1.17.11461.0 ### Windows build number [Version 10.0.22621.1992] ### Other Software Ultradefrag https://sourceforge.net/projects/ultradefrag/files/stable-release/7.1.4 ### Steps to reproduce Install Ultradefrag. Run udefrag -a --all -v -m in windows terminal ### Expected Behavior https://github.com/microsoft/terminal/assets/8822292/fd62f580-67dd-4b13-a96c-58cf75350476 ### Actual Behavior https://github.com/microsoft/terminal/assets/8822292/ac2a9c7c-aade-467d-9137-05c2cbafa6f9
Author
Owner

@zadjii-msft commented on GitHub (Aug 4, 2023):

1.11??? That's a super old version. Can you try a newer Terminal version/?

@zadjii-msft commented on GitHub (Aug 4, 2023): **1.11**??? That's a super old version. Can you try a newer Terminal version/?
Author
Owner

@kotenok2000 commented on GitHub (Aug 4, 2023):

I mistyped. It is actually 1.17

@kotenok2000 commented on GitHub (Aug 4, 2023): I mistyped. It is actually 1.17
Author
Owner

@zadjii-msft commented on GitHub (Aug 23, 2023):

Theories:

  • Maybe this is busted because of Terminal defaulting to ENABLE_VIRTUAL_TERMINAL_PROCESSING?
  • Maybe this is busted because of SetConsoleScreenBufferInfo wackiness in conpty mode
@zadjii-msft commented on GitHub (Aug 23, 2023): Theories: * Maybe this is busted because of Terminal defaulting to ENABLE_VIRTUAL_TERMINAL_PROCESSING? * Maybe this is busted because of `SetConsoleScreenBufferInfo` wackiness in conpty mode
Author
Owner

@j4james commented on GitHub (Aug 24, 2023):

Maybe this is busted because of Terminal defaulting to ENABLE_VIRTUAL_TERMINAL_PROCESSING?

I believe it's this. ☝️

When redrawing the progress line, they clear it first with a function that looks like this:

void clear_line(void)
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    if(!GetConsoleScreenBufferInfo(g_out,&csbi))
        return; /* impossible to determine the screen width */
    int n = (int)csbi.dwSize.X;

    char *line = new char[n + 1];
    memset(line,0x20,n);
    line[n] = 0;
    fprintf(stdout,"\r%s",line);
    delete [] line;

    /* move cursor back to the previous line */
    if(GetConsoleScreenBufferInfo(g_out,&csbi)){
        COORD pos; pos.X = 0;
        pos.Y = csbi.dwCursorPosition.Y - 1;
        (void)SetConsoleCursorPosition(g_out,pos);
    }
}

What that's doing is writing out a bunch of spaces to cover the width of the buffer. On the legacy console that would end up with the cursor position wrapping onto the next line. So they follow that up with a call to SetConsoleCursorPosition to move the cursor back up a line.

When in VT mode, though, we have "delayed EOL wrap", so writing out something the exact with of the buffer does not wrap onto the next line. So their attempt to correct the cursor position actually ends up placing it a line higher than it was intended to be.

@j4james commented on GitHub (Aug 24, 2023): > Maybe this is busted because of Terminal defaulting to ENABLE_VIRTUAL_TERMINAL_PROCESSING? I believe it's this. ☝️ When redrawing the progress line, they clear it first with a function that looks like this: ```c void clear_line(void) { CONSOLE_SCREEN_BUFFER_INFO csbi; if(!GetConsoleScreenBufferInfo(g_out,&csbi)) return; /* impossible to determine the screen width */ int n = (int)csbi.dwSize.X; char *line = new char[n + 1]; memset(line,0x20,n); line[n] = 0; fprintf(stdout,"\r%s",line); delete [] line; /* move cursor back to the previous line */ if(GetConsoleScreenBufferInfo(g_out,&csbi)){ COORD pos; pos.X = 0; pos.Y = csbi.dwCursorPosition.Y - 1; (void)SetConsoleCursorPosition(g_out,pos); } } ``` What that's doing is writing out a bunch of spaces to cover the width of the buffer. On the legacy console that would end up with the cursor position wrapping onto the next line. So they follow that up with a call to `SetConsoleCursorPosition` to move the cursor back up a line. When in VT mode, though, we have "delayed EOL wrap", so writing out something the exact with of the buffer does _not_ wrap onto the next line. So their attempt to correct the cursor position actually ends up placing it a line higher than it was intended to be.
Author
Owner

@zadjii-msft commented on GitHub (Aug 24, 2023):

Well, that's a fantastic investigation! I guess this is something that's different between Terminal and conhost, sure. I'd make the call though that this is a bug in ultradefrag - they should make sure to set the console modes to exactly what they expect to work.

@kotenok2000 You should probably file this upstream at https://sourceforge.net/p/ultradefrag/bugs/

Thanks!

@zadjii-msft commented on GitHub (Aug 24, 2023): Well, that's a fantastic investigation! I guess this is something that's different between Terminal and conhost, sure. I'd make the call though that this is a bug in ultradefrag - they should make sure to set the console modes to exactly what they expect to work. @kotenok2000 You should probably file this upstream at https://sourceforge.net/p/ultradefrag/bugs/ Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20333