mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-08 14:31:06 +00:00
strwidth: Initial commit
This commit is contained in:
parent
0781421762
commit
d2c90d70dc
34
gen/strwidth.c
Normal file
34
gen/strwidth.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
||||
#include "fonts.h"
|
||||
|
||||
static inline char convert(char c) {
|
||||
if (c < 0x80) {
|
||||
return c;
|
||||
} else if (c >= 0xC0) {
|
||||
return '_';
|
||||
} else {
|
||||
return '\0';
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char *line;
|
||||
while ((line = readline(NULL)) != NULL) {
|
||||
size_t length = strlen(line);
|
||||
if (length) {
|
||||
add_history(line);
|
||||
}
|
||||
|
||||
size_t width = 0;
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
width += fontCharWidth(convert(line[i])) + 1;
|
||||
}
|
||||
|
||||
printf("%zu\n", width);
|
||||
free(line);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user