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