1 require("minibuffer-read.js");
3 function or_string(options) {
4 return options.slice(0,options.length-1).join(", ") + " or " + options[options.length - 1];
7 define_keywords("$options");
8 minibuffer.prototype.read_explicit_option = function () {
10 var options = arguments.$options;
11 var options_string = or_string(options);
12 var result = yield this.read(forward_keywords(arguments),
13 $prompt = arguments.$prompt + " (" + options_string + ")",
14 $validator = function (x, m) {
15 if (options.indexOf(x) == -1) {
16 m.message("Please answer " + options_string + ".");
23 yield co_return(result);
26 minibuffer.prototype.read_yes_or_no = function () {
28 var result = yield this.read_explicit_option(forward_keywords(arguments), $options = ["yes", "no"]);
29 yield co_return(result == "yes");
32 function single_character_options_minibuffer_state(continuation) {
34 this.continuation = continuation;
35 this.options = arguments.$options;
36 minibuffer_input_state.call(this, single_character_options_minibuffer_keymap, arguments.$prompt);
38 single_character_options_minibuffer_state.prototype = {
39 __proto__: minibuffer_input_state.prototype,
40 destroy: function () {
41 if (this.continuation)
42 this.continuation.throw(abort());
45 function single_character_options_enter_character(window, s, event) {
46 var ch = String.fromCharCode(event.charCode);
47 if (s.options.indexOf(ch) != -1) {
48 var c = s.continuation;
49 delete s.continuation;
50 window.minibuffer.pop_state();
55 var str = "Please answer " + or_string(s.options) + ".";
56 window.minibuffer.message(str);
59 interactive("single-character-options-enter-character",
61 single_character_options_enter_character(
63 I.minibuffer.check_state(single_character_options_minibuffer_state),
67 minibuffer.prototype.read_single_character_option = function () {
69 var s = new single_character_options_minibuffer_state((yield CONTINUATION), forward_keywords(arguments));
71 var result = yield SUSPEND;
72 yield co_return(result);