Process every new keystroke arriving from the keyboard. As a side effect * the input buffer state is modified in order to reflect the current line * the user is typing, so that reading the input buffer 'buf' for 'len' * bytes will contain it. */
| 143 | * the user is typing, so that reading the input buffer 'buf' for 'len' |
| 144 | * bytes will contain it. */ |
| 145 | int inputBufferFeedChar(struct InputBuffer *ib, int c) { |
| 146 | switch(c) { |
| 147 | case '\n': |
| 148 | break; // Ignored. We handle \r instead. |
| 149 | case '\r': |
| 150 | return IB_GOTLINE; |
| 151 | case 127: // Backspace. |
| 152 | if (ib->len > 0) { |
| 153 | ib->len--; |
| 154 | inputBufferHide(ib); |
| 155 | inputBufferShow(ib); |
| 156 | } |
| 157 | break; |
| 158 | default: |
| 159 | if (inputBufferAppend(ib,c) == IB_OK) |
| 160 | write(fileno(stdout),ib->buf+ib->len-1,1); |
| 161 | break; |
| 162 | } |
| 163 | return IB_OK; |
| 164 | } |
| 165 | |
| 166 | /* Hide the line the user is typing. */ |
| 167 | void inputBufferHide(struct InputBuffer *ib) { |
no test coverage detected