Changes in uspace/app/bdsh/input.c [ef8bcc6:5db9084] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
ref8bcc6 r5db9084 1 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 2 2 * All rights reserved. 3 * Copyright (c) 2008, Jiri Svoboda - All Rights Reserved4 3 * 5 4 * Redistribution and use in source and binary forms, with or without … … 32 31 #include <stdio.h> 33 32 #include <stdlib.h> 34 #include <str ing.h>33 #include <str.h> 35 34 #include <io/console.h> 36 35 #include <io/keycode.h> 37 36 #include <io/style.h> 37 #include <io/color.h> 38 38 #include <vfs/vfs.h> 39 #include <clipboard.h> 40 #include <macros.h> 39 41 #include <errno.h> 42 #include <assert.h> 40 43 #include <bool.h> 44 #include <tinput.h> 41 45 42 46 #include "config.h" … … 47 51 #include "exec.h" 48 52 49 static void read_line(char *, int); 53 extern volatile unsigned int cli_quit; 54 55 /** Text input field. */ 56 static tinput_t *tinput; 50 57 51 58 /* Tokenizes input from console, sees if the first word is a built-in, if so … … 99 106 } 100 107 101 static void read_line(char *buffer, int n)102 {103 console_event_t ev;104 size_t offs, otmp;105 wchar_t dec;106 107 offs = 0;108 while (true) {109 fflush(stdout);110 if (!console_get_event(fphone(stdin), &ev))111 return;112 113 if (ev.type != KEY_PRESS)114 continue;115 116 if (ev.key == KC_ENTER || ev.key == KC_NENTER)117 break;118 if (ev.key == KC_BACKSPACE) {119 if (offs > 0) {120 /*121 * Back up until we reach valid start of122 * character.123 */124 while (offs > 0) {125 --offs; otmp = offs;126 dec = str_decode(buffer, &otmp, n);127 if (dec != U_SPECIAL)128 break;129 }130 putchar('\b');131 }132 continue;133 }134 if (ev.c >= ' ') {135 if (chr_encode(ev.c, buffer, &offs, n - 1) == EOK)136 putchar(ev.c);137 }138 }139 putchar('\n');140 buffer[offs] = '\0';141 }142 143 /* TODO:144 * Implement something like editline() / readline(), if even145 * just for command history and making arrows work. */146 108 void get_input(cliuser_t *usr) 147 109 { 148 char line[INPUT_MAX]; 110 char *str; 111 int rc; 149 112 150 113 fflush(stdout); … … 154 117 console_set_style(fphone(stdout), STYLE_NORMAL); 155 118 156 read_line(line, INPUT_MAX); 157 /* Make sure we don't have rubbish or a C/R happy user */ 158 if (str_cmp(line, "") == 0 || str_cmp(line, "\n") == 0) 119 rc = tinput_read(tinput, &str); 120 if (rc == ENOENT) { 121 /* User requested exit */ 122 cli_quit = 1; 123 putchar('\n'); 159 124 return; 160 usr->line = str_dup(line);125 } 161 126 127 if (rc != EOK) { 128 /* Error in communication with console */ 129 return; 130 } 131 132 /* Check for empty input. */ 133 if (str_cmp(str, "") == 0) { 134 free(str); 135 return; 136 } 137 138 usr->line = str; 162 139 return; 163 140 } 164 141 142 int input_init(void) 143 { 144 tinput = tinput_new(); 145 if (tinput == NULL) { 146 printf("Failed to initialize input.\n"); 147 return 1; 148 } 149 150 return 0; 151 }
Note:
See TracChangeset
for help on using the changeset viewer.