-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlibbash_gui.sh
1545 lines (1279 loc) · 30.6 KB
/
libbash_gui.sh
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
########################################################
# #
# libbash.sh GUI #
# Functions to extend bash scripts to GUI tools #
# #
# MIT License #
# Copyright (c) 2017-2022 Jean Prunneaux #
# Website: https://github.com/pruje/libbash.sh #
# #
# Version 1.21.0 (2022-06-03) #
# #
########################################################
# Index
#
# * Internal functions
# lbg__get_console_size
# lbg__dialog_size
# lbg__osascript
# lbg__cscript
# lbg__powershell
# lbg__display_msgbox
# * GUI tools
# lbg_get_gui
# lbg_set_gui
# * Messages and notifications
# lbg_display_info
# lbg_display_warning
# lbg_display_error
# lbg_notify
# * User interaction
# lbg_yesno
# lbg_choose_option
# lbg_input_text
# lbg_input_password
# * Files and directories
# lbg_choose_directory
# lbg_choose_file
# lbg_open_directory
# * Aliases and compatibility
# lbg_display_critical
# lbg_critical
# lbg_display_debug
# lbg_debug
# lbg_info
# lbg_warning
# lbg_error
# * Initialization
##################################
# INTERNAL FUNCTIONS #
# DO NOT PUBLISH DOCUMENTATION #
##################################
# Get console size and update lbg__console_width and lbg__console_height variables
# Usage: lbg__get_console_size
# Exit codes:
# 0: OK
# 1: No terminal available
lbg__get_console_size() {
# get console width and height
lbg__console_width=$(tput cols 2> /dev/null)
lbg__console_height=$(tput lines 2> /dev/null)
# if error (script not running in a terminal)
if [ -z "$lbg__console_width" ] || [ -z "$lbg__console_height" ] ; then
return 1
fi
}
# Set dialog size to fit console
# Usage: lbg__dialog_size MAX_WIDTH MAX_HEIGHT
# Return: HEIGHT WIDTH
# e.g. dialog --msgbox "Hello world" $(lbg__dialog_size 50 10)
lbg__dialog_size() {
# given size
local dialog_width=$1 dialog_height=$2
# if max width > console width, fit to console width
if [ "$dialog_width" -gt "$lbg__console_width" ] ; then
dialog_width=$lbg__console_width
fi
# if max height > console height, fit to console height
if [ "$dialog_height" -gt "$lbg__console_height" ] ; then
dialog_height=$lbg__console_height
fi
# return height width
echo $dialog_height $dialog_width
}
# Run osascript command
# Usage: lbg__osascript COMMAND
lbg__osascript() {
osascript 2> /dev/null <<EOF
$*
EOF
}
# Run cscript command
# Usage: lbg__cscript COMMAND
lbg__cscript() {
# must be ran in relative path context
(cd "$lb_directory/inc" && cscript /NoLogo libbash_gui.vbs "$@")
}
# Run powershell command
# Usage: lbg__powershell COMMAND
lbg__powershell() {
powershell -ExecutionPolicy ByPass -File "$(cygpath -w "$lb_directory"/inc/libbash_gui.ps1)" "$@"
}
# Display message box
# Usage: lbg__display_msgbox TYPE [OPTIONS] TEXT
lbg__display_msgbox() {
# default options
local type=$1 title=$lb_current_script_name
shift
# get options
while [ $# -gt 0 ] ; do
case $1 in
-t|--title)
[ -z "$2" ] && return 1
title=$2
shift
;;
*)
break
;;
esac
shift # load next argument
done
local text=$*
# get text from stdin
if [ ${#text} = 0 ] ; then
if ! [ -t 0 ] ; then
local t
while read -r t ; do
text+="
$t"
done
# delete first line jump
text=${text:1}
fi
fi
# usage error if no text
[ ${#text} = 0 ] && return 1
# prepare command
local cmd
case $lbg__gui in
kdialog)
cmd=(kdialog --title "$title")
case $type in
error)
cmd+=(--error)
;;
warning)
cmd+=(--sorry)
;;
*)
# default: info
cmd+=(--msgbox)
;;
esac
cmd+=("$text")
;;
zenity)
cmd=(zenity --title "$title")
case $type in
error)
cmd+=(--error)
;;
warning)
cmd+=(--warning)
;;
*)
# default: info
cmd+=(--info)
;;
esac
cmd+=(--text "$text")
;;
osascript)
local icon
case $type in
error)
icon=stop
;;
warning)
icon=caution
;;
*)
# default: info
icon=note
;;
esac
# run command
lbg__osascript "display dialog \"$text\" with title \"$title\" with icon $icon buttons {\"$lb__ok_label\"} default button 1" &> /dev/null || return 2
return 0
;;
cscript)
cmd=(lbg__cscript lbg_display_$type "$(echo -e "$text")" "$title")
;;
dialog)
local result=0 prefix
case $type in
error)
prefix="$lb__error_label: "
;;
warning)
prefix="$lb__warning_label: "
;;
esac
dialog --title "$title" --clear --msgbox "$prefix$text" $(lbg__dialog_size 50 10) 2> /dev/null || result=$?
# clear console
clear
# command error
[ $result != 0 ] && return 2
return 0
;;
*)
# console mode
cmd=(lb_display_$type "$text")
;;
esac
# run command
"${cmd[@]}" 2> /dev/null || return 2
}
###############
# GUI TOOLS #
###############
# Get current GUI tool
# Usage: lbg_get_gui
lbg_get_gui() {
# no GUI tool defined
[ -z "$lbg__gui" ] && return 1
# return current GUI tool
echo $lbg__gui
}
# Set GUI display to use
# Usage: lbg_set_gui [GUI_TOOL...]
lbg_set_gui() {
# default options
local gui_tools=("${lbg__supported_gui[@]}") result=0
# if args set, test list of commands
[ $# -gt 0 ] && gui_tools=("$@")
# test GUI tools
local gui
for gui in "${gui_tools[@]}" ; do
# set console mode is always OK
if [ "$gui" = console ] ; then
result=0
break
fi
# test if GUI is supported
if ! lb_in_array "$gui" "${lbg__supported_gui[@]}" ; then
result=1
continue
fi
# test if command exists
if ! which "$gui" &> /dev/null ; then
result=3
continue
fi
# dialog command
case $gui in
dialog)
# get console size
if ! lbg__get_console_size ; then
result=4
continue
fi
;;
osascript)
# test OS
if [ "$lb_current_os" != macOS ] ; then
result=4
continue
fi
;;
cscript)
# test OS
if [ "$lb_current_os" != Windows ] ; then
result=4
continue
fi
# test VB script
if ! [ -f "$lb_directory"/inc/libbash_gui.vbs ] ; then
result=4
continue
fi
# test PowerShell script
if ! [ -f "$lb_directory"/inc/libbash_gui.ps1 ] ; then
result=4
continue
fi
;;
*)
# test if X server started (not for macOS)
if [ "$lb_current_os" != macOS ] && [ -z "$DISPLAY" ] ; then
result=4
continue
fi
;;
esac
# all tests passed: tool can be set
result=0
break
done
# set gui tool
[ $result = 0 ] && lbg__gui=$gui
return $result
}
################################
# MESSAGES AND NOTIFICATIONS #
################################
# Display an info dialog
# Usage: lbg_display_info [OPTIONS] TEXT
lbg_display_info() {
lbg__display_msgbox info "$@"
}
# Display a warning message
# Usage: lbg_display_warning [OPTIONS] TEXT
lbg_display_warning() {
lbg__display_msgbox warning "$@"
}
# Display an error message
# Usage: lbg_display_error [OPTIONS] TEXT
lbg_display_error() {
lbg__display_msgbox error "$@"
}
# Display a notification popup
# Usage: lbg_notify [OPTIONS] TEXT
lbg_notify() {
# default options
local timeout use_notifysend=true title=$lb_current_script_name
# get options
while [ $# -gt 0 ] ; do
case $1 in
-t|--title)
[ -z "$2" ] && return 1
title=$2
shift
;;
--timeout)
[[ $2 =~ ^-?[0-9]+$ ]] || return 1
timeout=$2
shift
;;
--no-notify-send)
# do not use notify-send command if available
use_notifysend=false
;;
*)
break
;;
esac
shift # load next argument
done
local text=$*
# get text from stdin
if [ ${#text} = 0 ] ; then
if ! [ -t 0 ] ; then
local t
while read -r t ; do
text+="
$t"
done
# delete first line jump
text=${text:1}
fi
fi
# usage error if no text
[ ${#text} = 0 ] && return 1
local opts
# if notify-send is installed, use it by default,
# as it is better than zenity or other system
if $use_notifysend && which notify-send &> /dev/null ; then
# do not override kdialog because it has the best integration to KDE desktop
# do not use it on macOS nor in console mode
if ! lb_in_array "$lbg__gui" kdialog osascript console ; then
# execute command with timeout in milliseconds
[ -n "$timeout" ] && opts="-t $(($timeout * 1000)) "
# push notification and return
notify-send $opts"$title" "$text" || return 2
return 0
fi
fi
# run command
case $lbg__gui in
kdialog)
kdialog --title "$title" --passivepopup "$text" $timeout 2> /dev/null || return 2
;;
zenity)
# set a timeout
[ -n "$timeout" ] && opts="--timeout=$timeout"
# run command
zenity --notification $opts --text "$text" 2> /dev/null || return 2
;;
osascript)
lbg__osascript "display notification \"$text\" with title \"$title\"" &> /dev/null || return 2
;;
cscript)
lbg__powershell send-notification "$text" "$title" || return 2
;;
# dialog: nothing, because it doesn't make sense in console
*)
# print in console mode
lb_display "[$lb__info_label] $text" || return 2
;;
esac
}
######################
# USER INTERACTION #
######################
# Prompt user to confirm an action
# Usage: lbg_yesno [OPTIONS] TEXT
# SOME OPTIONS ARE NOT AVAILABLE ON WINDOWS
lbg_yesno() {
# default options
local yes_label no_label yes_default=false title=$lb_current_script_name
# get options
while [ $# -gt 0 ] ; do
case $1 in
-y|--yes)
yes_default=true
;;
--yes-label)
[ -z "$2" ] && return 1
yes_label=$2
shift
;;
--no-label)
[ -z "$2" ] && return 1
no_label=$2
shift
;;
-t|--title)
[ -z "$2" ] && return 1
title=$2
shift
;;
*)
break
;;
esac
shift # load next argument
done
# usage error if no text to display
[ -z "$1" ] && return 1
local cmd result=0
# prepare command
case $lbg__gui in
kdialog)
cmd=(kdialog --title "$title")
[ -n "$yes_label" ] && cmd+=(--yes-label "$yes_label")
[ -n "$no_label" ] && cmd+=(--no-label "$no_label")
cmd+=(--yesno "$*")
;;
zenity)
cmd=(zenity --question --title "$title" --text "$*")
;;
osascript)
# set button labels
[ -z "$yes_label" ] && yes_label=$lb__yes_label
[ -z "$no_label" ] && no_label=$lb__no_label
# set options
local default_button=2
$yes_default && default_button=1
# run command
result=$(lbg__osascript "set question to (display dialog \"$*\" with title \"$title\" buttons {\"$yes_label\", \"$no_label\"} default button $default_button)
set answer to button returned of question
if answer is equal to \"$yes_label\" then
return 0
else
return 2
end if")
# return choice
return $result
;;
cscript)
cmd=(lbg__cscript lbg_yesno "$(echo -e "$*")" "$title")
$yes_default && cmd+=(true)
;;
dialog)
cmd=(dialog --title "$title")
$yes_default || cmd+=(--defaultno)
[ -n "$yes_label" ] && cmd+=(--yes-label "$yes_label")
[ -n "$no_label" ] && cmd+=(--no-label "$no_label")
cmd+=(--clear --yesno "$*" $(lbg__dialog_size 100 10))
# run command
"${cmd[@]}" || result=$?
# clear console
clear
# return result
case $result in
0)
return 0
;;
255)
# cancelled
return 3
;;
*)
return 2
;;
esac
;;
*)
# console mode
cmd=(lb_yesno)
$yes_default && cmd+=(-y)
[ -n "$yes_label" ] && cmd+=(--yes-label "$yes_label")
[ -n "$no_label" ] && cmd+=(--no-label "$no_label")
cmd+=("$*")
;;
esac
# run command
"${cmd[@]}" 2> /dev/null || return 2
}
# Ask user to choose one or multiple options
# Usage: lbg_choose_option [OPTIONS] CHOICE [CHOICE...]
lbg_choose_option=()
lbg_choose_option() {
# reset result
lbg_choose_option=()
# default options
local default=() multiple_choices=false
local title=$lb_current_script_name label=$lb__chopt_label
# get options
while [ $# -gt 0 ] ; do
case $1 in
-d|--default)
[ -z "$2" ] && return 1
# transform option1,option2,... to array
lb_split , $2
default=(${lb_split[@]})
shift
;;
-m|--multiple)
multiple_choices=true
;;
-l|--label)
[ -z "$2" ] && return 1
label=$2
shift
;;
-t|--title)
[ -z "$2" ] && return 1
title=$2
shift
;;
*)
break
;;
esac
shift # load next argument
done
# usage error if missing at least 1 choice option
[ -z "$1" ] && return 1
# verify if default options are valid
if [ ${#default[@]} -gt 0 ] ; then
local d
for d in "${default[@]}" ; do
[[ $d =~ ^-?[0-9]+$ ]] || return 1
if [ $d -lt 1 ] || [ $d -gt $# ] ; then
return 1
fi
done
else
# one choice: initialize first choice as default (except for console mode)
if ! $multiple_choices && [ "$lbg__gui" != console ] ; then
default=(1)
fi
fi
# change default label if multiple options
if $multiple_choices ; then
[ "$label" = "$lb__chopt_label" ] && label=$lb__chopts_label
fi
local o choices cmd
local -i i=1
case $lbg__gui in
kdialog)
cmd=(kdialog --title "$title")
if $multiple_choices ; then
cmd+=(--checklist)
else
cmd+=(--radiolist)
fi
cmd+=("$label")
# add options
for o in "$@" ; do
cmd+=($i "$o")
if lb_in_array $i "${default[@]}" ; then
cmd+=(on)
else
cmd+=(off)
fi
i+=1
done
# run command
choices=$("${cmd[@]}" 2> /dev/null)
# multiple choices: transform '"1" "3"' to '1 3'
choices=$(echo $choices | sed 's/"//g')
;;
zenity)
cmd=(zenity --list --title "$title" --text "$label" --column "" --column "" --column "")
if $multiple_choices ; then
cmd+=(--checklist)
else
cmd+=(--radiolist)
fi
# add options
for o in "$@" ; do
if lb_in_array $i "${default[@]}" ; then
cmd+=(TRUE)
else
cmd+=(FALSE)
fi
cmd+=($i "$o")
i+=1
done
# run command
choices=$("${cmd[@]}" 2> /dev/null)
# multiple choices: transform '1|3' to '1 3'
choices=$(echo $choices | sed 's/|/ /g')
;;
osascript)
# prepare options
local default_options=() multiple_option opts=()
# security: remove comas and spaces
for o in "$@" ; do
o=$(echo "$o" | sed 's/,//g' | lb_trim)
opts+=("\"$o\"")
# set default option
lb_in_array $i "${default[@]}" && default_options+=("\"$o\"")
i+=1
done
# add multiple choice option
$multiple_choices && multiple_option="with multiple selections allowed"
# execute command
local choice=$(lbg__osascript "set answer to (choose from list {$(lb_join , "${opts[@]}")} $multiple_option default items {$(lb_join , "${default_options[@]}")} with prompt \"$label\" with title \"$title\")")
# if empty, error
[ -z "$choice" ] && return 2
# split choices
lb_split , "$choice"
# find choice IDs
for c in "${lb_split[@]}" ; do
i=1
for o in "${opts[@]}" ; do
if [ "\"$(lb_trim "$c")\"" = "$o" ] ; then
choices+="$i "
break
fi
i+=1
done
done
;;
cscript)
# avoid \n in label
label=$(echo -e "$label")
# add options to the label, with a line return between each option
for o in "$@" ; do
label+=$(echo -e "\n $i. $o")
i+=1
done
# avoid empty default values (if multiple choices)
[ ${#default[@]} = 0 ] && default=(1)
choices=$(lbg__cscript lbg_input_text "$label" "$title" "${default[*]}") || return 2
# multiple choices: transform '1,3' to '1 3'
# and remove \r ending character
choices=$(echo $choices | sed 's/,/ /g; s/[[:space:]]*$//')
;;
dialog)
cmd=(dialog --title "$title" --clear)
if $multiple_choices ; then
cmd+=(--checklist)
else
cmd+=(--radiolist)
fi
cmd+=("$label" $(lbg__dialog_size 100 30) 1000)
# add options
for o in "$@" ; do
cmd+=($i "$o")
if lb_in_array $i "${default[@]}" ; then
cmd+=(on)
else
cmd+=(off)
fi
i+=1
done
# run command (complex case)
exec 3>&1
choices=$("${cmd[@]}" 2>&1 1>&3)
exec 3>&-
# clear console
clear
;;
*)
# console mode
cmd=(lb_choose_option -l "$label")
$multiple_choices && cmd+=(-m)
# add default choice(s)
[ ${#default[@]} -gt 0 ] && cmd+=(-d "$(lb_join , "${default[@]}")")
# execute console function and forward result
"${cmd[@]}" "$@" && choices=${lb_choose_option[*]}
;;
esac
# if empty, cancelled
[ -z "$choices" ] && return 2
# parsing choices
for o in ${choices[*]} ; do
# strict check type
if ! [[ $o =~ ^-?[0-9]+$ ]] ; then
lb_choose_option=()
return 3
fi
# check if user choice is valid
if [ $o -lt 1 ] || [ $o -gt $# ] ; then
lbg_choose_option=()
return 3
fi
# save choice
lbg_choose_option+=("$o")
done
}
# Ask user to enter a text
# Usage: lbg_input_text [OPTIONS] TEXT
lbg_input_text=""
lbg_input_text() {
# reset result
lbg_input_text=""
# default options
local default title=$lb_current_script_name
# get options
while [ $# -gt 0 ] ; do
case $1 in
-d|--default)
[ -z "$2" ] && return 1
default=$2
shift
;;
-t|--title)
[ -z "$2" ] && return 1
title=$2
shift
;;
*)
break
;;
esac
shift # load next argument
done
# usage error if no text to display
[ -z "$1" ] && return 1
# run command
local cmd
case $lbg__gui in
kdialog)
lbg_input_text=$(kdialog --title "$title" --inputbox "$*" "$default" 2> /dev/null)
;;
zenity)
lbg_input_text=$(zenity --entry --title "$title" --entry-text "$default" --text "$*" 2> /dev/null)
;;
osascript)
lbg_input_text=$(lbg__osascript "set answer to the text returned of (display dialog \"$*\" with title \"$title\" default answer \"$default\")")
;;
cscript)
# prepare command
cmd=(lbg_input_text "$(echo -e "$*")" "$title")
[ -n "$default" ] && cmd+=("$default")
lbg_input_text=$(lbg__cscript "${cmd[@]}") || return 2
# remove \r ending character
lbg_input_text=${lbg_input_text:0:${#lbg_input_text}-1}
;;
dialog)
# run command (complex case)
exec 3>&1
lbg_input_text=$(dialog --title "$title" --clear --inputbox "$*" $(lbg__dialog_size 100 10) "$default" 2>&1 1>&3)
exec 3>&-
# clear console
clear
;;
*)
# console mode
cmd=(lb_input_text)
[ -n "$default" ] && cmd+=(-d "$default")
cmd+=("$*")
# execute console function and forward result
"${cmd[@]}" && lbg_input_text=$lb_input_text
;;
esac
# if empty, return cancelled
[ -n "$lbg_input_text" ] || return 2
}
# Ask user to enter a password
# Usage: lbg_input_password [OPTIONS] [TEXT]
lbg_input_password=""
lbg_input_password() {
# reset result
lbg_input_password=""
# default options
local label=$lb__pwd_label confirm_label=$lb__pwd_confirm_label
local title=$lb_current_script_name confirm=false min_size=0
# get options
while [ $# -gt 0 ] ; do
case $1 in
-l|--label) # old option kept for compatibility
[ -z "$2" ] && return 1
label=$2
shift
;;
-c|--confirm)
confirm=true
;;
--confirm-label)
[ -z "$2" ] && return 1
confirm_label=$2
shift
;;
-m|--min-size)
[[ $2 =~ ^-?[0-9]+$ ]] || return 1
[ $2 -lt 1 ] && return 1
min_size=$2
shift
;;
-t|--title)
[ -z "$2" ] && return 1
title=$2
shift
;;
*)
break
;;
esac
shift # load next argument
done
# text label
[ -n "$*" ] && label=$*
# display dialog
local i result=0
for i in 1 2 ; do
# run command
case $lbg__gui in
kdialog)
lbg_input_password=$(kdialog --title "$title" --password "$label" 2> /dev/null)
;;