Improved IRC color handling to allow messages ending with spaces to display colored backgrounds for ASCII/ANSI art :P

This commit is contained in:
Dionysus 2024-05-26 20:11:57 -04:00
parent 99e19c29c3
commit e721ac125c
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE

View File

@ -173,15 +173,38 @@ int renderFormattedMessage(String message, int cursorY, int lineHeight, bool hig
cursorY += lineHeight; cursorY += lineHeight;
tft.setCursor(0, cursorY); tft.setCursor(0, cursorY);
} }
tft.print(c); if (c == ' ') {
// Draw background for spaces
int spaceWidth = tft.textWidth(" ");
tft.fillRect(tft.getCursorX(), tft.getCursorY(), spaceWidth, lineHeight, bgColor);
tft.setCursor(tft.getCursorX() + spaceWidth, tft.getCursorY());
} else {
// Ensure that background color is applied to characters
tft.setTextColor(fgColor, bgColor);
tft.print(c);
}
} }
} }
} }
// Ensure trailing spaces are displayed with background color
if (message.endsWith(" ")) {
int trailingSpaces = 0;
for (int i = message.length() - 1; i >= 0 && message[i] == ' '; i--) {
trailingSpaces++;
}
for (int i = 0; i < trailingSpaces; i++) {
int spaceWidth = tft.textWidth(" ");
tft.fillRect(tft.getCursorX(), tft.getCursorY(), spaceWidth, lineHeight, bgColor);
tft.setCursor(tft.getCursorX() + spaceWidth, tft.getCursorY());
}
}
cursorY += lineHeight; // Add line height after printing the message cursorY += lineHeight; // Add line height after printing the message
return cursorY; // Return the new cursor Y position for the next line return cursorY; // Return the new cursor Y position for the next line
} }
void turnOffScreen() { void turnOffScreen() {
Serial.println("Screen turned off"); Serial.println("Screen turned off");
tft.writecommand(TFT_DISPOFF); // Turn off display tft.writecommand(TFT_DISPOFF); // Turn off display
@ -432,7 +455,6 @@ void sendIRC(String command) {
void handleIRC() { void handleIRC() {
while (client.available()) { while (client.available()) {
String line = client.readStringUntil('\n'); String line = client.readStringUntil('\n');
line.trim();
Serial.println("IRC: " + line); Serial.println("IRC: " + line);
int firstSpace = line.indexOf(' '); int firstSpace = line.indexOf(' ');