summaryrefslogtreecommitdiffstatshomepage
path: root/unix/unix_mphal.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-05-24 22:36:31 +0100
committerDamien George <damien.p.george@gmail.com>2015-05-27 15:59:43 +0100
commit9ae3fc65235303322ef5282d3cdd4ca99a2c37cc (patch)
tree5644437cc732a8a33f2ec8752610d4d55c8a740b /unix/unix_mphal.c
parent4a10214be20cb8a51724913903678f4506358752 (diff)
downloadmicropython-9ae3fc65235303322ef5282d3cdd4ca99a2c37cc.tar.gz
micropython-9ae3fc65235303322ef5282d3cdd4ca99a2c37cc.zip
unix: Add option to use uPy readline, and enable by default.
This gets uPy readline working with unix port, with tab completion and history. GNU readline is still supported, configure using MICROPY_USE_READLINE variable.
Diffstat (limited to 'unix/unix_mphal.c')
-rw-r--r--unix/unix_mphal.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/unix/unix_mphal.c b/unix/unix_mphal.c
index c70045b4e4..1f545f9e51 100644
--- a/unix/unix_mphal.c
+++ b/unix/unix_mphal.c
@@ -25,6 +25,7 @@
*/
#include <unistd.h>
+#include <stdlib.h>
#include <string.h>
#include "py/mpstate.h"
@@ -35,13 +36,12 @@
STATIC void sighandler(int signum) {
if (signum == SIGINT) {
+ if (MP_STATE_VM(mp_pending_exception) == MP_STATE_VM(keyboard_interrupt_obj)) {
+ // this is the second time we are called, so die straight away
+ exit(1);
+ }
mp_obj_exception_clear_traceback(MP_STATE_VM(keyboard_interrupt_obj));
MP_STATE_VM(mp_pending_exception) = MP_STATE_VM(keyboard_interrupt_obj);
- // disable our handler so next we really die
- struct sigaction sa;
- sa.sa_handler = SIG_DFL;
- sigemptyset(&sa.sa_mask);
- sigaction(SIGINT, &sa, NULL);
}
}
#endif
@@ -67,6 +67,32 @@ void mp_hal_set_interrupt_char(char c) {
}
}
+#if MICROPY_USE_READLINE == 1
+
+#include <termios.h>
+
+static struct termios orig_termios;
+
+void mp_hal_stdio_mode_raw(void) {
+ // save and set terminal settings
+ tcgetattr(0, &orig_termios);
+ static struct termios termios;
+ termios = orig_termios;
+ termios.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ termios.c_cflag = (termios.c_cflag & ~(CSIZE | PARENB)) | CS8;
+ termios.c_lflag = 0;
+ termios.c_cc[VMIN] = 1;
+ termios.c_cc[VTIME] = 0;
+ tcsetattr(0, TCSAFLUSH, &termios);
+}
+
+void mp_hal_stdio_mode_orig(void) {
+ // restore terminal settings
+ tcsetattr(0, TCSAFLUSH, &orig_termios);
+}
+
+#endif
+
int mp_hal_stdin_rx_chr(void) {
unsigned char c;
int ret = read(0, &c, 1);