From 3ba9e63e9c4b93f035045c6cfd7b645398d7bda9 Mon Sep 17 00:00:00 2001 From: a bellenir Date: Mon, 4 Jan 2016 16:04:32 -0500 Subject: [PATCH] reorganize functions --- source/main.c | 123 ++++++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 58 deletions(-) diff --git a/source/main.c b/source/main.c index 4611d01..260f536 100644 --- a/source/main.c +++ b/source/main.c @@ -43,8 +43,13 @@ static FilePos Loc = { .line = NULL, .offset = 0 }; *****************************************************************************/ static void setup(void); static void load(char* fname); -static void input(int ch); static void edit(void); +static void input(int ch); +static void cursorLeft(void); +static void cursorDown(void); +static void cursorUp(void); +static void cursorRight(void); +static void cursorHome(void); /* Main Routine *****************************************************************************/ @@ -109,6 +114,64 @@ static void load(char* fname) fclose(file); } +static void edit(void) +{ + int ch = 0; + do { + /* Handle input */ + input(ch); + /* Refresh the screen */ + if (ScreenDirty) { + clear(); + Line* line = Curr_File.start; + for (int i = 0; (i < Max.y) && line; i++, line = line->next) { + if (line->length > Loc.offset) { + mvprintw(i, 0, "%s", &(line->text[Loc.offset])); + } + } + refresh(); + ScreenDirty = false; + } + /* Place the cursor */ + move(Curr.y, Curr.x); + } while((ch = getch()) != 'q'); +} + +static void input(int ch) +{ + switch (ch) { + case KEY_LEFT: + case 'h': + cursorLeft(); + break; + + case KEY_DOWN: + case 'j': + cursorDown(); + break; + + case KEY_UP: + case 'k': + cursorUp(); + break; + + case KEY_RIGHT: + case 'l': + cursorRight(); + break; + + case KEY_HOME: + case '0': + cursorHome(); + break; + } + /* Cap the column selection at the end of text on the current line */ + if (Loc.line->length <= 1) + Curr.x = 0; + else if (Curr.x >= (Loc.line->length-1 - Loc.offset)) + Curr.x = (Loc.line->length-2 - Loc.offset); +} + static void cursorLeft() { Curr.x--; @@ -161,7 +224,7 @@ static void cursorRight() } } -static void cursorLineStart() +static void cursorHome() { if(Curr.x != 0){ Curr.x = 0; @@ -169,59 +232,3 @@ static void cursorLineStart() } } -static void input(int ch) -{ - switch (ch) { - case KEY_LEFT: - case 'h': - cursorLeft(); - break; - - case KEY_DOWN: - case 'j': - cursorDown(); - break; - - case KEY_UP: - case 'k': - cursorUp(); - break; - - case KEY_RIGHT: - case 'l': - cursorRight(); - break; - case '0': - cursorLineStart(); - break; - } - /* Cap the column selection at the end of text on the current line */ - if (Loc.line->length <= 1) - Curr.x = 0; - else if (Curr.x >= (Loc.line->length-1 - Loc.offset)) - Curr.x = (Loc.line->length-2 - Loc.offset); -} - -static void edit(void) -{ - int ch = 0; - do { - /* Handle input */ - input(ch); - /* Refresh the screen */ - if (ScreenDirty) { - clear(); - Line* line = Curr_File.start; - for (int i = 0; (i < Max.y) && line; i++, line = line->next) { - if (line->length > Loc.offset) { - mvprintw(i, 0, "%s", &(line->text[Loc.offset])); - } - } - refresh(); - ScreenDirty = false; - } - /* Place the cursor */ - move(Curr.y, Curr.x); - } while((ch = getch()) != 'q'); -} - -- 2.54.0