ncurses basics
authorDaniel Liu <mr.picklepinosaur@gmail.com>
Thu, 3 Dec 2020 01:51:11 +0000 (20:51 -0500)
committerDaniel Liu <mr.picklepinosaur@gmail.com>
Thu, 3 Dec 2020 01:51:11 +0000 (20:51 -0500)
.gitignore [new file with mode: 0644]
main.cpp [new file with mode: 0644]
makefile [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..ba2906d
--- /dev/null
@@ -0,0 +1 @@
+main
diff --git a/main.cpp b/main.cpp
new file mode 100644 (file)
index 0000000..7757262
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,53 @@
+#include <ncurses.h>
+using namespace std;
+
+int main(int argc, char ** argv) {
+    
+    initscr();
+    cbreak();
+    /* raw(); */
+    noecho();
+    
+    WINDOW * win = newwin(10,20,10,10); 
+    
+    refresh();
+    
+    int x, y;
+    x = y = 0;
+
+    while (true) {
+        int ch = getch();
+        
+        //ofc the first thing we need is vim keys 
+        switch (ch) {
+            case 104: // h
+                x -= 1;
+                break;
+            case 106: // j
+                y += 1;
+                break;
+            case 107: // k
+                y -= 1;
+                break;
+            case 108: // l
+                x += 1;
+                break;
+        } 
+        if (ch == 113) break; // q for quit
+
+        move(y,x);
+
+        box(win, 0, 0);
+        mvwprintw(win, 0, 1, "lmao");
+        wrefresh(win);
+
+        refresh();
+        /* clear(); */
+    }
+
+    endwin();
+
+    return 0;
+}
+
+
diff --git a/makefile b/makefile
new file mode 100644 (file)
index 0000000..81646c7
--- /dev/null
+++ b/makefile
@@ -0,0 +1,9 @@
+CC=g++
+
+make: main
+
+main:
+       $(CC) -lncurses main.cpp -o main
+
+clean:
+       rm main