2019-04-18 14:27:27 +00:00
|
|
|
#include <readline/history.h>
|
|
|
|
#include <readline/readline.h>
|
2017-07-16 17:43:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "fonts.h"
|
|
|
|
|
|
|
|
static inline char convert(char c) {
|
2019-04-18 14:27:27 +00:00
|
|
|
if (c < 0x80) {
|
|
|
|
return c;
|
|
|
|
} else if (c >= 0xC0) {
|
2020-07-16 13:16:19 +00:00
|
|
|
return 0x7f;
|
2019-04-18 14:27:27 +00:00
|
|
|
} else {
|
|
|
|
return '\0';
|
|
|
|
}
|
2017-07-16 17:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2019-09-30 15:34:38 +00:00
|
|
|
char *line = NULL;
|
2019-04-18 14:27:27 +00:00
|
|
|
int font = FONT_STANDARD;
|
|
|
|
while ((line = readline(NULL)) != NULL) {
|
|
|
|
size_t length = strlen(line);
|
|
|
|
if (length) {
|
|
|
|
add_history(line);
|
|
|
|
}
|
2017-07-16 17:43:58 +00:00
|
|
|
|
2019-04-18 14:27:27 +00:00
|
|
|
size_t width = 0;
|
|
|
|
for (size_t i = 0; i < length; i++) {
|
|
|
|
width += fontCharWidth(font, convert(line[i])) + 1;
|
|
|
|
}
|
2017-07-16 17:43:58 +00:00
|
|
|
|
2019-04-18 14:27:27 +00:00
|
|
|
printf("%zu\n", width);
|
|
|
|
free(line);
|
|
|
|
}
|
2017-07-16 17:43:58 +00:00
|
|
|
}
|