about summary refs log tree commit diff stats
path: root/cpp/070display
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-20 17:40:25 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-20 17:40:25 -0700
commitec961781d0dd952384d08639b74f4b5a14942259 (patch)
treee5eb6b0814c5d2c4c511db37e4583e70e1ba0b86 /cpp/070display
parent12d73ee8db0f6748fabf65f4d0789c79f76c8d1f (diff)
downloadmu-ec961781d0dd952384d08639b74f4b5a14942259.tar.gz
1115 - another pass at names: console and display
(Follow-up to 544.)
Diffstat (limited to 'cpp/070display')
-rw-r--r--cpp/070display102
1 files changed, 102 insertions, 0 deletions
diff --git a/cpp/070display b/cpp/070display
new file mode 100644
index 00000000..a64aa550
--- /dev/null
+++ b/cpp/070display
@@ -0,0 +1,102 @@
+//: Text-mode cursor primitives. Currently thin wrappers around ncurses calls.
+//: Mu starts out at the 'console' where lines wrap and scrolling is
+//: automatic, where keys aren't read until pressing <enter>.
+//: This file provides mechanisms for opening a 'display' and taking raw
+//: charge of the cursor and keyboard.
+
+:(before "End Includes")
+#include<ncurses.h>
+
+//:: Display management
+
+:(before "End Primitive Recipe Declarations")
+SWITCH_TO_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["switch-to-display"] = SWITCH_TO_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case SWITCH_TO_DISPLAY: {
+  initscr();
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+RETURN_TO_CONSOLE,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["return-to-console"] = RETURN_TO_CONSOLE;
+:(before "End Primitive Recipe Implementations")
+case RETURN_TO_CONSOLE: {
+  endwin();
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+CLEAR_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["clear-display"] = CLEAR_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case CLEAR_DISPLAY: {
+  clear();
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+CLEAR_LINE_ON_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["clear-line-on-display"] = CLEAR_LINE_ON_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case CLEAR_LINE_ON_DISPLAY: {
+  clrtoeol();
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+PRINT_CHARACTER_TO_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["print-character-to-display"] = PRINT_CHARACTER_TO_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case PRINT_CHARACTER_TO_DISPLAY: {
+  vector<int> arg = read_memory(instructions[pc].ingredients[0]);
+  addch(arg[0]);
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+CURSOR_POSITION_ON_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["cursor-position-on-display"] = CURSOR_POSITION_ON_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case CURSOR_POSITION_ON_DISPLAY: {
+  size_t cursor_row = 0, cursor_column = 0;
+  getyx(stdscr, cursor_row, cursor_column);
+  vector<int> row;
+  row.push_back(cursor_row);
+  write_memory(instructions[pc].products[0], row);
+  vector<int> column;
+  column.push_back(cursor_column);
+  write_memory(instructions[pc].products[1], column);
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+MOVE_CURSOR_ON_DISPLAY,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["move-cursor-on-display"] = MOVE_CURSOR_ON_DISPLAY;
+:(before "End Primitive Recipe Implementations")
+case MOVE_CURSOR_ON_DISPLAY: {
+  vector<int> row = read_memory(instructions[pc].ingredients[0]);
+  vector<int> column = read_memory(instructions[pc].ingredients[1]);
+  move(row[0], column[0]);
+  break;
+}
+
+//:: Keyboard management
+
+:(before "End Primitive Recipe Declarations")
+WAIT_FOR_KEY_FROM_KEYBOARD,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["wait-for-key-from-keyboard"] = WAIT_FOR_KEY_FROM_KEYBOARD;
+:(before "End Primitive Recipe Implementations")
+case WAIT_FOR_KEY_FROM_KEYBOARD: {
+  getch();
+  break;
+}