“Universal” Widgets
Introduction
Short Text Widget
Type:
Value:
- single-line text.
Behavior:
- Press
<ret>
to submit.
HTML:
Emacs
:
(read-string "Name :")
CLI (Prompting):
#!/bin/sh
printf "Name: "
read NAME
LENGTH=$(printf "%s\n" ${NAME} | wc -m)
printf "Name Length: %d\n" ${LENGTH}
# POSIX-conformant
Examples:
- —
Links:
- <>
- <>
Long Text Widget
Type:
Value:
- multi-line text.
Behavior:
- Full Editing —
<ret>
is newline (i.e. doesn’t submit): for HTML, by default, click a “Submit”<button>
; for Emacs, by default, pressC-c C-c
; with a custom widget, press<ret>
twice; with a custom widget, press<S-ret>
.
HTML:
Emacs
:
(read-buffer? "Text :")
CLI (Completion):
Examples:
magit.el
— edit the git commit message.
Links:
- <>
- <>
Secret Text Widget
i.e. Password Input.
Type:
Value:
- text which is secret.
Behavior:
- MUST NOT echo input
- May echo input length (e.g. print a
*
for each character entered). - Press
<ret>
to submit.
HTML:
Emacs
:
(read-passwors "Password :") TODO
CLI (Prompting):
#!/bin/sh
stty -echo
printf "Password: "
read PASSWORD
stty echo
LENGTH=$(printf "%s\n" ${PASSWORD} | wc -m)
printf "Password Length: %d\n" ${LENGTH}
# POSIX-conformant
Examples:
- —
Links:
- <>
- <>
Choices Widget
i.e. a Checklist.
Type:
Value:
Behavior:
HTML
:
Emacs (Minibuffer):
(TODO)
Emacs (Widget):
(widget-create)
Examples:
- —
Links:
- <>
- <>
Choice Widget (for few choices)
i.e. a Radio-Group.
Type:
Value:
- one choice, from a set of choices
Behavior:
- Press a single key.
- Click a single button.
HTML
:
<input type="radio">
< label="Google Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
<option value="Microsoft Edge">
Emacs
:
(read-choice-
CLI (Prompting):
Examples:
- —
Links:
- <>
Choice Widget (for many choices)
i.e. a “Finite-List”.
Type:
Value:
- one choice, from a set of choices
Behavior:
- Completion (possibly)
- Defaulting (possibly)
- Vertical Navigation (possibly)
HTML
:
<!-- the chooser: -->
<label for="myBrowser">Choose a browser from this list:</label>
<input list="browsers" id="myBrowser" name="myBrowser" />
<!-- the choices: -->
<datalist id="browsers">
<option value="Google Chrome">
<option value="Firefox">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
<option value="Microsoft Edge">
</datalist>
Emacs
:
(let ((CHOICES '(
"Google Chrome"
"Firefox"
"Internet Explorer"
"Opera"
"Safari"
"Microsoft Edge"
)))
(completing-read "Browser: " CHOICES))
CLI (Completion):
$ IFS="\n" compgen ... -W <<<EOF
"Google Chrome"
"Firefox"
"Internet Explorer"
"Opera"
"Safari"
"Microsoft Edge"
EOF
Representation (must match):
data Browser
= Firefox
| GoogleChrome
| InternetExplorer
| Opera
| Safari
| MicrosoftEdge
deriving ( Enum, Bounded, ... )
Representation (free text):
type Browser = Either UnknownBrowser KnownBrowser
--
data KnownBrowser
= Firefox
| GoogleChrome
| InternetExplorer
| Opera
| Safari
| MicrosoftEdge
deriving ( Enum, Bounded, ... )
--
newtype UnknownBrowser = UnknownBrowser String
deriving ( IsString, ... )
Examples:
- —
Links:
File Widget
i.e. a File-Chooser.
Type:
Value:
- one filepath, from a set of choices.
- regular-only (possibly) or "directory-only*(possibly).
- must-exist (possibly) or can’t-exist (possibly).
Behavior:
- Vertical Navigation (possibly) between the directory contents
- Horizontal Navigation (possibly) between returning to the parent directory or descending into subdirectories.
HTML
:
read-file-name
(Emacs
): (read-file-name PROMPT &optional DIR DEFAULT-FILENAME MUSTMATCH INITIAL PREDICATE)
(a.k.a C-x C-f)
(read-file-name "Open File: " default-directory nil t)
(read-file-name "Open Directory: " )
(read-file-name "New File: " )
(defun sboo-elisp-filename-p (filename)
(match filename (rx ".el" eos))) ;TODO
(read-file-name "Open File: " default-directory nil nil nil #'sboo-elisp-filename-p))
CLI (Completion):
Examples:
- —
Links:
- <>
- <>