mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-21 11:31:41 +00:00
Fixed console rendering crash on wide consoles
This commit is contained in:
parent
102c467de5
commit
429d402dc4
1 changed files with 5 additions and 4 deletions
|
@ -218,20 +218,21 @@ void RedrawProgressBar(int CurPos, int MaxPos)
|
|||
CleanProgressBar();
|
||||
struct winsize sizeOfWindow;
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &sizeOfWindow);
|
||||
int windowColClamped = std::min((int)sizeOfWindow.ws_col, 512);
|
||||
double progVal = std::clamp((double)CurPos / (double)MaxPos,0.0,1.0);
|
||||
int curProgVal = std::clamp(int(sizeOfWindow.ws_col * progVal),0,(int)sizeOfWindow.ws_col);
|
||||
int curProgVal = std::clamp(int(windowColClamped * progVal),0,windowColClamped);
|
||||
|
||||
char progressBuffer[512];
|
||||
memset(progressBuffer,'.',512);
|
||||
progressBuffer[sizeOfWindow.ws_col - 1] = 0;
|
||||
progressBuffer[windowColClamped - 1] = 0;
|
||||
int lengthOfStr = 0;
|
||||
|
||||
while (curProgVal-- > 0)
|
||||
{
|
||||
progressBuffer[lengthOfStr++] = '=';
|
||||
if (lengthOfStr >= sizeOfWindow.ws_col - 1) break;
|
||||
if (lengthOfStr >= windowColClamped - 1) break;
|
||||
}
|
||||
fprintf(stdout, "\0337\033[%d;%dH\033[2K[%s\033[%d;%dH]\0338", sizeOfWindow.ws_row, 0, progressBuffer, sizeOfWindow.ws_row, sizeOfWindow.ws_col);
|
||||
fprintf(stdout, "\0337\033[%d;%dH\033[2K[%s\033[%d;%dH]\0338", sizeOfWindow.ws_row, 0, progressBuffer, sizeOfWindow.ws_row, windowColClamped);
|
||||
fflush(stdout);
|
||||
ProgressBarCurPos = CurPos;
|
||||
ProgressBarMaxPos = MaxPos;
|
||||
|
|
Loading…
Reference in a new issue