Porting the kilo text editor as a micropython module (work in progress)
Posted: Sun Apr 07, 2019 12:58 pm
I was looking for a small text editor that I could integrate with micropython as a C module and found kilo http://antirez.com/news/108
Someone in the comments even talks about running it on a microcontroller and gives pointers to reducing its memory footprint.
For now, I've only tested this on the unix port, but here's what I did. The idea is that you'll be able to:
Edit the file, then saving (ctrl-s) and/or quitting (ctrl-q) will return you to the repl.
First, my mangled kilo.c is here: https://github.com/j0hnlittle/kilo/blob ... hon/kilo.c
It includes some basic highlighting for Python keywords (better python support in that fork that could be lifted later: https://github.com/practicalswift/opene ... penemacs.c) and handles resizing the terminal window. Variable sized tabs would be nice but that's also for later.
Following https://micropython-dev-docs.readthedoc ... odule.html, you need to add kilo.c to your Makefile along the other source files:
And modify mpconfigport.h by adding both this line with the other "extern const":
... and the last line in this block:
Not sure how that would work on an ESP8266 but anyway, I thought I'd share if anyone wanted to try something similar
Someone in the comments even talks about running it on a microcontroller and gives pointers to reducing its memory footprint.
For now, I've only tested this on the unix port, but here's what I did. The idea is that you'll be able to:
Code: Select all
import kilo
kilo.edit("somefile.py")
First, my mangled kilo.c is here: https://github.com/j0hnlittle/kilo/blob ... hon/kilo.c
It includes some basic highlighting for Python keywords (better python support in that fork that could be lifted later: https://github.com/practicalswift/opene ... penemacs.c) and handles resizing the terminal window. Variable sized tabs would be nice but that's also for later.
Following https://micropython-dev-docs.readthedoc ... odule.html, you need to add kilo.c to your Makefile along the other source files:
Code: Select all
# source files
SRC_C = \
kilo.c \
main.c \
Code: Select all
extern const struct _mp_obj_module_t mp_module_kilo;
Code: Select all
#define MICROPY_PORT_BUILTIN_MODULES \
MICROPY_PY_FFI_DEF \
MICROPY_PY_JNI_DEF \
MICROPY_PY_UTIME_DEF \
MICROPY_PY_SOCKET_DEF \
{ MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \
MICROPY_PY_UOS_DEF \
MICROPY_PY_USELECT_DEF \
MICROPY_PY_TERMIOS_DEF \
{ MP_OBJ_NEW_QSTR(MP_QSTR_kilo), (mp_obj_t)&mp_module_kilo }, \