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