58 lines
1.9 KiB
C
58 lines
1.9 KiB
C
//---------------------------------------------------------------------------//
|
|
// ____ PythonExtra //
|
|
//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. //
|
|
//.-'` `---` ' License: MIT (except some files; see LICENSE) //
|
|
//---------------------------------------------------------------------------//
|
|
|
|
#include "py/mphal.h"
|
|
#include "../../shared/readline/readline.h"
|
|
#include "keymap.h"
|
|
#include "shell.h"
|
|
#include <gint/display.h>
|
|
#include <gint/keyboard.h>
|
|
#include <unistd.h>
|
|
|
|
int mp_hal_stdin_rx_chr(void)
|
|
{
|
|
while(1) {
|
|
key_event_t ev = getkey();
|
|
int key = ev.key;
|
|
|
|
/* (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 */
|
|
if(key == KEY_ACON)
|
|
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 */
|
|
if(key == KEY_EXE)
|
|
return '\r';
|
|
|
|
uint32_t code_point = keymap_translate(key, ev.shift, ev.alpha);
|
|
if(code_point != 0)
|
|
return code_point;
|
|
}
|
|
}
|
|
|
|
void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len)
|
|
{
|
|
int r = write(STDOUT_FILENO, str, len);
|
|
(void)r;
|
|
|
|
pe_shell_schedule_update();
|
|
}
|