Path: blob/main/contrib/bsddialog/examples_library/mixedlist.c
39530 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 <stdio.h>1213int main()14{15int output;16unsigned int i, j;17struct bsddialog_conf conf;18struct bsddialog_menuitem item;19struct bsddialog_menuitem sep1[1] = {20{ "", true, 0, "Checklist", "(desc)", "" }21};22struct bsddialog_menuitem check[5] = {23{ "+", true, 0, "Name 1", "Desc 1", "Bottom Desc 1" },24{ "" , false, 0, "Name 2", "Desc 2", "Bottom Desc 2" },25{ "+", true, 0, "Name 3", "Desc 3", "Bottom Desc 3" },26{ "" , false, 0, "Name 4", "Desc 4", "Bottom Desc 4" },27{ "+", true, 0, "Name 5", "Desc 5", "Bottom Desc 5" }28};29struct bsddialog_menuitem sep2[2] = {30{ "", true, 0, "Radiolist", "(desc)", "" },31{ "", true, 0, "Subtitle", "(desc)", "" }32};33struct bsddialog_menuitem radio[5] = {34{ "", true, 0, "Name 1", "Desc 1", "Bottom Desc 1" },35{ "+", false, 0, "Name 2", "Desc 2", "Bottom Desc 2" },36{ "", false, 0, "Name 3", "Desc 3", "Bottom Desc 3" },37{ "+", false, 0, "Name 4", "Desc 4", "Bottom Desc 4" },38{ "", false, 0, "Name 5", "Desc 5", "Bottom Desc 5" }39};40struct bsddialog_menugroup group[4] = {41{ BSDDIALOG_SEPARATOR, 1, sep1, 0 },42{ BSDDIALOG_CHECKLIST, 5, check, 0 },43{ BSDDIALOG_SEPARATOR, 2, sep2, 0 },44{ BSDDIALOG_RADIOLIST, 5, radio, 0 }45};4647if (bsddialog_init() == BSDDIALOG_ERROR) {48printf("Error: %s\n", bsddialog_geterror());49return (1);50}51bsddialog_initconf(&conf);52conf.title = "mixedlist";53output = bsddialog_mixedlist(&conf, "Example", 20, 0, 13, 4, group,54NULL, NULL);55bsddialog_end();56if (output == BSDDIALOG_ERROR) {57printf("Error: %s\n", bsddialog_geterror());58return (1);59}6061printf("Mixedlist:\n");62for (i = 0; i < 4; i++) {63for (j = 0; j < group[i].nitems; j++) {64item = group[i].items[j];65if (group[i].type == BSDDIALOG_SEPARATOR)66printf("----- %s -----\n", item.name);67else if (group[i].type == BSDDIALOG_RADIOLIST)68printf(" (%c) %s\n",69item.on ? '*' : ' ', item.name);70else /* BSDDIALOG_CHECKLIST */71printf(" [%c] %s\n",72item.on ? 'X' : ' ', item.name);73}74}7576return (0);77}787980