bash - Toggleable nconf-like menu from command output -


i'm trying create following kind of nconf-like space-toggleable menu:

[*] 1st item [*] 2nd 1 [ ] 3rd 1 [*] 4th 1 

the items should created according output of command in script.

you want use dialog (or whiptail; similar) --checklist widget.

here's example command:

options=$(   dialog 2>&1 1>/dev/tty \          --keep-tite \          --checklist "dialog title" 20 120 4 \          tag1 "1st item" on \          tag2 "2nd item" off \          tag3 "3rd item" off \          tag4 "4th item" on ) 

the end result $options contain list of tag values selected items. taking command apart:

dialog uses stdout write terminal , writes own output (the list of selected tags) stderr. that's bit awkward scripting; $(...) construct redirects stdout pipe bash can read from. duplicate pipe stdout stderr (2>&1) final output captured, , set stdout terminal (2>/dev/tty)

  dialog 2>&1 1>/dev/tty \ 

--keep-tite dialog-specific; causes dialog use "alternate screen", means once widget finished, display restored. try , without if wasn't clear.

         --keep-tite \ 

the first 4 arguments after --checklist windows's title, height , width, , menu height (which same number of items)

         --checklist "dialog title" 20 120 4 \ 

the rest of arguments in sets of three: tag (which should not have whitespace or shell metacharacters) used identify selected options; actual text displayed; , indication of whether option selected or not.

         tag1 "1st item" on \          tag2 "2nd item" off \          tag3 "3rd item" off \          tag4 "4th item" on 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -