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) {
38 minibuffer_input_state.call(this, minibuffer, single_character_options_minibuffer_keymap, arguments.$prompt);
39 this.deferred = Promise.defer();
40 this.promise = make_simple_cancelable(this.deferred);
41 this.options = arguments.$options;
43 single_character_options_minibuffer_state.prototype = {
44 constructor: single_character_options_minibuffer_state,
45 __proto__: minibuffer_input_state.prototype,
46 destroy: function () {
47 this.promise.cancel();
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 s.deferred.resolve(ch);
55 window.minibuffer.pop_state();
58 var str = "Please answer " + or_string(s.options) + ".";
59 window.minibuffer.message(str);
62 interactive("single-character-options-enter-character", null,
64 single_character_options_enter_character(
66 I.minibuffer.check_state(single_character_options_minibuffer_state),
70 minibuffer.prototype.read_single_character_option = function () {
72 var s = new single_character_options_minibuffer_state(this, forward_keywords(arguments));
74 yield co_return(yield s.promise);
77 provide("minibuffer-read-options");