Changes in uspace/app/bdsh/input.c [5db9084:ef8bcc6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
r5db9084 ref8bcc6 1 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 2 2 * All rights reserved. 3 * Copyright (c) 2008, Jiri Svoboda - All Rights Reserved 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 31 32 #include <stdio.h> 32 33 #include <stdlib.h> 33 #include <str .h>34 #include <string.h> 34 35 #include <io/console.h> 35 36 #include <io/keycode.h> 36 37 #include <io/style.h> 37 #include <io/color.h>38 38 #include <vfs/vfs.h> 39 #include <clipboard.h>40 #include <macros.h>41 39 #include <errno.h> 42 #include <assert.h>43 40 #include <bool.h> 44 #include <tinput.h>45 41 46 42 #include "config.h" … … 51 47 #include "exec.h" 52 48 53 extern volatile unsigned int cli_quit; 54 55 /** Text input field. */ 56 static tinput_t *tinput; 49 static void read_line(char *, int); 57 50 58 51 /* Tokenizes input from console, sees if the first word is a built-in, if so … … 106 99 } 107 100 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 of 122 * 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 even 145 * just for command history and making arrows work. */ 108 146 void get_input(cliuser_t *usr) 109 147 { 110 char *str; 111 int rc; 148 char line[INPUT_MAX]; 112 149 113 150 fflush(stdout); … … 117 154 console_set_style(fphone(stdout), STYLE_NORMAL); 118 155 119 rc = tinput_read(tinput, &str); 120 if (rc == ENOENT) { 121 /* User requested exit */ 122 cli_quit = 1; 123 putchar('\n'); 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) 124 159 return; 125 }160 usr->line = str_dup(line); 126 161 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;139 162 return; 140 163 } 141 164 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.