Skip to content

Commit

Permalink
Logo (image-raw): better Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Sep 4, 2024
1 parent 3f67fac commit cf7c5d3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/logo/logo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -51,15 +51,20 @@ 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)
fprintf(stderr, "\nLogo (image-raw): fail to query cursor position: %s\n", error);
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);
}
Expand Down

0 comments on commit cf7c5d3

Please sign in to comment.