Remove ui_confirm_deny() as an extraneous abstraction
[clav.git] / ui-cli.c
blob23cefe974486d67793fe0645eb5e156d54fbcb1e
1 /*
2 * Copyright (c) 2016, S. Gilles <sgilles@math.umd.edu>
4 * Permission to use, copy, modify, and/or distribute this software
5 * for any purpose with or without fee is hereby granted, provided
6 * that the above copyright notice and this permission notice appear
7 * in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <errno.h>
19 #include <stdint.h>
20 #include <stdio.h>
21 #include <stdlib.h>
23 #include "macros.h"
24 #include "quiver.h"
25 #include "ui.h"
27 /* Whether we actually need to draw this frame or not */
28 static uint_fast8_t need_to_draw = 1;
30 /* The quiver */
31 struct quiver *q;
33 /* The event we'll give back */
34 static struct ui_event pass_back = { 0 };
36 /* Intialize CLI */
37 int ui_init(struct quiver *i_q)
39 q = i_q;
41 return 0;
44 /* Deal with the fact that the quiver was changed */
45 int ui_respond_quiver_change(void)
47 return 0;
50 /* Tear down CLI */
51 int ui_teardown(void)
53 return 0;
56 /* Record that a frame has been started */
57 int ui_start_frame(void)
59 return 0;
62 /* Draw a frame, sleep to framelimit */
63 int ui_finish_frame(void)
65 size_t i = 0;
66 size_t j = 0;
67 struct rational *e = 0;
68 size_t line_length = 0;
70 if (!need_to_draw) {
71 return 0;
74 printf("%*s| Name\n----------\n", 4, "i");
76 for (j = 0; j < q->v_num; ++j) {
77 printf("%*llu | %s\n", 4, (long long unsigned) j, q->v[j].name);
80 line_length = printf("%*s| ", 4, "i\\j");
82 for (j = 0; j < q->v_num; ++j) {
83 line_length += printf("%*llu", 5, (long long unsigned) j);
86 putchar('\n');
88 for (j = 0; j < line_length; ++j) {
89 putchar('-');
92 for (i = 0; i < q->v_num; ++i) {
93 printf("\n %*llu| ", 3, (long long unsigned) i);
95 for (j = 0; j < q->v_num; ++j) {
96 e = &(q->e[i * q->v_len + j]);
98 if (e->p == 0) {
99 printf("%*s", 5, "");
100 } else if (e->q == 1) {
101 printf("%*lld", 5, (long long int) e->p);
102 } else {
103 printf("%*lld/%llu", 3, (long long int) e->p,
104 (long long unsigned) e->q);
109 printf("\n> ");
110 fflush(stdout);
111 need_to_draw = 0;
113 return 0;
116 int ui_get_event(struct ui_event *e, uint_fast8_t *more)
118 *e = pass_back;
119 *more = 0;
120 pass_back = (struct ui_event) { 0 };
122 return 0;