fixed tab handling + made things look nicer

master
bx 2022-04-02 15:46:23 +00:00
parent 849b4139df
commit 5ed3ab8aa6
3 changed files with 24 additions and 3 deletions

View File

@ -1,11 +1,26 @@
void
print_with_fixed_tabs(Row *row) {
for (int i = 0; i < ROW_SIZE; i++) {
if(row->text[i] == 0) break;
if (row->text[i] == '\t') printf(" ");
else printf("%c", row->text[i]);
}
}
void void
c_print(char *c) { c_print(char *c) {
Row *row = buffer; Row *row = buffer;
int line = 1; int line = 1;
for (;; line++) { for (;; line++) {
printf("%4.4i| %s\n", line, row->text); printf("%3.i| ", line);
print_with_fixed_tabs(row);
puts("");
if (row->n == NULL) break; if (row->n == NULL) break;
row = row -> n; row = row -> n;
} }
} }

View File

@ -1 +1,4 @@
#define ROW_SIZE 100 #define ROW_SIZE 100
#define COM_BUF_SIZE 256

7
main.c
View File

@ -1,8 +1,9 @@
int int
main(int argc, char **argv) { main(int argc, char **argv) {
static char buf[256]; static char buf[COM_BUF_SIZE];
while(1) { while(1) {
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
printf(" > ");
char *com = fgets(buf, sizeof(buf), stdin); char *com = fgets(buf, sizeof(buf), stdin);
for (int i = 0; i < sizeof(buf); i++) for (int i = 0; i < sizeof(buf); i++)
if (buf[i] == '\n') if (buf[i] == '\n')
@ -15,3 +16,5 @@ char *com = fgets(buf, sizeof(buf), stdin);
return 0; return 0;
} }