2022-10-23 23:47:33 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include "py/mpconfig.h"
|
|
|
|
#include "py/mphal.h"
|
|
|
|
#include "../../shared/readline/readline.h"
|
|
|
|
|
|
|
|
#include "keymap.h"
|
2022-10-30 17:53:13 +01:00
|
|
|
#include "shell.h"
|
2022-10-23 23:47:33 +02:00
|
|
|
#include <gint/display.h>
|
|
|
|
#include <gint/keyboard.h>
|
|
|
|
|
|
|
|
// Receive single character, blocking until one is available.
|
2022-10-30 17:53:13 +01:00
|
|
|
int mp_hal_stdin_rx_chr(void)
|
|
|
|
{
|
2022-10-23 23:47:33 +02:00
|
|
|
while(1) {
|
|
|
|
key_event_t ev = getkey();
|
|
|
|
int key = ev.key;
|
|
|
|
|
2022-10-24 00:53:53 +02:00
|
|
|
/* (The following meanings are only for non-empty lines) */
|
|
|
|
/* TODO: Check cons->cursor before triggering them */
|
|
|
|
|
|
|
|
if(key == KEY_LEFT && ev.shift)
|
|
|
|
return CHAR_CTRL_A; /* go-to-start-of-line */
|
|
|
|
if(key == KEY_LEFT)
|
|
|
|
return CHAR_CTRL_B; /* go-back-one-char */
|
2022-10-23 23:47:33 +02:00
|
|
|
if(key == KEY_ACON)
|
2022-10-24 00:53:53 +02:00
|
|
|
return CHAR_CTRL_C; /* cancel */
|
|
|
|
if(key == KEY_DEL && !ev.shift)
|
|
|
|
return 8; /* delete-at-cursor */
|
|
|
|
if(key == KEY_RIGHT && ev.shift)
|
|
|
|
return CHAR_CTRL_E; /* go-to-end-of-line */
|
|
|
|
if(key == KEY_RIGHT)
|
|
|
|
return CHAR_CTRL_F; /* go-forward-one-char */
|
|
|
|
if(key == KEY_DEL && ev.shift)
|
|
|
|
return CHAR_CTRL_K; /* kill from cursor to end-of-line */
|
|
|
|
if(key == KEY_DOWN)
|
|
|
|
return CHAR_CTRL_N; /* go to next line in history */
|
|
|
|
if(key == KEY_UP)
|
|
|
|
return CHAR_CTRL_P; /* go to previous line in history */
|
2022-10-23 23:47:33 +02:00
|
|
|
if(key == KEY_EXE)
|
|
|
|
return '\r';
|
|
|
|
|
|
|
|
uint32_t code_point = keymap_translate(key, ev.shift, ev.alpha);
|
|
|
|
if(code_point != 0)
|
|
|
|
return code_point;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send the string of given length.
|
2022-10-30 17:53:13 +01:00
|
|
|
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len)
|
|
|
|
{
|
2022-10-23 23:47:33 +02:00
|
|
|
int r = write(STDOUT_FILENO, str, len);
|
|
|
|
(void)r;
|
|
|
|
|
2022-10-30 17:53:13 +01:00
|
|
|
pe_shell_schedule_update();
|
2022-10-23 23:47:33 +02:00
|
|
|
}
|