Skip to content

Latest commit

 

History

History
69 lines (59 loc) · 2.66 KB

wsdialog.org

File metadata and controls

69 lines (59 loc) · 2.66 KB

wsdialog

Description

Display a dialog, depending on input display warnings

Variables

Parameters:

  • dialog: dialog name string identifier
  • line4: identifier of message/warning to be displayed when the

dialog input cannot be accepted

User defined variables and functions

Dialog functions

  • wsdialog_${dialog}_msg: prompt message
  • wsdialog_${dialog}_accept: function called on ^M (accept), sets

wsdialog_mode to empty if accepted or to a name of a dialog mode $wsdialog_text holds the prompt input. Returns the selected mode in the $wsdialog_l4mode variable.

  • wsdialog_${dialog}_restore: function called after accept/cancel/undo,

to restore the state after exiting the dialog

Line4 functions

  • wsdialog_${dialog}_${line4}_msg: prompt message
  • wsdialog_${dialog]_${line4}_funcs: associative array of keybindings

to the functions that are bound to the keybindings, must be declared with declare -A <funcs array>

zle modes defined by zwsh

  • wsdialog_${dialog}_mode: name of the zle mode
  • wsdialog_${dialog}_${line4}_mode: name of the zle mode

Global behaviour rules

  • ^M is always bound to accept
  • ^U is the default cancel key, for the dialog modes it removes the

dialog and restores the state before the dialog, and for line4 modes it removes the line4 and returns to the prompt in order to restore the state before ^M was pressed. These rules do not have to be followed strictly, for example if the state was modified in such a way that it would be a problem to restore it. The purpose of the dialogs is to get the string from the prompt, therefore the user do not have to know whether it was exited through accept or cancel, the most important thing is the string entered by the user.

Usage

  • Declare the necessary variables
  • Call wsdialog-add $dialog, where $dialog is the name of the dialog
  • When in a line4 event function: define $wsdialog_l4mode in order to

tell what should be done after this event. The value can be either the name of another line4 mode, or a constant:

  • <accept>: accepts the prompt value and exit dialog
  • <cancel>: exit dialog with empty result (same as ^U in dialog mode)

It also can be undefined, in which case the line4 is removed and the cursor is moved to the position where it was before entering line4 mode.

The dialog

<message>: <enter text>
 *RETURN* done | *Backspace* or *^H* erase left
  *^U* cancel  |       *Del* or *^G* erase char
<Line4>

The dialog as well as the messages defined by the user can contain formatting defined by *bold text*, #standout text#, _underline text_.