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

Last change on this file since 690ad20 was 28a5ebd, checked in by Martin Decky <martin@…>, 5 years ago

Use char32_t instead of wchat_t to represent UTF-32 strings

The intention of the native HelenOS string API has been always to
support Unicode in the UTF-8 and UTF-32 encodings as the sole character
representations and ignore the obsolete mess of older single-byte and
multibyte character encodings. Before C11, the wchar_t type has been
slightly misused for the purpose of the UTF-32 strings. The newer
char32_t type is obviously a much more suitable option. The standard
defines char32_t as uint_least32_t, thus we can take the liberty to fix
it to uint32_t.

To maintain compatilibity with the C Standard, the putwchar(wchar_t)
functions has been replaced by our custom putuchar(char32_t) functions
where appropriate.

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[f0d7bd9]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
[174156fd]30/** @addtogroup kernel_generic_console
[f0d7bd9]31 * @{
32 */
33
34/**
35 * @file
36 * @brief Kernel console special prompts.
37 */
38
[63e27ef]39#include <assert.h>
[f0d7bd9]40#include <console/prompt.h>
41
[550af2b]42/** Display the <i>display all possibilities</i> prompt and wait for answer.
43 *
44 * @param indev Where to read characters from.
45 * @param hints Number of hints that would be displayed.
[dfc07c1]46 *
[550af2b]47 * @return Whether to print all hints.
[dfc07c1]48 *
[550af2b]49 */
[aca4a04]50bool console_prompt_display_all_hints(indev_t *indev, size_t hints)
51{
[63e27ef]52 assert(indev);
53 assert(hints > 0);
[a35b458]54
[dfc07c1]55 printf("Display all %zu possibilities? (y or n) ", hints);
[a35b458]56
[aca4a04]57 while (true) {
[28a5ebd]58 char32_t answer = indev_pop_character(indev);
[a35b458]59
[dfc07c1]60 if ((answer == 'y') || (answer == 'Y')) {
61 printf("y");
[aca4a04]62 return true;
63 }
[a35b458]64
[dfc07c1]65 if ((answer == 'n') || (answer == 'N')) {
66 printf("n");
[aca4a04]67 return false;
68 }
69 }
70}
71
[550af2b]72/** Display the <i>--more--</i> prompt and wait for answer.
73 *
74 * When the function returns false, @p display_hints is set to zero.
75 *
[dfc07c1]76 * @param[in] indev Where to read characters from.
[550af2b]77 * @param[out] display_hints How many hints to display.
[dfc07c1]78 *
[550af2b]79 * @return Whether to display more hints.
[dfc07c1]80 *
[550af2b]81 */
[f0d7bd9]82bool console_prompt_more_hints(indev_t *indev, size_t *display_hints)
83{
[63e27ef]84 assert(indev);
85 assert(display_hints != NULL);
[a35b458]86
[f0d7bd9]87 printf("--More--");
88 while (true) {
[28a5ebd]89 char32_t continue_showing_hints = indev_pop_character(indev);
[f0d7bd9]90 /* Display a full page again? */
[dfc07c1]91 if ((continue_showing_hints == 'y') ||
92 (continue_showing_hints == 'Y') ||
93 (continue_showing_hints == ' ')) {
[f0d7bd9]94 *display_hints = MAX_TAB_HINTS - 1;
95 break;
96 }
[a35b458]97
[f0d7bd9]98 /* Stop displaying hints? */
[dfc07c1]99 if ((continue_showing_hints == 'n') ||
100 (continue_showing_hints == 'N') ||
101 (continue_showing_hints == 'q') ||
102 (continue_showing_hints == 'Q')) {
[f0d7bd9]103 *display_hints = 0;
104 break;
105 }
[a35b458]106
[f0d7bd9]107 /* Show one more hint? */
108 if (continue_showing_hints == '\n') {
109 *display_hints = 1;
110 break;
111 }
112 }
[a35b458]113
[f0d7bd9]114 /* Delete the --More-- option */
115 printf("\r \r");
[a35b458]116
[f0d7bd9]117 return *display_hints > 0;
118}
119
120/** @}
121 */
Note: See TracBrowser for help on using the repository browser.