-#include <curses.h>
+#define NCURSES_WIDECHAR 1
+#include <ncurses.h>
#include <locale.h>
#include <glib.h>
#include <signal.h>
};
const char *escaped_strings[] = {
+ "→", "to",
"α", "alpha",
"β", "beta",
"Γ", "Gamma",
"𝟞", "66",
"𝟟", "77",
"𝟠", "88",
- "𝟡", "99",
+ "𝟡", "99",
};
GHashTable *escaped_table;
create_rule()
{
struct rule *rule;
-
+
rule = malloc(sizeof(struct rule));
rule->name = NULL;
rule->hypotheses = NULL;
/* Γ */
set_ctp_and_pair(&ctp, &pair, caret, (*point)++);
+ prev_not_displayed = FALSE;
if (judgment->generic_l)
draw_wrap(w, y, x, v, TRUE, pair, judgment->generic_l);
else if (workplace_mode) {
caret, &point, inputstr, rule->conclusion);
set_ctp_and_pair(&ctp, &pair, caret, point++);
draw_slot(w, y, &r, TRUE, FALSE, pair, ctp == ctp_on ? inputstr : rule->name);
-
+
lw = c;
if (!virtual) {
*y = row + 1; *x = col;
y = 0; x = 0;
draw_rule(state->workspace_w, &y, &x, FALSE, TRUE,
state->caret, state->input->str, state->rule);
-
+
/* draw existing rules */
i = 0;
g_hash_table_iter_init(&iter, state->rules);
draw_rule(state->support_w, &y, &x, FALSE, FALSE, -1, NULL, rule);
i = y + 2;
l = l->next;
- }
+ }
/* draw echo area */
if (state->err) {
move(2 * q + 1, 0);
printw("support%*s", COLS - 7, "");
attroff(COLOR_PAIR(PAIR_WB));
-
+
refresh();
}
{
GSList *l;
struct name *name;
-
+
if (key == '\\') {
state->escape = TRUE;
state->status = 0;
}
}
+void
+handle_slot_backspace(struct state *state)
+{
+ switch (state->st) {
+ case st_a:
+ state->st = st_thesis;
+ state->judgment->kind = tk_unknown;
+ break;
+ case st_b:
+ break;
+ default:
+ }
+}
+
+void
+handle_input_backspace(struct state *state)
+{
+ if (*state->input->str == '\0')
+ handle_slot_backspace(state);
+ else
+ g_string_erase(state->input, 0, -1);
+}
+
+void
+handle_backspace(struct state *state)
+{
+ if (!state->escape)
+ handle_input_backspace(state);
+ else
+ {
+ if (*state->escaped_input->str == '\0')
+ state->escape = FALSE;
+ else
+ g_string_erase(state->escaped_input, 0, -1);
+ }
+}
+
bool
conclusion_p(struct rule *rule, struct judgment *judgment)
{
validate_type_thesis(struct state *state)
{
struct name *name;
-
+
if (*state->input->str == '\0')
return 1;
if (conclusion_p(state->rule, state->judgment)) {
if ((name = g_hash_table_lookup(state->vets, state->input->str))) {
if (name->kind != nk_type)
return 6;
-
+
/* the name exists, is a type, and is local */
state->judgment->a = create_wrap(FALSE, name);
return -1; /* TODO: check dependencies */
main()
{
const char *k, *v;
- char key, *str;
+ char *str;
int i, j, q;
struct state state;
struct judgment *j_p;
GSList *l;
GHashTableIter iter;
gpointer hkey, hvalue;
-
+ wint_t key;
+
setlocale(LC_ALL, "");
initscr();
start_color();
state.support_w = subwin(stdscr, q, COLS, q + 1, 0);
state.echo_w = subwin(stdscr, 1, COLS, LINES - 1, 0);
state.rules = g_hash_table_new_full(g_str_hash, g_str_equal,
- free, (GDestroyNotify)free_rule);
+ NULL, (GDestroyNotify)free_rule);
state.decls = g_hash_table_new(g_str_hash, g_str_equal);
state.gctxs = g_hash_table_new(g_str_hash, g_str_equal);
state.gtheses = g_hash_table_new(g_str_hash, g_str_equal);
state.escaped_input = g_string_new(NULL);
state.escape = FALSE;
state.err = 0;
-
+
/* populate escaped strings table */
/* NOTE: `g_hash_table_insert' deletes keys and values if they already exist.
This is not what we want for the value list. Thus, we will free the
values manually before destroying the table.
*/
- escaped_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
+ escaped_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
for (i = 0 ; i < sizeof(escaped_strings) / sizeof(char *) / 2 ; i++) {
k = escaped_strings[2 * i + 1];
v = escaped_strings[2 * i + 0];
render(&state);
}
while(state.running) {
- key = getch();
+ get_wch(&key);
if (key == KEY_ESC) {
state.running = FALSE;
break;
g_slist_free(g_steal_pointer(&state.support));
}
}
+ else if (key == KEY_BACKSPACE)
+ handle_backspace(&state);
else
handle_input(&state, key);
break;
state.st = st_ctx_dots;
}
}
+ else if (key == KEY_BACKSPACE)
+ handle_backspace(&state);
else
handle_input(&state, key);
break;
state.status = 0;
}
}
+ else if (key == KEY_BACKSPACE)
+ handle_backspace(&state);
else
handle_input(&state, key);
break;
state.err = -1;
}
}
+ else if (key == KEY_BACKSPACE)
+ handle_backspace(&state);
else
handle_input(&state, key);
break;
state.st = st_rule_name;
}
}
+ else if (key == KEY_BACKSPACE)
+ handle_backspace(&state);
else
handle_input(&state, key);
break;
state.caret += 1;
state.st = st_rule_name;
}
+ else if (key == KEY_BACKSPACE)
+ handle_backspace(&state);
else
handle_input(&state, key);
break;