Skip to content

Commit 933434b

Browse files
committed
👍 Update documentation for input-function
1 parent 2c0dd2e commit 933434b

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

denops_std/function/input.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@ import { BuiltinCompletion, isValidBuiltinCompletion } from "./types.ts";
1414
* :if input("Coffee or beer? ") == "beer"
1515
* : echo "Cheers!"
1616
* :endif
17+
*
1718
* If the optional {text} argument is present and not empty, this
1819
* is used for the default reply, as if the user typed this.
1920
* Example:
2021
* :let color = input("Color? ", "white")
22+
*
2123
* The optional {completion} argument specifies the type of
2224
* completion supported for the input. Without it completion is
2325
* not performed. The supported completion types are the same as
2426
* that can be supplied to a user-defined command using the
2527
* "-complete=" argument. Refer to |:command-completion| for
2628
* more information. Example:
2729
* let fname = input("File: ", "", "file")
30+
*
2831
* NOTE: This function must not be used in a startup file, for
2932
* the versions that only run in GUI mode (e.g., the Win32 GUI).
3033
* Note: When input() is called from within a mapping it will
@@ -34,13 +37,15 @@ import { BuiltinCompletion, isValidBuiltinCompletion } from "./types.ts";
3437
* after input() to avoid that. Another solution is to avoid
3538
* that further characters follow in the mapping, e.g., by using
3639
* |:execute| or |:normal|.
40+
*
3741
* Example with a mapping:
38-
* :nmap \x :call GetFoo()<CR>:exe "/" . Foo<CR
42+
* :nmap \x :call GetFoo()<CR>:exe "/" .. Foo<CR>
3943
* :function GetFoo()
4044
* : call inputsave()
4145
* : let g:Foo = input("enter search pattern: ")
4246
* : call inputrestore()
4347
* :endfunction
48+
*
4449
* Can also be used as a |method|:
4550
* GetPrompt()->input()
4651
*/
@@ -65,16 +70,18 @@ export function input(
6570
* displayed, one string per line. The user will be prompted to
6671
* enter a number, which is returned.
6772
* The user can also select an item by clicking on it with the
68-
* mouse. For the first string 0 is returned. When clicking
69-
* above the first item a negative number is returned. When
70-
* clicking on the prompt one more than the length of {textlist}
71-
* is returned.
73+
* mouse, if the mouse is enabled in the command line ('mouse' is
74+
* "a" or includes "c"). For the first string 0 is returned.
75+
* When clicking above the first item a negative number is
76+
* returned. When clicking on the prompt one more than the
77+
* length of {textlist} is returned.
7278
* Make sure {textlist} has less than 'lines' entries, otherwise
7379
* it won't work. It's a good idea to put the entry number at
7480
* the start of the string. And put a prompt in the first item.
7581
* Example:
7682
* let color = inputlist(['Select color:', '1. red',
7783
* \ '2. green', '3. blue'])
84+
*
7885
* Can also be used as a |method|:
7986
* GetChoices()->inputlist()
8087
*/
@@ -86,10 +93,11 @@ export function inputlist(denops: Denops, textlist: string[]): Promise<number> {
8693
* Restore typeahead that was saved with a previous |inputsave()|.
8794
* Should be called the same number of times inputsave() is
8895
* called. Calling it more often is harmless though.
89-
* Returns 1 when there is nothing to restore, 0 otherwise.
96+
* Returns TRUE when there is nothing to restore, FALSE otherwise.
9097
*/
91-
export function inputrestore(denops: Denops): Promise<void> {
92-
return denops.call("inputrestore") as Promise<void>;
98+
export async function inputrestore(denops: Denops): Promise<boolean> {
99+
const result = await denops.call("inputrestore") as number;
100+
return !!result;
93101
}
94102

95103
/**
@@ -98,10 +106,11 @@ export function inputrestore(denops: Denops): Promise<void> {
98106
* followed by a matching inputrestore() after the prompt. Can
99107
* be used several times, in which case there must be just as
100108
* many inputrestore() calls.
101-
* Returns 1 when out of memory, 0 otherwise.
109+
* Returns TRUE when out of memory, FALSE otherwise.
102110
*/
103-
export function inputsave(denops: Denops): Promise<void> {
104-
return denops.call("inputsave") as Promise<void>;
111+
export async function inputsave(denops: Denops): Promise<boolean> {
112+
const result = await denops.call("inputsave") as number;
113+
return !!result;
105114
}
106115

107116
/**
@@ -114,6 +123,7 @@ export function inputsave(denops: Denops): Promise<void> {
114123
* The result is a String, which is whatever the user actually
115124
* typed on the command-line in response to the issued prompt.
116125
* NOTE: Command-line completion is not supported.
126+
*
117127
* Can also be used as a |method|:
118128
* GetPrompt()->inputsecret()
119129
*/

0 commit comments

Comments
 (0)