1/*-
2 * SPDX-License-Identifier: CC0-1.0
3 *
4 * Written in 2021 by Alfonso Sabato Siciliano.
5 * To the extent possible under law, the author has dedicated all copyright
6 * and related and neighboring rights to this software to the public domain
7 * worldwide. This software is distributed without any warranty, see:
8 *   <http://creativecommons.org/publicdomain/zero/1.0/>.
9 */
10
11#include <bsddialog.h>
12#include <locale.h>
13#include <stdio.h>
14#include <stdlib.h>
15
16#define H   BSDDIALOG_FIELDHIDDEN
17#define RO  BSDDIALOG_FIELDREADONLY
18
19int main()
20{
21	int i, output;
22	struct bsddialog_conf conf;
23	struct bsddialog_formitem items[3] = {
24	    {"Input:",    0, 0, "value",     0, 10, 30, 50, NULL, 0,  "desc 1"},
25	    {"Input:",    1, 0, "read only", 1, 10, 30, 50, NULL, RO, "desc 2"},
26	    {"Password:", 2, 0, "",          2, 10, 30, 50, NULL, H,  "desc 3"}
27	};
28
29	/* Optional, unless for unicode/multi-column characters */
30	setlocale(LC_ALL, "");
31
32	if (bsddialog_init() == BSDDIALOG_ERROR) {
33		printf("Error: %s\n", bsddialog_geterror());
34		return (1);
35	}
36	bsddialog_initconf(&conf);
37	conf.title = "form";
38	conf.form.securech = '*';
39	output = bsddialog_form(&conf, "Example", 10, 50, 3, 3, items, NULL);
40	bsddialog_end();
41	if (output == BSDDIALOG_ERROR) {
42		printf("Error: %s", bsddialog_geterror());
43		return (1);
44	}
45
46	for (i = 0; i < 3; i++) {
47		printf("%s \"%s\"\n", items[i].label, items[i].value);
48		free(items[i].value);
49	}
50
51	return (0);
52}
53