/
gui.h
83 lines (70 loc) · 1.45 KB
/
gui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/** phiola: executor: 'gui' command
2023, Simon Zolin */
static int gui_help()
{
help_info_write("\
Show graphical interface:\n\
`phiola gui` [INPUT...]\n\
\n\
INPUT File name, directory or URL\n\
");
x->exit_code = 0;
return 1;
}
struct cmd_gui {
ffvec input; // ffstr[]
};
static int gui_input(struct cmd_gui *g, ffstr s)
{
*ffvec_pushT(&g->input, ffstr) = s;
return 0;
}
static void gui_log_ctl(uint flags)
{
if (flags)
x->log.func = x->logif->log; // GUI is ready to display logs
else
x->log.func = NULL;
}
static int gui_action(struct cmd_gui *g)
{
struct phi_queue_conf qc = {
.first_filter = &phi_guard_gui,
.ui_module = "gui.track",
};
x->queue->create(&qc);
ffstr *it;
FFSLICE_WALK(&g->input, it) {
struct phi_queue_entry qe = {
.conf.ifile.name = ffsz_dupstr(it),
};
x->queue->add(NULL, &qe);
}
ffvec_free(&g->input);
x->log.use_color = (x->log.use_color && x->debug);
x->core->mod("gui");
if (!x->debug) {
// show logs inside Logs window
x->logif = x->core->mod("gui.log");
x->logif->setup(gui_log_ctl);
}
x->exit_code = 0;
return 0;
}
static int gui_open()
{
return 0;
}
static const struct ffarg cmd_gui[] = {
{ "-help", 0, gui_help },
{ "\0\1", 'S', gui_input },
{ "", 0, gui_open },
};
static void cmd_gui_free(struct cmd_gui *g)
{
ffmem_free(g);
}
static struct ffarg_ctx cmd_gui_init(void *obj)
{
return SUBCMD_INIT(ffmem_new(struct cmd_gui), cmd_gui_free, gui_action, cmd_gui);
}