Handle trimming of unicode characters properly

This commit is contained in:
Utkarsh Verma 2021-12-30 10:44:06 +05:30
parent 6d762615dd
commit 172a239edb
No known key found for this signature in database
GPG Key ID: 817656CF818EFCCC
2 changed files with 12 additions and 7 deletions

View File

@ -1,16 +1,16 @@
#define CMDLENGTH 50
#define DELIMITER "<"
#define LEADING_DELIMITER
#define CMDLENGTH 60
#define DELIMITER " "
#define CLICKABLE_BLOCKS
const Block blocks[] = {
BLOCK("sb-mail", 1800, 17)
BLOCK("sb-music", 0, 18)
BLOCK("sb-disk", 1800, 19)
BLOCK("sb-memory", 1800, 20)
BLOCK("sb-loadavg", 1800, 21)
BLOCK("sb-memory", 10, 20)
BLOCK("sb-loadavg", 5, 21)
BLOCK("sb-mic", 0, 26)
BLOCK("sb-volume", 0, 22)
BLOCK("sb-battery", 5, 23)
BLOCK("sb-date", 1, 24)
BLOCK("sb-network", 5, 25)
// BLOCK("sb-network", 5, 25)
};

7
main.c
View File

@ -94,7 +94,12 @@ void updateBlock(int i) {
char* output = outputs[i];
char buffer[LEN(outputs[0])];
int bytesRead = read(pipes[i][0], buffer, LEN(buffer));
buffer[bytesRead - 1] = '\0';
// Trim UTF-8 characters properly
int j = bytesRead - 1;
while ((buffer[j] & 0b11000000) == 0x80)
j--;
buffer[j] = '\0';
if (bytesRead == LEN(buffer)) {
// Clear the pipe