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
11 require("minibuffer-read.js");
13 define_keywords("$options");
14 minibuffer.prototype.read_explicit_option = function () {
16 var options = arguments.$options;
17 var options_string = or_string(options);
18 var result = yield this.read(forward_keywords(arguments),
19 $prompt = arguments.$prompt + " (" + options_string + ")",
20 $validator = function (x, m) {
21 if (options.indexOf(x) == -1) {
22 m.message("Please answer " + options_string + ".");
29 yield co_return(result);
32 minibuffer.prototype.read_yes_or_no = function () {
34 var result = yield this.read_explicit_option(forward_keywords(arguments), $options = ["yes", "no"]);
35 yield co_return(result == "yes");
38 function single_character_options_minibuffer_state (minibuffer, continuation) {
40 minibuffer_input_state.call(this, minibuffer, single_character_options_minibuffer_keymap, arguments.$prompt);
41 this.continuation = continuation;
42 this.options = arguments.$options;
44 single_character_options_minibuffer_state.prototype = {
45 constructor: single_character_options_minibuffer_state,
46 __proto__: minibuffer_input_state.prototype,
47 destroy: function () {
48 if (this.continuation)
49 this.continuation.throw(abort());
50 minibuffer_input_state.prototype.destroy.call(this);
53 function single_character_options_enter_character (window, s, event) {
54 var ch = String.fromCharCode(event.charCode);
55 if (s.options.indexOf(ch) != -1) {
56 var c = s.continuation;
57 delete s.continuation;
58 window.minibuffer.pop_state();
63 var str = "Please answer " + or_string(s.options) + ".";
64 window.minibuffer.message(str);
67 interactive("single-character-options-enter-character", null,
69 single_character_options_enter_character(
71 I.minibuffer.check_state(single_character_options_minibuffer_state),
75 minibuffer.prototype.read_single_character_option = function () {
77 var s = new single_character_options_minibuffer_state(this, (yield CONTINUATION), forward_keywords(arguments));
79 var result = yield SUSPEND;
80 yield co_return(result);
83 provide("minibuffer-read-options");