]> git.mdlowis.com Git - projs/tide.git/commitdiff
reorganize functions
authora bellenir <a@bellenir.com>
Mon, 4 Jan 2016 21:04:32 +0000 (16:04 -0500)
committera bellenir <a@bellenir.com>
Mon, 4 Jan 2016 21:04:32 +0000 (16:04 -0500)
source/main.c

index 4611d01b381c71410826df6615be42affe5e6df7..260f5365466b176179d1eec7e0af8e6c963d48d1 100644 (file)
@@ -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');
-}
-