<commit_before>#include "lcd.h"
#include "keys.h"
#include "readline.h"
#include "interrupt.h"

#define MAX_CHARS 79
char readline_buffer[MAX_CHARS + 1];
char *buffer_pos;
unsigned char last_key = KEY_NONE;
char last_char = 0;

char * readline(unsigned char interruptible) {
  reset_interrupted();
  buffer_pos = readline_buffer;

  for (;;) {
    if (interruptible && is_interrupted()) {
      lcd_put_newline();
      *buffer_pos = '\0';
      return readline_buffer;
    }

    keys_update();

    if (keys_get_code() != KEY_NONE) {
      if (last_key == KEY_NONE) {
        last_key = keys_get_code();
        last_char = keys_getc();

        if ((last_key) == KEY_BACKSPACE) {
          if (buffer_pos != readline_buffer) {
            --buffer_pos;
            if (lcd_get_x() == 0) {
              lcd_goto(39, lcd_get_y() - 1);
              lcd_putc(' ');
              lcd_goto(39, lcd_get_y() - 1);
            } else {
              lcd_goto(lcd_get_x() - 1, lcd_get_y());
              lcd_putc(' ');
              lcd_goto(lcd_get_x() - 1, lcd_get_y());
            }
          }
        } else if (last_char == '\n') {
          lcd_putc(last_char);
          *buffer_pos = '\0';
          break;
        } else if (last_char != 0 && buffer_pos - readline_buffer < MAX_CHARS) {
          lcd_putc(last_char);
          *buffer_pos = last_char;
          ++buffer_pos;
        }
      }
    } else {
      last_key = KEY_NONE;
    }
  }

  return readline_buffer;
}<commit_msg>Clear the input buffer with Ctrl-U<commit_after>#include "lcd.h"
#include "keys.h"
#include "readline.h"
#include "interrupt.h"

#define MAX_CHARS 79
char readline_buffer[MAX_CHARS + 1];
char *buffer_pos;

void delete_character();

char * readline(unsigned char interruptible) {
  unsigned char last_key = KEY_NONE;
  char last_char;
  unsigned char last_modifiers;
  reset_interrupted();
  buffer_pos = readline_buffer;

  for (;;) {
    if (interruptible && is_interrupted()) {
      lcd_put_newline();
      *buffer_pos = '\0';
      return readline_buffer;
    }

    keys_update();

    if (keys_get_code() != KEY_NONE) {
      if (last_key == KEY_NONE) {
        last_key = keys_get_code();
        last_char = keys_getc();
        last_modifiers = keys_get_modifiers();

        if ((last_key) == KEY_BACKSPACE) {
          if (buffer_pos != readline_buffer) {
            delete_character();
          }
        } else if (last_char == '\n') {
          lcd_putc(last_char);
          *buffer_pos = '\0';
          break;
        } else if (last_modifiers ==  MODIFIER_CTRL && last_key == KEY_U) {
           while (buffer_pos != readline_buffer) {
              delete_character();
            }
        } else if (last_char != 0 && buffer_pos - readline_buffer < MAX_CHARS) {
          lcd_putc(last_char);
          *buffer_pos = last_char;
          ++buffer_pos;
        }
      }
    } else {
      last_key = KEY_NONE;
    }
  }

  return readline_buffer;
}

void delete_character() {
  --buffer_pos;
  if (lcd_get_x() == 0) {
    lcd_goto(39, lcd_get_y() - 1);
    lcd_putc(' ');
    lcd_goto(39, lcd_get_y() - 1);
  } else {
    lcd_goto(lcd_get_x() - 1, lcd_get_y());
    lcd_putc(' ');
    lcd_goto(lcd_get_x() - 1, lcd_get_y());
  }
}
{'fraction_non_alphanumeric': 0.13431916204559458, 'fraction_numerical': 0.009550215650030808, 'mean_word_length': 2.2021696252465484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4582926', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1168, 'n_words': 222}