Added code to properly support 'Enter' key, which was being sent as '\r\n' instead of '\n'

master
Aadhavan Srinivasan 2 years ago
parent f19eb3becc
commit da0f6fdf32

@ -27,7 +27,10 @@ Buffer* new_buffer(int size) {
void buffer_grow(Buffer* buffer) {
int old_size = buffer->size;
int old_size = buffer->size; /* I am making use of the fact that, whenever this
function is called, the strlen of the string must
equal the size of the buffer (since the gap size is zero) */
int start_offset = buffer->start - buffer->text;
buffer->size += 10;
buffer->text = realloc(buffer->text,buffer->size);
@ -135,6 +138,15 @@ int main() {
buffer_right(buffer);
break;
case 10: /* Enter key */
buffer_insert('\n',buffer); /* Why handle this separately?
Because, by default, curses seems to send '\r\n',
which is technically two characters. I should
probably add some code to deal with this scenario
in the 'insert' method (instead of creating an
exception here), but that's a problem for another day. */
break;
default:
buffer_insert(ch,buffer);

Loading…
Cancel
Save