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