Subversion Repositories HelenOS

Rev

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

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