Skip to content

Commit

Permalink
Now moves cursor vertically for sixel newlines even if there is no si…
Browse files Browse the repository at this point in the history
…xel data
  • Loading branch information
Utkarsh-khambra committed Sep 20, 2022
1 parent 2caa86f commit 380d4fc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<description>
<ul>
<li>Fixes a problem with oversized glyphs being wrongly cut off (#821).</li>
<li>Fixes vertical cursor movement for sixel graphics with only newlines (#822)</li>
</ul>
</description>
</release>
Expand Down
4 changes: 2 additions & 2 deletions src/terminal/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ void Screen<Cell>::renderImage(shared_ptr<Image const> _image,
cell.setImageFragment(rasterizedImage, CellLocation { offset.line, offset.column });
cell.setHyperlink(_state.cursor.hyperlink);
};
moveCursorTo(_topLeft.line + unbox<int>(linesToBeRendered) - 1, _topLeft.column);
moveCursorTo(_topLeft.line + unbox<int>(linesToBeRendered), _topLeft.column);
}

// If there're lines to be rendered missing (because it didn't fit onto the screen just yet)
Expand All @@ -1667,7 +1667,7 @@ void Screen<Cell>::renderImage(shared_ptr<Image const> _image,
}
}
// move ansi text cursor to position of the sixel cursor
moveCursorToColumn(_topLeft.column + _gridSize.columns.as<ColumnOffset>());
moveCursorToColumn(_topLeft.column);
}

template <typename Cell>
Expand Down
6 changes: 3 additions & 3 deletions src/terminal/Screen_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3372,8 +3372,8 @@ TEST_CASE("Sixel.simple", "[screen]")

mock.writeToScreen(sixelData);

CHECK(mock.terminal.primaryScreen().cursor().position.column == ColumnOffset(8));
CHECK(mock.terminal.primaryScreen().cursor().position.line == LineOffset(4));
CHECK(mock.terminal.primaryScreen().cursor().position.column == ColumnOffset(0));
CHECK(mock.terminal.primaryScreen().cursor().position.line == LineOffset(5));

for (auto line = LineOffset(0); line < boxed_cast<LineOffset>(pageSize.lines); ++line)
{
Expand Down Expand Up @@ -3410,7 +3410,7 @@ TEST_CASE("Sixel.AutoScroll-1", "[screen]")

mock.writeToScreen(sixelData);

CHECK(mock.terminal.primaryScreen().cursor().position.column == ColumnOffset(8));
CHECK(mock.terminal.primaryScreen().cursor().position.column == ColumnOffset(0));
CHECK(mock.terminal.primaryScreen().cursor().position.line == LineOffset(3));

for (auto line = LineOffset(-1); line < boxed_cast<LineOffset>(pageSize.lines); ++line)
Expand Down
9 changes: 7 additions & 2 deletions src/terminal/SixelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ void SixelImageBuilder::rewind()
void SixelImageBuilder::newline()
{
sixelCursor_.column = {};

if (unbox<int>(sixelCursor_.line) + 6 < unbox<int>(maxSize_.height))
if (unbox<int>(sixelCursor_.line) + 6 < unbox<int>(explicitSize_ ? size_.height : maxSize_.height))
sixelCursor_.line.value += 6;
}

Expand Down Expand Up @@ -477,6 +476,12 @@ void SixelImageBuilder::render(int8_t _sixel)

void SixelImageBuilder::finalize()
{
if (unbox<int>(size_.height) == 1)
{
size_.height = Height::cast_from(sixelCursor_.line.value);
buffer_.resize(size_.area() * 4);
return;
}
if (!explicitSize_)
{
Buffer tempBuffer(static_cast<size_t>(size_.height.value * size_.width.value) * 4);
Expand Down
14 changes: 14 additions & 0 deletions src/terminal/SixelParser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,17 @@ TEST_CASE("SixelParser.newline", "[sixel]")
}
}
}

TEST_CASE("SixelParser.vertical_cursor_advance", "[sixel]")
{
auto constexpr defaultColor = RGBAColor { 0, 0, 0, 255 };
SixelImageBuilder ib(
{ Width(5), Height { 30 } }, 1, 1, defaultColor, std::make_shared<SixelColorPalette>(16, 256));
auto sp = SixelParser { ib };

sp.parseFragment("$-$-$-$-");
sp.done();

REQUIRE(ib.size() == terminal::ImageSize { Width(1), Height(24) });
REQUIRE(ib.sixelCursor() == CellLocation { LineOffset(24), ColumnOffset { 0 } });
}

0 comments on commit 380d4fc

Please sign in to comment.