MCPcopy Create free account
hub / github.com/antirez/smallchat / inputBufferFeedChar

Function inputBufferFeedChar

smallchat-client.c:145–164  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

143 * the user is typing, so that reading the input buffer 'buf' for 'len'
144 * bytes will contain it. */
145int 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. */
167void inputBufferHide(struct InputBuffer *ib) {

Callers 1

mainFunction · 0.85

Calls 3

inputBufferHideFunction · 0.85
inputBufferShowFunction · 0.85
inputBufferAppendFunction · 0.85

Tested by

no test coverage detected