Skip to content

Commit

Permalink
Refactor cursor handling in appendCursorToText function
Browse files Browse the repository at this point in the history
- Refactored the condition check for cursor icons
- Replaced strncpy with memcpy for buffer copying
  • Loading branch information
forntoh committed Oct 8, 2024
1 parent 09032c4 commit 8bbfa32
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/renderer/CharacterDisplayRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ void CharacterDisplayRenderer::moveCursor(uint8_t cursorCol, uint8_t cursorRow)
}

void CharacterDisplayRenderer::appendCursorToText(const char* text, char* buf) {
if (cursorIcon == 0 && editCursorIcon == 0) {
strncpy(buf, text, maxCols + viewShift);
bool noCursorIcon = (cursorIcon == 0 && editCursorIcon == 0);
if (noCursorIcon) {
memcpy(buf, text, maxCols + viewShift);
return;
}

uint8_t cursor = hasFocus ? (inEditMode ? editCursorIcon : cursorIcon) : ' ';
buf[0] = cursor;
strncpy(buf + 1, text, maxCols + viewShift - 1);
memcpy(buf + 1, text, maxCols + viewShift - 1);
}

void CharacterDisplayRenderer::appendIndicatorToText(const char* text, char* buf) {
Expand Down

0 comments on commit 8bbfa32

Please sign in to comment.