Logo (image-raw): better Windows support

This commit is contained in:
李通洲 2024-09-04 10:57:25 +08:00
parent 3f67fac4fa
commit cf7c5d3cfa

View File

@ -40,7 +40,7 @@ static bool ffLogoPrintCharsRaw(const char* data, size_t length, bool printError
if (!options->width)
{
if (printError)
fputs("Logo (iterm): Must set logo width when using position right\n", stderr);
fputs("Logo (image-raw): Must set logo width when using position right\n", stderr);
return false;
}
ffStrbufAppendF(&buf, "\e[2J\e[3J\e[%u;9999999H\e[%uD", (unsigned) options->paddingTop + 1, (unsigned) options->paddingRight + options->width);
@ -51,7 +51,8 @@ static bool ffLogoPrintCharsRaw(const char* data, size_t length, bool printError
if (options->position == FF_LOGO_POSITION_LEFT || options->position == FF_LOGO_POSITION_RIGHT)
{
uint16_t X = 0, Y = 0;
const char* error = ffGetTerminalResponse("\e[6n", "\e[%hu;%huR", &Y, &X);
// Windows Terminal doesn't report `\e` for some reason
const char* error = ffGetTerminalResponse("\e[6n", "%*[^0-9]%hu;%huR", &Y, &X); // %*[^0-9]: ignore optional \e[
if (error)
{
if (printError)
@ -59,7 +60,11 @@ static bool ffLogoPrintCharsRaw(const char* data, size_t length, bool printError
return true;
}
if (options->position == FF_LOGO_POSITION_LEFT)
{
if (options->width + options->paddingLeft > X)
X = (uint16_t) (options->width + options->paddingLeft);
instance.state.logoWidth = X + instance.config.logo.paddingRight - 1;
}
instance.state.logoHeight = Y;
fputs("\e[H", stdout);
}