shithub: orca

Download patch

ref: df3a5b7ecfea7feebfde5a8353b3264996fe3198
parent: 05b552be69cd98d2ee718976f37a0e0d7da452b0
author: cancel <cancel@cancel.fm>
date: Thu Dec 13 18:41:14 EST 2018

Add more controls dialog stuff

--- a/term_util.c
+++ b/term_util.c
@@ -91,6 +91,11 @@
 
 WINDOW* qmsg_window(Qmsg* qm) { return qm->nav_block.content_window; }
 
+void qmsg_set_title(Qmsg* qm, char const* title) {
+  Qnav_block* qb = &qm->nav_block;
+  qnav_draw_title(qb, title);
+}
+
 Qmsg* qmsg_push(int height, int width) {
   Qmsg* qm = malloc(sizeof(Qmsg));
   qnav_stack_push(Qnav_type_qmsg, height, width, &qm->nav_block);
--- a/term_util.h
+++ b/term_util.h
@@ -95,6 +95,7 @@
 
 Qmsg* qmsg_push(int height, int width);
 WINDOW* qmsg_window(Qmsg* qm);
+void qmsg_set_title(Qmsg* qm, char const* title);
 bool qmsg_drive(Qmsg* qm, int key);
 Qmsg* qmsg_of(Qnav_block* qb);
 
--- a/tui_main.c
+++ b/tui_main.c
@@ -1455,7 +1455,7 @@
   qmenu_add_choice(qm, "Save", Main_menu_save);
   // qmenu_add_choice(qm, "Save As...", Main_menu_save_as);
   qmenu_add_spacer(qm);
-  qmenu_add_choice(qm, "Controls", Main_menu_controls);
+  qmenu_add_choice(qm, "Controls...", Main_menu_controls);
   qmenu_add_spacer(qm);
   qmenu_add_choice(qm, "Quit", Main_menu_quit);
   qmenu_push_to_nav(qm);
@@ -1464,11 +1464,58 @@
 }
 
 void push_controls_msg() {
-  Qmsg* qm = qmsg_push(30, 30);
+  struct Ctrl_item {
+    char const* left;
+    char const* right;
+  };
+  static struct Ctrl_item items[] = {
+      {"Ctrl+Q", "Quit"},
+      {"Arrow keys", "Move Cursor"},
+      {"Ctrl+D or F1", "Open Main Menu"},
+      {NULL, NULL},
+      {"0-9, A-Z, a-z,", "Insert Character"},
+      {"!, :, #, and *", NULL},
+      {NULL, NULL},
+      {"Spacebar", "Play/Pause"},
+      {"Ctrl+Z or Ctrl+U", "Undo"},
+      {"Ctrl+X", "Cut"},
+      {"Ctrl+C", "Copy"},
+      {"Ctrl+V", "Paste"},
+      {"Ctrl+S", "Save"},
+      {"Ctrl+F", "Frame Step Forward"},
+  };
+  int w_left = 0;
+  int w_right = 0;
+  for (Usz i = 0; i < ORCA_ARRAY_COUNTOF(items); ++i) {
+    // use wcswidth instead of strlen if you need wide char support. but note
+    // that won't be useful for UTF-8 or unicode chars in higher plane (emoji,
+    // complex zwj, etc.)
+    if (items[i].left) {
+      int wl = (int)strlen(items[i].left);
+      if (wl > w_left)
+        w_left = wl;
+    }
+    if (items[i].right) {
+      int wr = (int)strlen(items[i].right);
+      if (wr > w_right)
+        w_right = wr;
+    }
+  }
+  int mid_pad = 2;
+  int total_width = 1 + w_left + mid_pad + w_right;
+  Qmsg* qm = qmsg_push(ORCA_ARRAY_COUNTOF(items), total_width);
   WINDOW* w = qmsg_window(qm);
-  wmove(w, 0, 0);
-  wprintw(w, "ctrl+Q\tquit\n");
-  wprintw(w, "arrow keys\tmove cursor\n");
+  qmsg_set_title(qm, "Controls");
+  for (int i = 0; i < (int)ORCA_ARRAY_COUNTOF(items); ++i) {
+    if (items[i].left) {
+      wmove(w, i, 1);
+      wprintw(w, items[i].left);
+    }
+    if (items[i].right) {
+      wmove(w, i, w_left + 1 + mid_pad);
+      wprintw(w, items[i].right);
+    }
+  }
 }
 
 void try_save_with_msg(Ged* ged) {