Subversion Repositories HelenOS

Rev

Rev 4266 | Rev 4496 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4266 Rev 4486
Line 30... Line 30...
30
 */
30
 */
31
 
31
 
32
#include <stdio.h>
32
#include <stdio.h>
33
#include <stdlib.h>
33
#include <stdlib.h>
34
#include <string.h>
34
#include <string.h>
35
#include <io/stream.h>
-
 
36
#include <console.h>
35
#include <io/console.h>
37
#include <kbd/kbd.h>
36
#include <io/keycode.h>
38
#include <kbd/keycode.h>
37
#include <io/style.h>
39
#include <errno.h>
38
#include <errno.h>
40
#include <bool.h>
39
#include <bool.h>
41
 
40
 
42
#include "config.h"
41
#include "config.h"
43
#include "util.h"
42
#include "util.h"
Line 98... Line 97...
98
    return rc;
97
    return rc;
99
}
98
}
100
 
99
 
101
static void read_line(char *buffer, int n)
100
static void read_line(char *buffer, int n)
102
{
101
{
103
    kbd_event_t ev;
102
    console_event_t ev;
104
    size_t offs, otmp;
103
    size_t offs, otmp;
105
    wchar_t dec;
104
    wchar_t dec;
106
 
105
 
107
    offs = 0;
106
    offs = 0;
108
    while (true) {
107
    while (true) {
109
        fflush(stdout);
108
        fflush(stdout);
110
        if (kbd_get_event(&ev) < 0)
109
        if (!console_get_event(fphone(stdin), &ev))
111
            return;
110
            return;
-
 
111
       
112
        if (ev.type == KE_RELEASE)
112
        if (ev.type != KEY_PRESS)
113
            continue;
113
            continue;
114
 
114
       
115
        if (ev.key == KC_ENTER || ev.key == KC_NENTER)
115
        if (ev.key == KC_ENTER || ev.key == KC_NENTER)
116
            break;
116
            break;
117
        if (ev.key == KC_BACKSPACE) {
117
        if (ev.key == KC_BACKSPACE) {
118
            if (offs > 0) {
118
            if (offs > 0) {
119
                /*
119
                /*
Line 129... Line 129...
129
                putchar('\b');
129
                putchar('\b');
130
            }
130
            }
131
            continue;
131
            continue;
132
        }
132
        }
133
        if (ev.c >= ' ') {
133
        if (ev.c >= ' ') {
134
            //putchar(ev.c);
-
 
135
            if (chr_encode(ev.c, buffer, &offs, n - 1) == EOK)
134
            if (chr_encode(ev.c, buffer, &offs, n - 1) == EOK)
136
                console_putchar(ev.c);
135
                putchar(ev.c);
137
        }
136
        }
138
    }
137
    }
139
    putchar('\n');
138
    putchar('\n');
140
    buffer[offs] = '\0';
139
    buffer[offs] = '\0';
141
}
140
}
Line 145... Line 144...
145
 * just for command history and making arrows work. */
144
 * just for command history and making arrows work. */
146
void get_input(cliuser_t *usr)
145
void get_input(cliuser_t *usr)
147
{
146
{
148
    char line[INPUT_MAX];
147
    char line[INPUT_MAX];
149
 
148
 
150
    console_set_style(STYLE_EMPHASIS);
149
    console_set_style(fphone(stdout), STYLE_EMPHASIS);
151
    printf("%s", usr->prompt);
150
    printf("%s", usr->prompt);
152
    console_set_style(STYLE_NORMAL);
151
    console_set_style(fphone(stdout), STYLE_NORMAL);
153
 
152
 
154
    read_line(line, INPUT_MAX);
153
    read_line(line, INPUT_MAX);
155
    /* Make sure we don't have rubbish or a C/R happy user */
154
    /* Make sure we don't have rubbish or a C/R happy user */
156
    if (str_cmp(line, "") == 0 || str_cmp(line, "\n") == 0)
155
    if (str_cmp(line, "") == 0 || str_cmp(line, "\n") == 0)
157
        return;
156
        return;