source: mainline/kernel/generic/src/console/prompt.c@ f4a8734

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f4a8734 was f4a8734, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

C style

  • Property mode set to 100644
File size: 3.3 KB
Line 
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 * @return Whether to print all hints.
46 */
47bool console_prompt_display_all_hints(indev_t *indev, size_t hints)
48{
49 ASSERT(indev);
50 ASSERT(hints > 0);
51
52 printf("Display all %zu possibilities? (y or n)", hints);
53
54 while (true) {
55 wchar_t answer = indev_pop_character(indev);
56
57 if (answer == 'y' || answer == 'Y') {
58 printf(" y");
59 return true;
60 }
61
62 if (answer == 'n' || answer == 'N') {
63 printf(" n");
64 return false;
65 }
66 }
67}
68
69/** Display the <i>--more--</i> prompt and wait for answer.
70 *
71 * When the function returns false, @p display_hints is set to zero.
72 *
73 * @param[in] indev Where to read characters from.
74 * @param[out] display_hints How many hints to display.
75 * @return Whether to display more hints.
76 */
77bool console_prompt_more_hints(indev_t *indev, size_t *display_hints)
78{
79 ASSERT(indev);
80 ASSERT(display_hints != NULL);
81
82 printf("--More--");
83 while (true) {
84 wchar_t continue_showing_hints = indev_pop_character(indev);
85 /* Display a full page again? */
86 if (continue_showing_hints == 'y'
87 || continue_showing_hints == 'Y'
88 || continue_showing_hints == ' ') {
89 *display_hints = MAX_TAB_HINTS - 1;
90 break;
91 }
92
93 /* Stop displaying hints? */
94 if (continue_showing_hints == 'n'
95 || continue_showing_hints == 'N'
96 || continue_showing_hints == 'q'
97 || continue_showing_hints == 'Q') {
98 *display_hints = 0;
99 break;
100 }
101
102 /* Show one more hint? */
103 if (continue_showing_hints == '\n') {
104 *display_hints = 1;
105 break;
106 }
107 }
108
109 /* Delete the --More-- option */
110 printf("\r \r");
111
112 return *display_hints > 0;
113}
114
115/** @}
116 */
Note: See TracBrowser for help on using the repository browser.