diff options
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/interface-ncurses.cpp | 151 | ||||
-rw-r--r-- | src/interface-ncurses.h | 2 | ||||
-rw-r--r-- | src/parser.h | 8 | ||||
-rw-r--r-- | src/sciteco.html | 70 |
6 files changed, 177 insertions, 65 deletions
diff --git a/configure.ac b/configure.ac index 491217b..d2df4c6 100644 --- a/configure.ac +++ b/configure.ac @@ -112,7 +112,7 @@ AC_ARG_WITH(scinterm, SCINTERM_PATH=`canonicalize $SCINTERM_PATH` AC_ARG_WITH(interface, - AS_HELP_STRING([--with-interface=ncurses|pdcurses|gtk], + AS_HELP_STRING([--with-interface=ncurses|pdcurses|emcurses|gtk], [Specify user interface [default=ncurses]]), [INTERFACE=$withval], [INTERFACE=ncurses]) @@ -132,6 +132,12 @@ case $INTERFACE in AC_DEFINE(PDCURSES_WIN32A, , [PDCurses supports Win32a extensions]) ]) ;; + emcurses) + # EMCurses is the PDCurses/Emscripten port + # However, ordinary library checks do not work + # under Emscripten + LIBS="$LIBS -lpdcurses" + ;; esac AC_CHECK_HEADERS([curses.h], , [ 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 <Scintilla.h> #include <ScintillaTerm.h> +#ifdef EMSCRIPTEN +#include <emscripten.h> +#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 <CTRL/C> handling */ - raw(); - key = wgetch(cmdline_window); - /* allow asynchronous interruptions on <CTRL/C> */ - cbreak(); + /* no special <CTRL/C> handling */ + raw(); + key = wgetch(interface.cmdline_window); + /* allow asynchronous interruptions on <CTRL/C> */ + 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 @@ +<html>
+ <head>
+ <title>Text Editor and Corrector</title>
+ <style type="text/css">
+ body,p,a,td,li {
+ font-family: courier,fixed,swiss,sans-serif;
+ font-size: 12px;
+ color: #cccccc;
+ }
+ .lh15 {
+ line-height: 15px;
+ }
+
+ .term {
+ font-family: "Courier New",courier,fixed,monospace;
+ font-size: 12px;
+ color: #94aad6;
+ background: none;
+ letter-spacing: 1px;
+ }
+ .term .termReverse {
+ color: #232e45;
+ background: #95a9d5;
+ }
+ + #termDiv { + visibility: hidden; + width: 100%; + }
+ #termDiv table { + margin-left: auto; + margin-right: auto; + } + + /* the canvas *must not* have any border or padding, or mouse coords will be wrong */ + canvas.emscripten { + border: 0px none; + visibility: hidden; + } + </style>
+ </head>
+ <body bgcolor="#222222" link="#77dd11" text="#cccccc">
+ <!-- FIXME: We don't need a Canvas, but must nevertheless define it, + as Emscripten plugins for loading files depend on it. + --> + <!-- <canvas class="emscripten" id="canvas"></canvas> --> + <!-- For termlib... --> + <div id="termDiv"></div> + <center> + <a href="#" onClicK="term.resizeTo(80, 24)">80x24</a> • + <a href="#" onClicK="term.resizeTo(80, 43)">80x43</a> • + <a href="#" onClicK="term.resizeTo(132, 24)">132x24</a> • + <a href="#" onClicK="term.resizeTo(132, 43)">132x43</a> + </center> + + <script language="JavaScript" type="text/javascript"> + function sciteco_init() { + ENV.HOME = "/pages"; + +// FS.createPreloadedFile("/pages", "Welcome", "pages/Welcome", true, true); + } + + var Module = { + preRun: [sciteco_init], +// canvas: document.getElementById('canvas') + }; + </script> + <script async language="JavaScript" type="text/javascript" src="sciteco.js"></script> + </body> +</html> |