C_C++
Cerbian
Tcl
anon_-_poller
autoconfig
bison
compile_times
cpp_zh
emil_header_guards
flex
linking
sds
1st_day_of_month.cpp
JJbY.cpp
Tp6G.cpp
access.c
alternatice_bracket.c
arrows.cpp
auto_variad.c
c.php
c_old_argument_notation.c
clear_bindings.c
cnn.c
comment_as_space.c
comp.c
compare_to.py
conditional_const.c
const.c
correct_c_equivalent.c
cpp_regex_error.cpp
current_year.cpp
dda2.cpp
does_freeing_a_const_char_pointer_warn_or_is_it_a_footgun_under_gcc.c
dog.jpg
dog2.jpg
eh.cpp
else_while.c
finalize_reprepare.c
for_ctags.cpp
for_nop_true.c
free_null.c
function_pointer_strategy.c
function_pointer_strategy2.c
gcc_include_next.c
gdb_graph.c
getopt_test.c
getter_example.cpp
gnu_decimals.c
gnu_history.c
gnu_regex.c
gnu_regex2.c
header.h
highlight.c
hw.c
index_in_initializer_list_compiler_extension.c
int.ino
is_embed_finally_here.c
is_extern_c_retarded.c
is_this_what_you_are_asking_emil.c
knr.c
levenshtein_dist_-_usage.cpp
macro_paren.c
magic.c
main.ino
manual_unrolling.c
map_initialization.cpp
ncurses_labels.c
ncurses_mv_win.cpp
ncurses_out_of_bounds.c
ncurses_plus_readline.cpp
ncurses_resize2.cpp
ncurses_resize_hello_world.cpp
ncurses_resize_test.c
ncurses_scroll.c
ncurses_text_subwin_overflow.c
nf.c
no_way.cpp
null_printf.c
null_printf.cpp
pointer_array.c
portable_namespace.c
portable_namespace.h
printf_star.c
process_renaming.c
pta.c
raylib_hw.cpp
re2c_test.c
re2c_test2.c
readline_rl_redisplay_function_NULL.c
scoping_showcase.c
screen_size_(without_curses).c
sdl_render_to_texture.cpp
self_pointer.c
sentinel_pack.c
servo1.ino
setjmp_test.cpp
shebang.c
signals.c
strategiless.c
strcmp_vs_tricks.c
strdup.c
string_repetition
string_repetition.c
strinize.c
syntax.y
tcc_int.c
test.c
typedef.c
unctrl.c
undefined_reference.c
usb.c
vasprintf.c
void_main.c
x.cpp
xor_nn.cpp
xtermio.c
xtp.cpp
zongora.ino
Haskell
Java
LaTeX
Misc.
Python
Vim
Webdev
git
.gitignore
Makefile
86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
/* @BAKE gcc $@ -o $*.out $(pkg-config --cflags --libs ncurses) -Wpedantic && ./$*.out
|
|
*/
|
|
#include <stdio.h>
|
|
|
|
typedef struct {
|
|
const char * description;
|
|
void (*hook)();
|
|
} action_t;
|
|
|
|
typedef struct {
|
|
const char * name;
|
|
action_t * action;
|
|
} menu_item_t;
|
|
|
|
void yellow_line();
|
|
void tri_force();
|
|
void swap_with_first(menu_item_t * i);
|
|
void swap_with_first(move_up);
|
|
|
|
menu_item_t * menu_items[] = {
|
|
&(menu_item_t){"Item 1", &(action_t){"Print yellow line", yellow_line}},
|
|
&(menu_item_t){"Item 2", &(action_t){"Triforce like and oldfag", tri_force}},
|
|
&(menu_item_t){"Item 3", &(action_t){"Swap with first.", swap_with_first}},
|
|
&(menu_item_t){"Item 4", &(action_t){"Move up", move_up}},
|
|
&(menu_item_t){"Item 5", &(action_t){"print yellow line", yellow_line}},
|
|
&(menu_item_t){"Item 6", &(action_t){"print yellow line", yellow_line}},
|
|
&(menu_item_t){"Item 7", &(action_t){"print yellow line", yellow_line}},
|
|
&(menu_item_t){"Item 8", &(action_t){"print yellow line", yellow_line}},
|
|
&(menu_item_t){"Item 9", &(action_t){"print yellow line", yellow_line}},
|
|
};
|
|
|
|
void action_swap(menu_item_t * a, menu_item_t * b) {
|
|
action_t * swap = a->action;
|
|
a->action = b->action;
|
|
b->action = swap;
|
|
}
|
|
|
|
const unsigned menu_size = sizeof(menu_items) / sizeof(menu_item_t*);
|
|
|
|
void yellow_line() {
|
|
puts("\033[33m---------\033[0m");
|
|
}
|
|
|
|
void tri_force() {
|
|
puts (
|
|
" ▲ \n"
|
|
"▲ ▲\n"
|
|
);
|
|
}
|
|
|
|
void swap_with_first(menu_item_t * i) {
|
|
action_swap(menu_items[0], i);
|
|
}
|
|
|
|
void move_up(menu_item_t * i) {
|
|
int n = menu_items - i;
|
|
if (n > 1) {
|
|
action_swap(menu_items[n-1], menu_items[n]);
|
|
} else {
|
|
action_swap(menu_items[n], menu_items[menu_size]);
|
|
}
|
|
}
|
|
|
|
|
|
void print_menu() {
|
|
for (int i = 0; i < menu_size; i++) {
|
|
printf("%s:\n", menu_items[i]->name);
|
|
printf(" %s\n\n", menu_items[i]->action->description);
|
|
}
|
|
puts("###");
|
|
}
|
|
|
|
signed main() {
|
|
while (1) {
|
|
print_menu();
|
|
|
|
char c = getchar();
|
|
while(getchar() != '\n') { ; }
|
|
|
|
if (c >= '1'
|
|
&& c <= ('1' + menu_size)) {
|
|
menu_items[c - '1']->action->hook(menu_items[c - '1']);
|
|
}
|
|
}
|
|
}
|