[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 |
|
---|
| 30 | /** @addtogroup genericconsole
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | /**
|
---|
| 35 | * @file
|
---|
| 36 | * @brief Kernel console special prompts.
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | #include <console/prompt.h>
|
---|
| 40 |
|
---|
[550af2b] | 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.
|
---|
[dfc07c1] | 45 | *
|
---|
[550af2b] | 46 | * @return Whether to print all hints.
|
---|
[dfc07c1] | 47 | *
|
---|
[550af2b] | 48 | */
|
---|
[aca4a04] | 49 | bool console_prompt_display_all_hints(indev_t *indev, size_t hints)
|
---|
| 50 | {
|
---|
[f4a8734] | 51 | ASSERT(indev);
|
---|
| 52 | ASSERT(hints > 0);
|
---|
[dfc07c1] | 53 |
|
---|
| 54 | printf("Display all %zu possibilities? (y or n) ", hints);
|
---|
| 55 |
|
---|
[aca4a04] | 56 | while (true) {
|
---|
| 57 | wchar_t answer = indev_pop_character(indev);
|
---|
[dfc07c1] | 58 |
|
---|
| 59 | if ((answer == 'y') || (answer == 'Y')) {
|
---|
| 60 | printf("y");
|
---|
[aca4a04] | 61 | return true;
|
---|
| 62 | }
|
---|
[dfc07c1] | 63 |
|
---|
| 64 | if ((answer == 'n') || (answer == 'N')) {
|
---|
| 65 | printf("n");
|
---|
[aca4a04] | 66 | return false;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[550af2b] | 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 | *
|
---|
[dfc07c1] | 75 | * @param[in] indev Where to read characters from.
|
---|
[550af2b] | 76 | * @param[out] display_hints How many hints to display.
|
---|
[dfc07c1] | 77 | *
|
---|
[550af2b] | 78 | * @return Whether to display more hints.
|
---|
[dfc07c1] | 79 | *
|
---|
[550af2b] | 80 | */
|
---|
[f0d7bd9] | 81 | bool console_prompt_more_hints(indev_t *indev, size_t *display_hints)
|
---|
| 82 | {
|
---|
[f4a8734] | 83 | ASSERT(indev);
|
---|
[f0d7bd9] | 84 | ASSERT(display_hints != NULL);
|
---|
[dfc07c1] | 85 |
|
---|
[f0d7bd9] | 86 | printf("--More--");
|
---|
| 87 | while (true) {
|
---|
| 88 | wchar_t continue_showing_hints = indev_pop_character(indev);
|
---|
| 89 | /* Display a full page again? */
|
---|
[dfc07c1] | 90 | if ((continue_showing_hints == 'y') ||
|
---|
| 91 | (continue_showing_hints == 'Y') ||
|
---|
| 92 | (continue_showing_hints == ' ')) {
|
---|
[f0d7bd9] | 93 | *display_hints = MAX_TAB_HINTS - 1;
|
---|
| 94 | break;
|
---|
| 95 | }
|
---|
[dfc07c1] | 96 |
|
---|
[f0d7bd9] | 97 | /* Stop displaying hints? */
|
---|
[dfc07c1] | 98 | if ((continue_showing_hints == 'n') ||
|
---|
| 99 | (continue_showing_hints == 'N') ||
|
---|
| 100 | (continue_showing_hints == 'q') ||
|
---|
| 101 | (continue_showing_hints == 'Q')) {
|
---|
[f0d7bd9] | 102 | *display_hints = 0;
|
---|
| 103 | break;
|
---|
| 104 | }
|
---|
[dfc07c1] | 105 |
|
---|
[f0d7bd9] | 106 | /* Show one more hint? */
|
---|
| 107 | if (continue_showing_hints == '\n') {
|
---|
| 108 | *display_hints = 1;
|
---|
| 109 | break;
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
[dfc07c1] | 112 |
|
---|
[f0d7bd9] | 113 | /* Delete the --More-- option */
|
---|
| 114 | printf("\r \r");
|
---|
[dfc07c1] | 115 |
|
---|
[f0d7bd9] | 116 | return *display_hints > 0;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | /** @}
|
---|
| 120 | */
|
---|