2 * (C) Copyright 2008 Jeremy Maitin-Shepard
4 * Use, modification, and distribution are subject to the terms specified in the
8 require("minibuffer-read.js");
10 function or_string(options) {
11 return options.slice(0,options.length-1).join(", ") + " or " + options[options.length - 1];
14 define_keywords("$options");
15 minibuffer.prototype.read_explicit_option = function () {
17 var options = arguments.$options;
18 var options_string = or_string(options);
19 var result = yield this.read(forward_keywords(arguments),
20 $prompt = arguments.$prompt + " (" + options_string + ")",
21 $validator = function (x, m) {
22 if (options.indexOf(x) == -1) {
23 m.message("Please answer " + options_string + ".");
30 yield co_return(result);
33 minibuffer.prototype.read_yes_or_no = function () {
35 var result = yield this.read_explicit_option(forward_keywords(arguments), $options = ["yes", "no"]);
36 yield co_return(result == "yes");
39 function single_character_options_minibuffer_state(continuation) {
41 this.continuation = continuation;
42 this.options = arguments.$options;
43 minibuffer_input_state.call(this, single_character_options_minibuffer_keymap, arguments.$prompt);
45 single_character_options_minibuffer_state.prototype = {
46 __proto__: minibuffer_input_state.prototype,
47 destroy: function () {
48 if (this.continuation)
49 this.continuation.throw(abort());
52 function single_character_options_enter_character(window, s, event) {
53 var ch = String.fromCharCode(event.charCode);
54 if (s.options.indexOf(ch) != -1) {
55 var c = s.continuation;
56 delete s.continuation;
57 window.minibuffer.pop_state();
62 var str = "Please answer " + or_string(s.options) + ".";
63 window.minibuffer.message(str);
66 interactive("single-character-options-enter-character", null,
68 single_character_options_enter_character(
70 I.minibuffer.check_state(single_character_options_minibuffer_state),
74 minibuffer.prototype.read_single_character_option = function () {
76 var s = new single_character_options_minibuffer_state((yield CONTINUATION), forward_keywords(arguments));
78 var result = yield SUSPEND;
79 yield co_return(result);