From fe910b6e31e2b2c7ffc71b16dbed23ca6fbb4272 Mon Sep 17 00:00:00 2001 From: Mazar Farran Date: Tue, 18 Aug 2015 19:03:55 -0700 Subject: [PATCH] Old bug fixes that I never commited. Also added a .gitignore and modified the readme. --- .gitignore | 4 ++++ README.md | 18 +++++++++++++++++- makefile | 15 +++++++++------ page.c | 6 ++++++ text.c | 13 +++++++++++-- 5 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..31ee6fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.out +*.o +*.txt +text diff --git a/README.md b/README.md index f1cf96f..d93e82a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,23 @@ Text Editor =========== I learned ncurses and figured why not. -Posting this now (9/30) because school is starting +Posting this now (9/30/15) because school is starting so I don't plan on working on it anymore. Probably the most well-developed program I made this summer. + +How to use: + +F4 quits (no prompt) +F5 saves the current file as save.txt + +Current issues: + +x-y coordinates in ncurses correspond to rows and columns in +the text document. This means tabs are an issue and text +wrapping is impossible. Solution: separate screen logic +from document logic. + +Can only save files under the name save.txt. Solution: create +a prompt window (from scratch...) that retuns a string to the +caller. diff --git a/makefile b/makefile index 40ddb4d..32ad88f 100644 --- a/makefile +++ b/makefile @@ -2,17 +2,20 @@ CC=gcc CFLAGS=-Wall -g -OBJS=line.o page.o +OBJS=text.o page.o line.o LIBS=-lncurses -text: text.c text.h $(OBJS) - $(CC) $(CFLAGS) -o text text.c $(OBJS) $(LIBS) - -line.o: line.c line.h - $(CC) $(CFLAGS) -c line.c +text: $(OBJS) + $(CC) $(CFLAGS) -o text $(OBJS) $(LIBS) + +text.o: text.c text.h page.h line.h + $(CC) $(CFLAGS) -c text.c page.o: page.c page.h line.h $(CC) $(CFLAGS) -c page.c +line.o: line.c line.h + $(CC) $(CFLAGS) -c line.c + clean: rm -f $(OBJS) text diff --git a/page.c b/page.c index bd677e6..6fac2c1 100644 --- a/page.c +++ b/page.c @@ -85,6 +85,12 @@ void print_page(const PAGE *p, int start, int end) clrtoeol(); printw(" %s", p->text[i].line); } + if(start < end) + { + move(line, 0); + clrtoeol(); // if we deleted a line this may be necessary + move(line-1, 1); + } refresh(); } // print_page diff --git a/text.c b/text.c index 843bec1..68fc15b 100644 --- a/text.c +++ b/text.c @@ -9,6 +9,7 @@ **/ int y_offset = 0; // TODO: move to local scope +int tab_offset = 0; #define DEBUG @@ -143,7 +144,14 @@ void move_left(int *x, int *y) void move_right(PAGE *p, int *x, int *y) { - if(*x <= strlen(p->text[*y + y_offset].line)) move(*y, ++(*x)); + if(*x <= strlen(p->text[*y + y_offset].line)) + { + if(p->text[*y + y_offset].line[*x + tab_offset] == '\t') { + move(*y, ++(*x)); + } else { + move(*y, ++(*x)); + } + } } void move_up(PAGE *p, int *x, int *y) @@ -187,7 +195,8 @@ int count_lines(int argc, char **argv) while((ch = fgetc(fp)) != EOF) if( ch == '\n' ) count++; - + + fclose(fp); return count; } // count_lines