Subversion Repositories HelenOS

Rev

Rev 2726 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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