acid-drop

- Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.acid.vegas/-c.git
Log | Files | Refs | Archive | README | LICENSE

commit e721ac125c922466c394f73b455149fddfacb504
parent 99e19c29c3d4d03006a51e383a4aaa995fb71f5d
Author: acidvegas <acid.vegas@acid.vegas>
Date: Sun, 26 May 2024 20:11:57 -0400

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

Diffstat:
Msrc/main.ino | 26++++++++++++++++++++++++--

1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/main.ino b/src/main.ino
@@ -173,15 +173,38 @@ int renderFormattedMessage(String message, int cursorY, int lineHeight, bool hig
                     cursorY += lineHeight;
                     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
     return cursorY; // Return the new cursor Y position for the next line
 }
 
+
 void turnOffScreen() {
     Serial.println("Screen turned off");
     tft.writecommand(TFT_DISPOFF); // Turn off display
@@ -432,7 +455,6 @@ void sendIRC(String command) {
 void handleIRC() {
     while (client.available()) {
         String line = client.readStringUntil('\n');
-        line.trim();
         Serial.println("IRC: " + line);
 
         int firstSpace = line.indexOf(' ');