Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. console.c
  5. Abstract:
  6. Revision History
  7. --*/
  8. #include "lib.h"
  9. VOID
  10. Output (
  11. IN CHAR16 *Str
  12. )
  13. /* Write a string to the console at the current cursor location */
  14. {
  15. ST->ConOut->OutputString (ST->ConOut, Str);
  16. }
  17. VOID
  18. Input (
  19. IN CHAR16 *Prompt OPTIONAL,
  20. OUT CHAR16 *InStr,
  21. IN UINTN StrLen
  22. )
  23. /* Input a string at the current cursor location, for StrLen */
  24. {
  25. IInput (
  26. ST->ConOut,
  27. ST->ConIn,
  28. Prompt,
  29. InStr,
  30. StrLen
  31. );
  32. }
  33. VOID
  34. IInput (
  35. IN SIMPLE_TEXT_OUTPUT_INTERFACE *ConOut,
  36. IN SIMPLE_INPUT_INTERFACE *ConIn,
  37. IN CHAR16 *Prompt OPTIONAL,
  38. OUT CHAR16 *InStr,
  39. IN UINTN StrLen
  40. )
  41. /* Input a string at the current cursor location, for StrLen */
  42. {
  43. EFI_INPUT_KEY Key;
  44. EFI_STATUS Status;
  45. UINTN Len;
  46. if (Prompt) {
  47. ConOut->OutputString (ConOut, Prompt);
  48. }
  49. Len = 0;
  50. for (; ;) {
  51. WaitForSingleEvent (ConIn->WaitForKey, 0);
  52. Status = ConIn->ReadKeyStroke(ConIn, &Key);
  53. if (EFI_ERROR(Status)) {
  54. DEBUG((D_ERROR, "Input: error return from ReadKey %x\n", Status));
  55. break;
  56. }
  57. if (Key.UnicodeChar == '\n' ||
  58. Key.UnicodeChar == '\r') {
  59. break;
  60. }
  61. if (Key.UnicodeChar == '\b') {
  62. if (Len) {
  63. ConOut->OutputString(ConOut, L"\b \b");
  64. Len -= 1;
  65. }
  66. continue;
  67. }
  68. if (Key.UnicodeChar >= ' ') {
  69. if (Len < StrLen-1) {
  70. InStr[Len] = Key.UnicodeChar;
  71. InStr[Len+1] = 0;
  72. ConOut->OutputString(ConOut, &InStr[Len]);
  73. Len += 1;
  74. }
  75. continue;
  76. }
  77. }
  78. InStr[Len] = 0;
  79. }