aboutsummaryrefslogtreecommitdiff
path: root/contrib/bsddialog/lib/bsddialog.3
blob: 9cc68a90ff62fca3f99c7a192c4e34292118b62e (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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
.\"
.\" Copyright (c) 2021-2022 Alfonso Sabato Siciliano
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd September 23, 2022
.Dt BSDDIALOG 3
.Os
.Sh NAME
.Nm bsddialog_backtitle ,
.Nm bsddialog_calendar ,
.Nm bsddialog_clearterminal ,
.Nm bsddialog_color ,
.Nm bsddialog_color_attrs ,
.Nm bsddialog_checklist ,
.Nm bsddialog_datebox ,
.Nm bsddialog_end ,
.Nm bsddialog_form ,
.Nm bsddialog_gauge ,
.Nm bsddialog_geterror ,
.Nm bsddialog_get_theme ,
.Nm bsddialog_hascolors ,
.Nm bsddialog_infobox ,
.Nm bsddialog_init ,
.Nm bsddialog_init_notheme ,
.Nm bsddialog_initconf ,
.Nm bsddialog_menu ,
.Nm bsddialog_mixedgauge ,
.Nm bsddialog_mixedlist ,
.Nm bsddialog_msgbox ,
.Nm bsddialog_pause ,
.Nm bsddialog_radiolist ,
.Nm bsddialog_rangebox ,
.Nm bsddialog_set_theme ,
.Nm bsddialog_set_default_theme ,
.Nm bsddialog_textbox ,
.Nm bsddialog_timebox ,
.Nm bsddialog_yesno
.Nd TUI dialogs
.Sh LIBRARY
.Lb libbsddialog
.Sh SYNOPSIS
.In bsddialog.h
.Ft int
.Fn bsddialog_backtitle "struct bsddialog_conf *conf" "const char *backtitle"
.Ft int
.Fo bsddialog_calendar
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int *yy"
.Fa "unsigned int *mm"
.Fa "unsigned int *dd"
.Fc
.Ft int
.Fo bsddialog_checklist
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int menurows"
.Fa "unsigned int nitems"
.Fa "struct bsddialog_menuitem *items"
.Fa "int *focusitem"
.Fc
.Ft int
.Fn bsddialog_clearterminal "void"
.Ft int
.Fo bsddialog_datebox
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int *yy"
.Fa "unsigned int *mm"
.Fa "unsigned int *dd"
.Fc
.Ft int
.Fn bsddialog_end "void"
.Ft int
.Fo bsddialog_form
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int formrows"
.Fa "unsigned int nitems"
.Fa "struct bsddialog_formitem *items"
.Fc
.Ft int
.Fo bsddialog_gauge
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int perc"
.Fa "int fd"
.Fa "const char *sep"
.Fc
.Ft const char *
.Fn bsddialog_geterror "void"
.Ft int
.Fo bsddialog_infobox
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fc
.Ft int
.Fn bsddialog_init "void"
.Ft int
.Fn bsddialog_init_notheme "void"
.Ft int
.Fn bsddialog_initconf "struct bsddialog_conf *conf"
.Ft int
.Fo bsddialog_menu
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int menurows"
.Fa "unsigned int nitems"
.Fa "struct bsddialog_menuitem *items"
.Fa "int *focusitem"
.Fc
.Ft int
.Fo bsddialog_mixedgauge
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int mainperc"
.Fa "unsigned int nminibars"
.Fa "char **minilabels"
.Fa "int *minipercs"
.Fc
.Ft int
.Fo bsddialog_mixedlist
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int menurows"
.Fa "unsigned int ngroups"
.Fa "struct bsddialog_menugroup *groups"
.Fa "int *focuslist"
.Fa "int *focusitem"
.Fc
.Ft int
.Fo bsddialog_msgbox
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fc
.Ft int
.Fo bsddialog_pause
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int seconds"
.Fc
.Ft int
.Fo bsddialog_radiolist
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int menurows"
.Fa "unsigned int nitems"
.Fa "struct bsddialog_menuitem *items"
.Fa "int *focusitem"
.Fc
.Ft int
.Fo bsddialog_rangebox
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "int min"
.Fa "int max"
.Fa "int *value"
.Fc
.Ft int
.Fo bsddialog_textbox
.Fa "struct bsddialog_conf *conf"
.Fa "const char *file"
.Fa "int rows"
.Fa "int cols"
.Fc
.Ft int
.Fo bsddialog_timebox
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fa "unsigned int *hh"
.Fa "unsigned int *mm"
.Fa "unsigned int *ss"
.Fc
.Ft int
.Fo bsddialog_yesno
.Fa "struct bsddialog_conf *conf"
.Fa "const char *text"
.Fa "int rows"
.Fa "int cols"
.Fc
.In bsddialog_theme.h
.Ft int
.Fo bsddialog_color
.Fa "enum bsddialog_color foreground"
.Fa "enum bsddialog_color background"
.Fa "unsigned int flags"
.Fc
.Ft int
.Fo bsddialog_color_attrs
.Fa "int color"
.Fa "enum bsddialog_color *foreground"
.Fa "enum bsddialog_color *background"
.Fa "unsigned int *flags"
.Fc
.Ft int
.Fn bsddialog_get_theme "struct bsddialog_theme *theme"
.Ft bool
.Fn bsddialog_hascolors "void"
.Ft int
.Fn bsddialog_set_default_theme "enum bsddialog_default_theme theme"
.Ft int
.Fn bsddialog_set_theme "struct bsddialog_theme *theme"
.Sh DESCRIPTION
The
.Nm bsddialog
library provides an API to build Text User Interface dialogs and widgets: to
display messages, to get input and to inform about a computation status.
.Pp
.Fn bsddialog_init
initializes the library, the only functions that can be called before is
.Fn bsddialog_initconf
described later.
After the initialization the input and output should be handled via the library
API.
.Fn bsddialog_end
restores the screen like before
.Fn bsddialog_init ,
then it is not possible to use the library functions.
.Fn bsddialog_init_notheme
is equivalent to
.Fn bsddialog_init
except it does not set the default graphical theme; see
.Sx Theme
subsection to set a theme explicitly.
.Pp
.Fn bsddialog_error
returns a string to describe the last error, it should be called after a
.Dv BSDDIALOG_ERROR
returned value.
.Fn bsddialog_clearterminal
clears the screen.
.Fn bsddialog_backtitle
prints
.Fa backtitle
on the top of the screen, it is possible to set
.Fa conf.ascii_lines
and
.Fa conf.no_lines ;
.Fa conf
is described later.
.Pp
Each
.Fa char*
argument has to be a well terminated string, it can be a multibyte character
string depending on current locale, see
.Xr setlocale 3 .
.Ss Dialogs
The dialogs have common arguments.
.Fa text
is a string printed inside the dialog.
.Fa rows
and
.Fa cols
are height and width, their value can be between 2 and the screen size,
.Dv BSDDIALOG_AUTOSIZE
or
.Dv BSDDIALOG_FULLSCREEN .
.Fa conf
is a struct to customize the dialog, it does not set global properties to the
library.
.Pp
.Bd -literal -offset indent -compact
struct bsddialog_conf {
	bool ascii_lines;
	unsigned int auto_minheight;
	unsigned int auto_minwidth;
	unsigned int auto_topmargin;
	unsigned int auto_downmargin;
	const char *bottomtitle;
	bool clear;
	int *get_height;
	int *get_width;
	bool no_lines;
	bool shadow;
	unsigned int sleep;
	const char *title;
	int y;
	int x;
	struct {
		bool enable_esc;
		const char *f1_file;
		const char *f1_message;
	} key;
	struct {
		unsigned int cols_per_row;
		bool highlight;
		unsigned int tablen;
	} text;
	struct {
		bool align_left;
		bool no_desc;
		bool no_name;
		bool on_without_ok;
		bool shortcut_buttons;
	} menu;
	struct {
		char securech;
		char *securembch;
		bool value_wchar;
		bool value_without_ok;
	} form;
	struct {
		bool always_active;
		bool without_ok;
		const char *ok_label;
		bool with_extra;
		const char *extra_label;
		bool without_cancel;
		const char *cancel_label;
		bool default_cancel;
		bool with_help;
		const char *help_label;
		const char *generic1_label;
		const char *generic2_label;
		const char *default_label;
	} button;
};
.Ed
.Pp
.Bl -column -compact
.It Fa conf.ascii_lines
ascii characters to draw lines, default wide characters.
.It Fa conf.auto_minheight
minimum height if
.Fa rows
is
.Dv BSDDIALOG_AUTOSIZE .
.It Fa conf.auto_minwidth
minimum width if
.Fa cols
is
.Dv BSDDIALOG_AUTOSIZE .
.It Fa conf.auto_topmargin
top margin if
.Fa rows
is
.Dv BSDDIALOG_AUTOSIZE
or
.Dv BSDDIALOG_FULLSCREEN ,
.Fa conf.y
has to be
.Dv BSDDIALOG_CENTER .
.It Fa conf.auto_downmargin
down margin if
.Fa rows
is
.Dv BSDDIALOG_AUTOSIZE
or
.Dv BSDDIALOG_FULLSCREEN .
.It Fa conf.bottomtitle
subtitle at the dialog bottom side.
.It Fa conf.clear
hide the dialog at exit.
.It Fa conf.get_height
if not
.Dv NULL
is set like the dialog height.
.It Fa conf.get_width
if not
.Dv NULL
is set like the dialog width.
.It Fa conf.no_lines
not draw lines.
.It Fa conf.shadow
draw shadow.
.It Fa conf.sleep
wait before to return, the value is in seconds.
.It Fa conf.title
title at the top dialog side.
.It Fa conf.y
vertical position, 0 is top screen size, can be
.Dv BSDDIALOG_CENTER .
.It Fa conf.x
horizontal position, 0 is left screen side, can be
.Dv BSDDIALOG_CENTER .
.El
.Pp
.Bl -column -compact
.It Fa conf.key.enable_esc
enables
.Dv ESC
key to close the dialog.
.It Fa conf.key.f1_file
file to open if F1 is pressed.
.It Fa conf.key.f1_message
message to display if F1 is pressed.
.El
.Pp
.Bl -column -compact
.It Fa conf.text.cols_per_row
Try to set the number of columns for a row of
.Fa text
with autosizing; default
.Dv 10 .
.It Fa conf.text.highlight
enables highlights for
.Fa text ,
properly the following sequences are considered escapes:
.It Dq \eZ0
black.
.It Dq \eZ1
red.
.It Dq \eZ2
green.
.It Dq \eZ3
yellow.
.It Dq \eZ4
blue.
.It Dq \eZ5
magenta.
.It Dq \eZ6
cyan.
.It Dq \eZ7
white.
.It Dq \eZr
reverse foreground and background.
.It Dq \eZR
disable reverse.
.It Dq \eZb
bold.
.It Dq \eZB
disable bold.
.It Dq \eZu
underline.
.It Dq \eZU
disable underline.
.It Dq \eZn
disable each customization.
.It Fa conf.text.tablen
tab length for
.Fa text
argument and
.Fn bsddialog_textbox
function.
.El
.Pp
.Bl -column -compact
.It Fa conf.button.always_active
buttons always active, avoidind focus switch between buttons and input fields or
input boxes in
.Fn bsddialog_form ,
.Fn bsddialog_datebox ,
.Fn bsddialog_calendar
and
.Fn bsddialog_timebox .
.It Fa conf.button.without_ok
disable OK button.
.It Fa conf.button.ok_label
set label for OK button.
.It Fa conf.button.with_extra
add Extra button.
.It Fa conf.button.extra_label
set a label for Extra button.
.It Fa conf.button.without_cancel
disable Cancel button.
.It Fa conf.button.cancel_label
sets a label for Cancel button.
.It Fa conf.button.default_cancel
on startup focus on the Cancel button.
.It Fa conf.button.with_help
add Help button.
.It Fa conf.button.help_label
set a label for Help button.
.It Fa conf.button.generic1_label
add a button with the specified label.
.It Fa conf.button.generic2_label
add a button with the specified label.
.It Fa conf.button.default_label
focus on the button with the specified label.
.El
.Pp
.Fn bsddialog_initconf
initializes
.Fa conf
disabling each property, except
.Fa conf.shadow
to true,
.Fa conf.y
and
.Fa conf.x
to
.Dv BSDDIALOG_CENTER ,
.Fa conf.text.cols_per_row
to
.Dv 10 .
.Pp
.Fn bsddialog_infobox
builds a dialog without buttons and returns instantly.
.Fn bsddialog_msgbox
builds a dialog with OK button.
.Fn bsddialog_yesno
provides a dialog for a
.Dq Yes-No Question ,
the labels on buttons are Yes and No.
.Pp
.Fn bsddialog_pause
builds a dialog waiting until the timeout in
.Fa seconds
expires or a button is pressed.
.Pp
.Fn bsddialog_calendar
and
.Fn bsddialog_datebox
build a dialog to select a date,
.Fa yy ,
.Fa mm ,
and
.Fa dd
are default values on startup, selected date at exit.
.Fn bsddialog_timebox
builds a dialog to choose a time,
.Fa hh ,
.Fa mm ,
and
.Fa ss
are default values on startup, selected time at exit.
.Pp
.Fn bsddialog_checklist ,
.Fn bsddialog_menu
and
.Fn bsddialog_radiolist
build dialogs to select some item from a list via the SPACE key, an item is
defined like:
.Pp
.Bd -literal -offset indent -compact
struct bsddialog_menuitem {
	const char *prefix;
	bool on;
	unsigned int depth;
	const char *name;
	const char *desc;
	const char *bottomdesc;
};
.Ed
.Pp
.Fa prefix ,
.Fa name
and
.Fa desc
are strings to describe the item and are printed on its row,
.Fa bottomdesc
is printed on the bottom side of the screen,
.Fa depth
is a margin between the
.Fa prefix
and
.Fa name
useful to implement a
.Dq treeview,
.Fa on
is set to
.Dv true
if the item is selected,
.Dv false
otherwise.
.Fa items
is an array of items of
.Fa nitem
elements,
.Fa menurows
specifies the graphical fixed height of the list, if
.Fa cols
is set to
.Dv BSDDIALOG_AUTOSIZE
.Fa menurows
specifies a maximum value.
Finally, if not
.Dv NULL ,
.Fa focusitem
specifies the default item on startup and the last focused item at exit, could
be a negative value if no item is focused.
.Pp
.Fn bsddialog_mixedlist
builds a dialog with collections of checklists, radiolists and separators.
A collection is a set defined like:
.Pp
.Bd -literal -offset indent -compact
enum bsddialog_menutype {
	BSDDIALOG_CHECKLIST,
	BSDDIALOG_RADIOLIST,
	BSDDIALOG_SEPARATOR,
};

struct bsddialog_menugroup {
	enum bsddialog_menutype type;
	unsigned int nitems;
	struct bsddialog_menuitem *items;
};
.Ed
.Pp
.Fa groups
is an array of sets of
.Fa ngroups
elements.
.Fa menurows
is the graphical height size for the list.
If not
.Dv NULL ,
.Fa focuslist
and
.Fa focusitem
specify the default item on startup and the last focused item at exit, could be
a negative value if no item is focused.
.Pp
.Fn bsddialog_checklist ,
.Fn bsddialog_menu ,
.Fn bsddialog_mixedlist
and
.Fn bsddialog_radiolist
can be costomizated by:
.Bl -column -compact
.It Fa conf.menu.align_left
aligns items to left, default center.
.It Fa conf.menu.no_desc
hide description.
.It Fa conf.menu.no_name
hide names.
.It Fa conf.menu.on_without_ok
set items
.Fa on
also if the OK button is not pressed.
.It Fa conf.menu.shortcut_buttons
enable shortcut keys on buttons, default on items.
.El
.Pp
.Fn bsddialog_form
builds a dialog to display an array of
.Fa items
of
.Fa nitems
elements to get strings in input.
.Fa formrows
specifies the graphical height for the box around the items,
.Dv 0
for autosizing.
An item is defined like:
.Pp
.Bd -literal -offset indent -compact
struct bsddialog_formitem {
	const char *label;
	unsigned int ylabel;
	unsigned int xlabel;

	const char *init;
	unsigned int yfield;
	unsigned int xfield;
	unsigned int fieldlen;
	unsigned int maxvaluelen;
	char *value;

	unsigned int flags;

	const char *bottomdesc;
};
.Ed
.Pp
.Fa label
is a string to describe the request, it is printed at the position
.Fa ylabel
and
.Fa xlabel .
The field for the input is at the position
.Fa yfield
and
.Fa xfield ,
.Fa fieldlen
is its graphical width, while
.Fa maxvalelen
is the maximum number of characters of the input string.
.Fa init
is the default field value.
If the OK button is pressed
.Fa value
is the allocated memory with the current field string, its size depends on
the current locale.
.Fa flags
is an OR value to set the
.Dv BSDDIALOG_FIELDHIDDEN ,
.Dv BSDDIALOG_FIELDREADONLY ,
.Dv BSDDIALOG_FIELDNOCOLOR ,
.Dv BSDDIALOG_FIELDCURSOREND ,
.Dv BSDDIALOG_FIELDEXTEND
and
.Dv BSDDIALOG_FIELDSINGLEBYTE .
flags for the field.
.Fa bottomdesc
is printed on the bottom side of the screen if the item is focused.
.Pp
.Fn bsddialog_form
can be customized by:
.Bl -column -compact
.It Fa conf.form.securech
charachter to hide the input with
.Dv BSDDIALOG_FIELDHIDDEN .
.It Fa conf.form.securembch
multibyte charachter to hide the input with
.Dv BSDDIALOG_FIELDHIDDEN ,
.Fa conf.form.securech
is ignored.
.It Fa conf.form.value_wchar
the allocated
.Fa value
is a
.Em wchar_t*
string.
.It Fa conf.form.value_without_ok
allocate memory and set
.Fa value
also if the OK button is not pressed.
.El
.Pp
.Fn bsddialog_gauge
builds a dialog with a bar to shows
.Fa perc ,
if the file descriptor
.Fa fd
is greater or equal to 0 the dialog waits to read
.Fa separator
from it, then the first string replaces
.Fa perc
and the following strings replace
.Fa text
until the next
.Fa separator ,
the loop ends reading
.Dv EOF .
.Pp
.Fn bsddialog_mixedgauge
draws a main bar with the
.Fa mainperc
percentage and
.Fa nminibars
each one with a
.Fa minilabel
and a
.Fa miniperc
with a value between 0 and 100 or
.Dv BSDDIALOG_MG_SUCCEEDED ,
.Dv BSDDIALOG_MG_FAILED ,
.Dv BSDDIALOG_MG_PASSED ,
.Dv BSDDIALOG_MG_COMPLETED ,
.Dv BSDDIALOG_MG_CHECKED ,
.Dv BSDDIALOG_MG_DONE ,
.Dv BSDDIALOG_MG_SKIPPED ,
.Dv BSDDIALOG_MG_INPROGRESS ,
.Dv BSDDIALOG_MG_BLANK ,
.Dv BSDDIALOG_MG_NA
or
.Dv BSDDIALOG_MG_PENDING
to print a descriptive string.
.Pp
.Fn bsddialog_rangebox
to select a value between
.Fa min
and
.Fa max .
.Fa value
is the default value on startup and the selected value at exit.
The current value is printed inside a bar, the keys UP, DOWN, HOME, END, PAGEUP
and PAGEDOWN can change it.
.Pp
.Fn bsddialog_textbox
opens and prints
.Fa file
in a dialog, the UP, DOWN, HOME, END, PAGEUP and PAGEDOWN keys are availble to
navigate the file.
OK button is renamed EXIT.
.Ss Theme
The graphical properties are global to the library, they are represented by
.Fa struct bsddialog_theme
and can be customized at runtime via the
.In bsddialog_theme.h
API.
.Pp
.Bd -literal -offset indent -compact
struct bsddialog_theme {
	struct {
		int color;
	} screen;
	struct {
		int color;
		unsigned int y;
		unsigned int x;
	} shadow;
	struct {
		int  color;
		bool delimtitle;
		int  titlecolor;
		int  lineraisecolor;
		int  linelowercolor;
		int  bottomtitlecolor;
		int  arrowcolor;
	} dialog;
	struct {
		int f_selectorcolor;
		int selectorcolor;
		int f_namecolor;
		int namecolor;
		int f_desccolor;
		int desccolor;
		int namesepcolor;
		int descsepcolor;
		int f_shortcutcolor;
		int shortcutcolor;
		int bottomdesccolor;
	} menu;
	struct {
		int f_fieldcolor;
		int fieldcolor;
		int readonlycolor;
		int bottomdesccolor;
	} form;
	struct {
		int f_color;
		int color;
	} bar;
	struct {
		unsigned int minmargin;
		unsigned int maxmargin;
		char leftdelim;
		char rightdelim;
		int delimcolor;
		int f_delimcolor;
		int color;
		int f_color;
		int shortcutcolor;
		int f_shortcutcolor;
	} button;
};
.Ed
.Pp
A member with the
.Dq f_
prefix refers to an element with focus.
.Pp
.Fn bsddialog_get_theme
sets
.Fa theme
like the current theme.
.Pp
A color can be set by the value returned by
.Fn bsddialog_color ,
Possible values for
.Fa background
and
.Fa foreground
are:
.Dv BSDDIALOG_BLACK ,
.Dv BSDDIALOG_RED ,
.Dv BSDDIALOG_GREEN ,
.Dv BSDDIALOG_YELLOW ,
.Dv BSDDIALOG_BLUE ,
.Dv BSDDIALOG_MAGENTA ,
.Dv BSDDIALOG_CYAN ,
and
.Dv BSDDIALOG_WHITE ,
.Fa flags
specifies OR-flags, possible values:
.Dv BSDDIALOG_BOLD ,
.Dv BSDDIALOG_REVERSE
and
.Dv BSDDIALOG_UNDERLINE .
.Fn bsddialog_color_attrs
gets the properties of a color.
.Pp
.Fn bsddialog_set_theme
sets
.Fa theme
like current theme, the changes takes effect only for dialogs built after the
call.
.Pp
The library provides predefined themes:
.Dv BSDDIALOG_THEME_BLACKWHITE ,
.Dv BSDDIALOG_THEME_BSDDIALOG ,
.Dv BSDDIALOG_THEME_FLAT
and
.Dv BSDDIALOG_THEME_DIALOG ,
they can be set via
.Fn bsddialog_set_default_theme .
.Pp
.Fn bsddialog_hascolors
returns
.Dv true
if the terminal provides colors,
.Dv false
otherwise.
.Sh RETURN VALUES
The functions return the value
.Dv BSDDIALOG_ERROR
if unsuccessful;
otherwise, depending on the pressed button, the following values can be
returned:
.Dv BSDDIALOG_OK ,
.Dv BSDDIALOG_CANCEL ,
.Dv BSDDIALOG_HELP ,
.Dv BSDDIALOG_EXTRA ,
.Dv BSDDIALOG_GENERIC1
or
.Dv BSDDIALOG_GENERIC2 .
.Dv BSDDIALOG_YES
and
.Dv BSDDIALOG_NO
are aliases for
.Dv BSDDIALOG_OK
and
.Dv BSDDIALOG_CANCEL ,
respectively.
.Pp
The functions return
.Dv BSDDIALOG_ESC
if
.Fa conf.key.enable_esc
is enabled and the ESC key is pressed.
.Pp
.Fn bsddialog_pause
returns
.Dv BSDDIALOG_TIMEOUT
if the timeout expires.
.Sh EXAMPLES
.Dq Yes-No Question
Example:
.Pp
.Bd -literal -offset indent -compact
int output;
struct bsddialog_conf conf;

if (bsddialog_init() == BSDDIALOG_ERROR)
	return (1);

bsddialog_initconf(&conf);
conf.title = "yesno";
output = bsddialog_yesno(&conf, "Example", 7, 25);

bsddialog_end();

switch (output) {
case BSDDIALOG_YES:
	printf("Yes\\n");
	break;
case BSDDIALOG_NO
	printf("NO\\n");
	break;
case BSDDIALOG_ERROR:
	printf("Error: %s\\n", bsddialog_geterror());
}
.Ed
.Pp
Theme Example:
.Pp
.Bd -literal -offset indent -compact
struct bsddialog_conf conf;
struct bsddialog_theme theme;

bsddialog_init();

bsddialog_initconf(&conf);
bsddialog_msgbox(&conf, "Default theme", 7, 25);

bsddialog_get_theme(&theme);
theme.screen.color = bsddialog_color(BSDDIALOG_RED, BSDDIALOG_GREEN,
    BSDDIALOG_BOLD);
bsddialog_set_theme(&theme);
bsddialog_backtitle(&conf, "Red foreground and Green background");
bsddialog_msgbox(&conf, "Change screen color", 7, 25);

bsddialog_set_default_theme(BSDDIALOG_THEME_BLACKWHITE);
bsddialog_msgbox(&conf, "Black and White theme", 7, 25);

bsddialog_end();
.Ed
.Pp
Mixedlist Example:
.Pp
.Bd -literal -offset indent -compact
unsigned int i, j;
struct bsddialog_conf conf;
struct bsddialog_menuitem item;
struct bsddialog_menuitem check[2] = {
    { "1", true,  0, "Name 1", "Desc 1", "Check Bottom Desc 1" },
    { "2", false, 0, "Name 2", "Desc 2", "Check Bottom Desc 2" }
};
struct bsddialog_menuitem sep[1] = {
    { "3", true, 0, "Radiolist", "(desc)", "" }
};
struct bsddialog_menuitem radio[2] = {
    { "4", true,  0, "Name 1", "Desc 1", "Radio Bottom Desc 1" },
    { "5", false, 0, "Name 2", "Desc 2", "Radio Bottom Desc 2" }
};
struct bsddialog_menugroup group[3] = {
    { BSDDIALOG_CHECKLIST, 2, check },
    { BSDDIALOG_SEPARATOR, 1, sep   },
    { BSDDIALOG_RADIOLIST, 2, radio }
};

bsddialog_init();
bsddialog_initconf(&conf);
bsddialog_mixedlist(&conf, "Example", 20, 30, 11, 3, group, NULL,
    NULL);
bsddialog_end();

for (i = 0; i < 3; i++) {
	for (j = 0; j < group[i].nitems; j++) {
		item = group[i].items[j];
		switch (item.type) {
		case BSDDIALOG_SEPARATOR:
			printf("---- %s ----\\n", item.name);
			break;
		case BSDDIALOG_RADIOLIST:
			printf(" (%c) %s\\n",
			    item.on ? '*' : ' ', item.name);
			break;
		case BSDDIALOG_CHECKLIST:
			printf(" [%c] %s\\n",
			    item.on ? 'X' : ' ', item.name);
			break;
		}
	}
}
.Ed
.Sh SEE ALSO
.Xr bsddialog 1 ,
.Xr curses 3
.Sh HISTORY
The
.Nm bsddialog
library first appeared in
.Fx 14.0 .
.Sh AUTHORS
.Nm bsddialog
was written by
.An Alfonso Sabato Siciliano Aq Mt asiciliano@FreeBSD.org .