aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-05-30 21:02:59 +0200
committerGravatar Tom Willemse2013-05-30 21:02:59 +0200
commit6e73d176507a806b1f11bcc1b7f56ea60371f1bd (patch)
tree61a4f061154ce169c703cca36c710262d8142fc2
parentdc842516b0388548442f93aa31d529a02ed2b76c (diff)
downloadcdispass-6e73d176507a806b1f11bcc1b7f56ea60371f1bd.tar.gz
cdispass-6e73d176507a806b1f11bcc1b7f56ea60371f1bd.zip
Make sure an element is focused
Also fix up the docstrings.
-rw-r--r--cdispass.js53
1 files changed, 35 insertions, 18 deletions
diff --git a/cdispass.js b/cdispass.js
index 62e8ee9..adb601e 100644
--- a/cdispass.js
+++ b/cdispass.js
@@ -86,25 +86,42 @@ function dispass_complete(input, pos, conservative)
}
}
-function dispass_interactive(I) {
- let label = yield I.minibuffer.read($prompt="label:",
- $auto_complete=true,
- $completer=dispass_complete);
-
- I.minibuffer.input_element.type = "password";
- let password = yield I.minibuffer.read(
- $prompt="password:"
- );
- I.minibuffer.input_element.type = "";
-
- I.buffer.focused_element.value = (yield dispass(label, password));
+function dispass_interactive(with_submit) {
+ return function (I) {
+ if (!I.buffer.focused_element) {
+ I.minibuffer.message("No input selected.");
+ yield co_return(null);
+ }
+
+ let label = yield I.minibuffer.read(
+ $prompt="label:", $auto_complete=true,
+ $completer=dispass_complete
+ );
+
+ I.minibuffer.input_element.type = "password";
+ let password = yield I.minibuffer.read(
+ $prompt="password:"
+ );
+ I.minibuffer.input_element.type = "";
+
+ I.buffer.focused_element.value =
+ (yield dispass(label, password));
+
+ if (with_submit)
+ I.buffer.focused_element.form.submit();
+ };
}
-interactive("dispass", "Something", dispass_interactive);
-interactive("dispass-and-submit", "Something",
- function (I) {
- yield dispass_interactive(I);
- I.buffer.focused_element.form.submit();
- });
+interactive("dispass",
+ "Call DisPass to generate a passphrase.\n"
+ + "\n"
+ + "Put the result in the currently focused input.",
+ dispass_interactive(false));
+interactive("dispass-and-submit",
+ "Call Dispass to generate a passphrase.\n"
+ + "\n"
+ + "Put the result in the currently focused input and"
+ + " submit the input's form.",
+ dispass_interactive(true));
provide("cdispass");