fissh

termios terminal aquarium. demo at ssh://fish@kloet.net
Download | Log | Files | Refs

commit 6976525c1fdb46b0bc6e3031ae29d759bed3654c
parent fdd66522e9f9b3a50e22b8e42ffbf71c183fcbbf
Author: amrfti <andrew@kloet.net>
Date:   Sat, 12 Jul 2025 09:12:08 -0400

only move cursor when needed

Diffstat:
Msrc/Aquarium.cpp | 35+++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/Aquarium.cpp b/src/Aquarium.cpp @@ -280,35 +280,38 @@ void Aquarium::initColorLookup() { void Aquarium::renderToScreen() { static std::string output; output.clear(); - output.reserve(height * width * 20); // Reserve space for efficiency + output.reserve(height * width * 20); + + int cursor_y = -1, cursor_x = -1; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { const Cell &newCell = currentFrame[y][x]; Cell &oldCell = previousFrame[y][x]; - if (newCell != oldCell) { - oldCell = newCell; + if (newCell == oldCell) + continue; - // Move cursor to position - output += ANSI::moveTo(y, x); + oldCell = newCell; - // Reset cell - output += ANSI::RESET_BLACK_BG; + // Move cursor only when needed + if (cursor_y != y || cursor_x != x) { + output += ANSI::moveTo(y, x); + cursor_y = y; + cursor_x = x; + } - // Set color and attributes - if (newCell.bold) { - output += ANSI::BOLD; - } - output += colorLookup[static_cast<unsigned char>(newCell.colorChar)]; + // Apply cell formatting and character + output += ANSI::RESET_BLACK_BG; + if (newCell.bold) + output += ANSI::BOLD; + output += colorLookup[static_cast<unsigned char>(newCell.colorChar)]; + output += newCell.ch; - // Add the character - output += newCell.ch; - } + ++cursor_x; } } - // Output everything at once if (!output.empty()) { std::cout << output << std::flush; }