From 6d4668bdaf393aa45d9adb640774f998c6b4aa58 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 15 Feb 2014 15:18:09 +0100 Subject: added EMCurses/Emscripten support by building with Emscripten support, SciTECO may be embedded into web pages. * sciteco.html is not a piece of documentation but a sample SciTECO embedding --- src/Makefile.am | 3 +- src/interface-ncurses.cpp | 151 +++++++++++++++++++++++++++------------------- src/interface-ncurses.h | 2 + src/parser.h | 8 ++- src/sciteco.html | 70 +++++++++++++++++++++ 5 files changed, 170 insertions(+), 64 deletions(-) create mode 100644 src/sciteco.html (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 93de359..596f398 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,8 @@ endif BUILT_SOURCES = EXTRA_DIST = gtk-info-popup.gob \ - symbols-extract.tes + symbols-extract.tes \ + sciteco.html noinst_LIBRARIES = libsciteco-base.a libsciteco_base_a_SOURCES = main.cpp sciteco.h \ diff --git a/src/interface-ncurses.cpp b/src/interface-ncurses.cpp index eca9268..654b6ac 100644 --- a/src/interface-ncurses.cpp +++ b/src/interface-ncurses.cpp @@ -33,6 +33,10 @@ #include #include +#ifdef EMSCRIPTEN +#include +#endif + #include "sciteco.h" #include "cmdline.h" #include "qregisters.h" @@ -81,10 +85,14 @@ InterfaceNCurses::main(int &argc, char **&argv) msg_clear(); cmdline_update(""); +#ifdef EMSCRIPTEN + nodelay(cmdline_window, TRUE); +#else #ifndef PDCURSES_WIN32A /* workaround: endwin() is somewhat broken in the win32a port */ endwin(); #endif +#endif } #ifdef __PDCURSES__ @@ -342,84 +350,103 @@ InterfaceNCurses::popup_clear(void) popup.window = NULL; } +/** + * One iteration of the event loop. + * + * This is a global function, so it may + * be used as an Emscripten callback. + * + * @bug + * Can probably be defined as a static method, + * so we can avoid declaring it a fried function of + * InterfaceNCurses. + */ void -InterfaceNCurses::event_loop(void) +event_loop_iter() { - /* in commandline (visual) mode, enforce redraw */ - wrefresh(curscr); - draw_info(); + int key; - for (;;) { - int key; + keypad(interface.cmdline_window, Flags::ed & Flags::ED_FNKEYS); - /* also handles initial refresh (styles are configured...) */ - scintilla_refresh(sci); - if (popup.window) - wrefresh(popup.window); - - keypad(cmdline_window, Flags::ed & Flags::ED_FNKEYS); - - /* no special handling */ - raw(); - key = wgetch(cmdline_window); - /* allow asynchronous interruptions on */ - cbreak(); + /* no special handling */ + raw(); + key = wgetch(interface.cmdline_window); + /* allow asynchronous interruptions on */ + cbreak(); + if (key == ERR) + return; - switch (key) { + switch (key) { #ifdef KEY_RESIZE - case ERR: - case KEY_RESIZE: + case KEY_RESIZE: #ifdef PDCURSES - resize_term(0, 0); + resize_term(0, 0); #endif - resize_all_windows(); - break; + interface.resize_all_windows(); + break; #endif - case 0x7F: /* DEL */ - case KEY_BACKSPACE: - cmdline_keypress('\b'); - break; - case KEY_ENTER: - case '\r': - case '\n': - cmdline_keypress(get_eol()); - break; + case 0x7F: /* DEL */ + case KEY_BACKSPACE: + cmdline_keypress('\b'); + break; + case KEY_ENTER: + case '\r': + case '\n': + cmdline_keypress(get_eol()); + break; - /* - * Function key macros - */ + /* + * Function key macros + */ #define FN(KEY) case KEY_##KEY: cmdline_fnmacro(#KEY); break #define FNS(KEY) FN(KEY); FN(S##KEY) - FN(DOWN); FN(UP); FNS(LEFT); FNS(RIGHT); - FNS(HOME); - case KEY_F(0)...KEY_F(63): { - gchar macro_name[3+1]; - - g_snprintf(macro_name, sizeof(macro_name), - "F%d", key - KEY_F0); - cmdline_fnmacro(macro_name); - break; - } - FNS(DC); - FNS(IC); - FN(NPAGE); FN(PPAGE); - FNS(PRINT); - FN(A1); FN(A3); FN(B2); FN(C1); FN(C3); - FNS(END); - FNS(HELP); + FN(DOWN); FN(UP); FNS(LEFT); FNS(RIGHT); + FNS(HOME); + case KEY_F(0)...KEY_F(63): { + gchar macro_name[3+1]; + + g_snprintf(macro_name, sizeof(macro_name), + "F%d", key - KEY_F0); + cmdline_fnmacro(macro_name); + break; + } + FNS(DC); + FNS(IC); + FN(NPAGE); FN(PPAGE); + FNS(PRINT); + FN(A1); FN(A3); FN(B2); FN(C1); FN(C3); + FNS(END); + FNS(HELP); #undef FNS #undef FN - /* - * Control keys and keys with printable representation - */ - default: - if (key <= 0xFF) - cmdline_keypress((gchar)key); - } - - sigint_occurred = FALSE; + /* + * Control keys and keys with printable representation + */ + default: + if (key <= 0xFF) + cmdline_keypress((gchar)key); } + + sigint_occurred = FALSE; + + scintilla_refresh(interface.sci); + if (interface.popup.window) + wrefresh(interface.popup.window); +} + +void +InterfaceNCurses::event_loop(void) +{ + /* initial refresh: window might have been changed in batch mode */ + scintilla_refresh(sci); + +#ifdef EMSCRIPTEN + emscripten_set_main_loop(event_loop_iter, 1000/100, TRUE); +#else + for (;;) + event_loop_iter(); +#endif } InterfaceNCurses::Popup::~Popup() diff --git a/src/interface-ncurses.h b/src/interface-ncurses.h index da4bbc1..30f73f6 100644 --- a/src/interface-ncurses.h +++ b/src/interface-ncurses.h @@ -93,6 +93,8 @@ private: void init_screen(void); void resize_all_windows(void); void draw_info(void); + + friend void event_loop_iter(); } interface; #endif diff --git a/src/parser.h b/src/parser.h index 0b139d9..b96e8d4 100644 --- a/src/parser.h +++ b/src/parser.h @@ -123,7 +123,13 @@ protected: MicroState state; - inline void +#ifdef EMSCRIPTEN + /* FIXME: Shouldn't be required! */ + __attribute__((noinline)) +#else + inline +#endif + void set(MicroState next) { if (next != state) diff --git a/src/sciteco.html b/src/sciteco.html new file mode 100644 index 0000000..9acef2b --- /dev/null +++ b/src/sciteco.html @@ -0,0 +1,70 @@ + + + Text Editor and Corrector + + + + + + +
+
+ 80x24 • + 80x43 • + 132x24 • + 132x43 +
+ + + + + -- cgit v1.2.3