1 | /*
|
---|
2 | * Copyright (c) 2012 Sandeep Kumar
|
---|
3 | * Copyright (c) 2012 Vojtech Horky
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /** @addtogroup genericconsole
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * @file
|
---|
36 | * @brief Kernel console special prompts.
|
---|
37 | */
|
---|
38 |
|
---|
39 | #include <console/prompt.h>
|
---|
40 |
|
---|
41 | /** Display the <i>display all possibilities</i> prompt and wait for answer.
|
---|
42 | *
|
---|
43 | * @param indev Where to read characters from.
|
---|
44 | * @param hints Number of hints that would be displayed.
|
---|
45 | *
|
---|
46 | * @return Whether to print all hints.
|
---|
47 | *
|
---|
48 | */
|
---|
49 | bool console_prompt_display_all_hints(indev_t *indev, size_t hints)
|
---|
50 | {
|
---|
51 | ASSERT(indev);
|
---|
52 | ASSERT(hints > 0);
|
---|
53 |
|
---|
54 | printf("Display all %zu possibilities? (y or n) ", hints);
|
---|
55 |
|
---|
56 | while (true) {
|
---|
57 | wchar_t answer = indev_pop_character(indev);
|
---|
58 |
|
---|
59 | if ((answer == 'y') || (answer == 'Y')) {
|
---|
60 | printf("y");
|
---|
61 | return true;
|
---|
62 | }
|
---|
63 |
|
---|
64 | if ((answer == 'n') || (answer == 'N')) {
|
---|
65 | printf("n");
|
---|
66 | return false;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | /** Display the <i>--more--</i> prompt and wait for answer.
|
---|
72 | *
|
---|
73 | * When the function returns false, @p display_hints is set to zero.
|
---|
74 | *
|
---|
75 | * @param[in] indev Where to read characters from.
|
---|
76 | * @param[out] display_hints How many hints to display.
|
---|
77 | *
|
---|
78 | * @return Whether to display more hints.
|
---|
79 | *
|
---|
80 | */
|
---|
81 | bool console_prompt_more_hints(indev_t *indev, size_t *display_hints)
|
---|
82 | {
|
---|
83 | ASSERT(indev);
|
---|
84 | ASSERT(display_hints != NULL);
|
---|
85 |
|
---|
86 | printf("--More--");
|
---|
87 | while (true) {
|
---|
88 | wchar_t continue_showing_hints = indev_pop_character(indev);
|
---|
89 | /* Display a full page again? */
|
---|
90 | if ((continue_showing_hints == 'y') ||
|
---|
91 | (continue_showing_hints == 'Y') ||
|
---|
92 | (continue_showing_hints == ' ')) {
|
---|
93 | *display_hints = MAX_TAB_HINTS - 1;
|
---|
94 | break;
|
---|
95 | }
|
---|
96 |
|
---|
97 | /* Stop displaying hints? */
|
---|
98 | if ((continue_showing_hints == 'n') ||
|
---|
99 | (continue_showing_hints == 'N') ||
|
---|
100 | (continue_showing_hints == 'q') ||
|
---|
101 | (continue_showing_hints == 'Q')) {
|
---|
102 | *display_hints = 0;
|
---|
103 | break;
|
---|
104 | }
|
---|
105 |
|
---|
106 | /* Show one more hint? */
|
---|
107 | if (continue_showing_hints == '\n') {
|
---|
108 | *display_hints = 1;
|
---|
109 | break;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | /* Delete the --More-- option */
|
---|
114 | printf("\r \r");
|
---|
115 |
|
---|
116 | return *display_hints > 0;
|
---|
117 | }
|
---|
118 |
|
---|
119 | /** @}
|
---|
120 | */
|
---|