2 * (C) Copyright 2008 Jeremy Maitin-Shepard
3 * (C) Copyright 2009-2010 John J. Foerch
5 * Use, modification, and distribution are subject to the terms specified in the
9 require("minibuffer-read.js");
11 define_keywords("$options");
12 minibuffer.prototype.read_explicit_option = function () {
14 var options = arguments.$options;
15 var options_string = or_string(options);
16 var result = yield this.read(forward_keywords(arguments),
17 $prompt = arguments.$prompt + " (" + options_string + ")",
18 $validator = function (x, m) {
19 if (options.indexOf(x) == -1) {
20 m.message("Please answer " + options_string + ".");
27 yield co_return(result);
30 minibuffer.prototype.read_yes_or_no = function () {
32 var result = yield this.read_explicit_option(forward_keywords(arguments), $options = ["yes", "no"]);
33 yield co_return(result == "yes");
36 function single_character_options_minibuffer_state (minibuffer, continuation) {
38 minibuffer_input_state.call(this, minibuffer, single_character_options_minibuffer_keymap, arguments.$prompt);
39 this.continuation = continuation;
40 this.options = arguments.$options;
42 single_character_options_minibuffer_state.prototype = {
43 constructor: single_character_options_minibuffer_state,
44 __proto__: minibuffer_input_state.prototype,
45 destroy: function () {
46 if (this.continuation)
47 this.continuation.throw(abort());
48 minibuffer_input_state.prototype.destroy.call(this);
51 function single_character_options_enter_character (window, s, event) {
52 var ch = String.fromCharCode(event.charCode);
53 if (s.options.indexOf(ch) != -1) {
54 var c = s.continuation;
55 delete s.continuation;
56 window.minibuffer.pop_state();
61 var str = "Please answer " + or_string(s.options) + ".";
62 window.minibuffer.message(str);
65 interactive("single-character-options-enter-character", null,
67 single_character_options_enter_character(
69 I.minibuffer.check_state(single_character_options_minibuffer_state),
73 minibuffer.prototype.read_single_character_option = function () {
75 var s = new single_character_options_minibuffer_state(this, (yield CONTINUATION), forward_keywords(arguments));
77 var result = yield SUSPEND;
78 yield co_return(result);
81 provide("minibuffer-read-options");