Calculate values in GetViewIntoMessageBuffer properly #12

Closed
opened 2023-01-22 20:33:36 +01:00 by zotan · 0 comments
Owner

Code in question:

Lines 395 to 404 in 8267890
var finalMessage = message[(bufferWidth - wraparoundOffsetPreW - wraparoundOffsetPost)..];
var finalCursorPos = absoluteCursorPosition - bufferWidth + wraparoundOffsetPreW + wraparoundOffsetPostW;
// successive wraps
// repeat above steps (but respective of the new < character) until the string fits into the buffer
// it fits into the buffer when cursorPos >= bufferwidth minus wraparound (this time respecting > character absent on first wrap)
while (finalCursorPos >= bufferWidth - wraparoundOffsetPreW) {
finalMessage = finalMessage[(bufferWidth - wraparoundOffsetPreW - wraparoundOffsetPostW)..];
finalCursorPos = finalCursorPos - bufferWidth + wraparoundOffsetPreW + wraparoundOffsetPostW;
}

This can possibly be implemented in a nicer way, replacing that while loop (and possibly even the first wrap calculation) with a modulo operation.

Code in question: https://git.ztn.sh/zotan/tgcli/src/commit/82678907ba73d0682ac18c98f5fd3a19164fcde5/tgcli/Util.cs#L395-L404 This can possibly be implemented in a nicer way, replacing that while loop (and possibly even the first wrap calculation) with a modulo operation.
zotan closed this issue 2023-01-23 12:02:51 +01:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: zotan/tgcli#12
No description provided.