aboutsummaryrefslogtreecommitdiff
path: root/apps/exec.c
blob: 305e9eff81250df9e7b08e31f6212ab1fa04f2d6 (plain) (blame)
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
// MIT License, Copyright (c) 2020 Marvin Borner

#include <gui.h>
#include <mem.h>
#include <print.h>
#include <str.h>
#include <sys.h>

#define PATH "/bin/"

#define HEIGHT 32
#define WIDTH 300
#define BORDER 2

void on_submit(struct gui_event_keyboard *event, struct element *elem)
{
	(void)event;
	char *inp = ((struct element_text_input *)elem->data)->text;
	u8 l = strlen(PATH) + strlen(inp) + 1;
	char *final = malloc(l);
	strcat(final, PATH);
	strcat(final, inp);
	exec(final, inp, NULL);
}

int main()
{
	struct element *root =
		gui_init("Exec", WIDTH + BORDER * 2, HEIGHT + BORDER * 2, COLOR_BLACK);
	struct element *input =
		gui_add_text_input(root, BORDER, BORDER, WIDTH, FONT_32, COLOR_WHITE, COLOR_BLACK);

	input->event.on_submit = on_submit;

	gui_event_loop(root);

	return 0;
}