diff options
-rw-r--r-- | core/args.lua | 2 | ||||
-rw-r--r-- | core/keys.lua | 2 | ||||
-rw-r--r-- | doc/12_Compiling.md | 12 | ||||
-rw-r--r-- | src/Makefile | 98 | ||||
-rw-r--r-- | src/textadept.c | 107 |
5 files changed, 165 insertions, 56 deletions
diff --git a/core/args.lua b/core/args.lua index dedfc22e..15b614d3 100644 --- a/core/args.lua +++ b/core/args.lua @@ -80,7 +80,7 @@ end if not CURSES then M.register('-h', '--help', 0, show_help, 'Shows this') end -- For Windows, create arg table from single command line string (arg[0]). -if WIN32 and #arg[0] > 0 then +if WIN32 and not CURSES and #arg[0] > 0 then local P, C = lpeg.P, lpeg.C local param = P('"') * C((1 - P('"'))^0) * '"' + C((1 - P(' '))^1) local params = lpeg.match(lpeg.Ct(param * (P(' ')^1 * param)^0), arg[0]) diff --git a/core/keys.lua b/core/keys.lua index 5d599482..f1bfb7d1 100644 --- a/core/keys.lua +++ b/core/keys.lua @@ -112,7 +112,7 @@ local error = function(e) events.emit(events.ERROR, e) end -- @name KEYSYMS M.KEYSYMS = { -- From Scintilla.h and cdk/curdefs.h. - [7] = 'esc', [8] = '\b', [9] = '\t', [13] = '\n', [27] = 'esc', + [7] = 'esc', [8] = '\b', [9] = '\t', [13] = '\n', [27] = 'esc', [127] = 'del', -- From curses.h. [263] = '\b', -- From Scintilla.h. diff --git a/doc/12_Compiling.md b/doc/12_Compiling.md index 2c1e3ad4..e7fd8a58 100644 --- a/doc/12_Compiling.md +++ b/doc/12_Compiling.md @@ -171,10 +171,16 @@ made to CDK are as follows: *radio.c*, *scale.{c,h}*, *selection.c*, *slider.{c,h}*, *swindow.c*, *template.c*, *u{scale,slider}.{c,h}*, *view_{file,info}.c*, and *viewer.c*. * *cdk.h* does not `#include` "matrix.h", "viewer.h", and any headers labeled - "Generated headers" due to their machine-dependence. + "Generated headers" due to their machine-dependence. It also `#define`s + `boolean` as `CDKboolean` on Windows platforms since the former is already + `typedef`ed. * *cdk_config.h* no longer defines `HAVE_SETLOCALE` since Textadept handles - locale settings and no longer defines `HAVE_NCURSES_H` and `NCURSES` since - Textadept supports multiple curses implementations, not just ncurses. + locale settings, no longer defines `HAVE_NCURSES_H` and `NCURSES` since + Textadept supports multiple curses implementations (not just ncurses), and + conditionally enables `HAVE_GRP_H`, `HAVE_LSTAT`, and `HAVE_PWD_H` definitions + on \*nix platforms since Windows does not have them. +* *cdk_util.h* `#define`s `Beep` as `CDKBeep` on Windows platforms since Beep is + already defined. * The `deleteFileCB` routine in *fselect.c* has been deactivated. [CDK]: http://invisible-island.net/cdk/ diff --git a/src/Makefile b/src/Makefile index c1b266e1..a1bf2ebe 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,26 +4,38 @@ kernel = $(shell uname -s) ifneq (, $(or $(findstring Linux, $(kernel)), $(findstring BSD, $(kernel)))) ifeq (win, $(findstring win, $(MAKECMDGOALS))) # Cross-compile for Win32. - ifeq (win32, $(MAKECMDGOALS)) + ifeq (win32, $(findstring win32, $(MAKECMDGOALS))) + arch = win32 CROSS = i686-w64-mingw32- - else ifeq (win64, $(MAKECMDGOALS)) + else ifeq (win64, $(findstring win64, $(MAKECMDGOALS))) + arch = win64 CROSS = x86_64-w64-mingw32- endif CC = gcc CFLAGS = -mms-bitfields CXX = g++ - CXXFLAGS = -mms-bitfields -mwindows -static-libgcc -static-libstdc++ - LDFLAGS = -liconv -Wl,--retain-symbols-file -Wl,lua.sym + CXXFLAGS = -mms-bitfields -static-libgcc -static-libstdc++ + LDFLAGS = -Wl,--retain-symbols-file -Wl,lua.sym + ifeq (, $(findstring curses, $(MAKECMDGOALS))) + CXXFLAGS += -mwindows + LDFLAGS += -liconv + endif WINDRES = windres MAKE = make - plat_flag = -DGTK - gtk_flags = $(shell PKG_CONFIG_PATH=`pwd`/$(MAKECMDGOALS)gtk/lib/pkgconfig \ - pkg-config --define-variable=prefix=$(MAKECMDGOALS)gtk \ - --cflags gtk+-2.0) - gtk_libs = $(shell PKG_CONFIG_PATH=`pwd`/$(MAKECMDGOALS)gtk/lib/pkgconfig \ - pkg-config --define-variable=prefix=$(MAKECMDGOALS)gtk \ - --libs gtk+-2.0) + ifeq (, $(findstring curses, $(MAKECMDGOALS))) + plat_flag = -DGTK + gtk_flags = $(shell PKG_CONFIG_PATH=`pwd`/$(arch)gtk/lib/pkgconfig \ + pkg-config --define-variable=prefix=$(arch)gtk \ + --cflags gtk+-2.0) + gtk_libs = $(shell PKG_CONFIG_PATH=`pwd`/$(arch)gtk/lib/pkgconfig \ + pkg-config --define-variable=prefix=$(arch)gtk \ + --libs gtk+-2.0) + else + plat_flag = -DCURSES + curses_flags = -DLIBICONV_STATIC -I$(arch)curses/include + curses_libs = $(arch)curses/lib/pdcurses.a $(arch)curses/lib/libiconv.a + endif luadoc = luadoc_start.bat else ifeq (osx, $(findstring osx, $(MAKECMDGOALS))) @@ -39,7 +51,7 @@ ifneq (, $(or $(findstring Linux, $(kernel)), $(findstring BSD, $(kernel)))) LDFLAGS = -liconv -rdynamic MAKE = make - ifneq (osx-curses, $(MAKECMDGOALS)) + ifeq (, $(findstring curses, $(MAKECMDGOALS))) plat_flag = -DGTK gtk_flags = $(shell PKG_CONFIG_PATH=`pwd`/gtkosx/lib/pkgconfig \ pkg-config --define-variable=prefix=gtkosx \ @@ -49,8 +61,7 @@ ifneq (, $(or $(findstring Linux, $(kernel)), $(findstring BSD, $(kernel)))) --libs gtk+-2.0) -framework Cocoa -lgtkmacintegration else plat_flag = -DCURSES - curses_lib = -lncurses - .DEFAULT_GOAL := osx-curses + curses_libs = -lncurses endif libluajit = libluajit.osx.a @@ -75,7 +86,7 @@ ifneq (, $(or $(findstring Linux, $(kernel)), $(findstring BSD, $(kernel)))) bin_dir = $(DESTDIR)$(PREFIX)/bin data_dir = $(DESTDIR)$(PREFIX)/share/textadept - ifneq (curses, $(findstring curses, $(MAKECMDGOALS))) + ifeq (, $(findstring curses, $(MAKECMDGOALS))) plat_flag = -DGTK ifndef GTK3 gtk_version = 2.0 @@ -87,7 +98,7 @@ ifneq (, $(or $(findstring Linux, $(kernel)), $(findstring BSD, $(kernel)))) install_targets = ../textadept ../textadeptjit else plat_flag = -DCURSES - curses_lib = -lncursesw + curses_libs = -lncursesw install_targets = ../textadept-curses ../textadeptjit-curses endif x64 = $(shell echo "" | $(CC) -E -dM - | grep __x86_64__ | cut -d ' ' -f 3) @@ -109,7 +120,7 @@ ifneq (, $(or $(findstring Linux, $(kernel)), $(findstring BSD, $(kernel)))) # LUAFLAGS = -DLUA_USE_MACOSX # LDFLAGS = -liconv -rdynamic # -# #ifneq (curses, $(MAKECMDGOALS)) +# #ifeq (, $(findstring curses, $(MAKECMDGOALS))) # plat_flag = -DGTK # gtk_flags = $(shell PKG_CONFIG_PATH=`pwd`/gtkosx/lib/pkgconfig \ # gtkosx/bin/pkg-config --define-variable=prefix=gtkosx \ @@ -120,7 +131,7 @@ ifneq (, $(or $(findstring Linux, $(kernel)), $(findstring BSD, $(kernel)))) # .DEFAULT_GOAL := osx # #else # # plat_flag = -DCURSES -# # curses_lib = -lncurses +# # curses_libs = -lncurses # # .DEFAULT_GOAL := osx-curses # #endif # @@ -182,7 +193,9 @@ all: textadept textadeptjit curses: textadept-curses textadeptjit-curses m32: textadept32 textadeptjit32 textadept32-curses textadeptjit32-curses win32: textadept.exe textadeptjit.exe +win32-curses: textadept-curses.exe textadeptjit-curses.exe win64: textadept64.exe #textadeptjit64.exe +win64-curses: textadept64-curses.exe #textadeptjit64-curses.exe osx: textadept.osx textadeptjit.osx osx-curses: textadept-curses.osx textadeptjit-curses.osx @@ -190,7 +203,7 @@ tmp: rm -rf /tmp/tabuild && hg clone ../ /tmp/tabuild cp -rL ../Doxyfile ../doc ../lexers ../modules /tmp/tabuild/ cp -rL gtdialog gtkosx LexLPeg.cxx libluajit*.a lua luajit lua51.dll \ - scintilla termkey cdk win*gtk /tmp/tabuild/src/ + scintilla termkey cdk win*gtk win*curses /tmp/tabuild/src/ cd /tmp/tabuild/src/luajit && $(MAKE) clean ln -s `pwd`/../releases /tmp/tabuild @echo /tmp/tabuild ready for building. @@ -204,7 +217,7 @@ $(scintilla_gtk_objs): scintilla/gtk/*.cxx scintilla-marshal.o: scintilla/gtk/scintilla-marshal.c $(CROSS)$(CC) -c $(CFLAGS) $(gtk_flags) $< ScintillaTerm.o: scintilla/term/ScintillaTerm.cxx - $(CROSS)$(CXX) -c $(CXXFLAGS) $(sci_flags) -Iscintilla/term $^ + $(CROSS)$(CXX) -c $(CXXFLAGS) $(sci_flags) -Iscintilla/term $(curses_flags) $^ LexLPeg.o: LexLPeg.cxx $(CROSS)$(CXX) -c $(CXXFLAGS) $(LUAFLAGS) $(sci_flags) -DLPEG_LEXER \ -DNO_SCITE -Ilua/src $< @@ -213,10 +226,10 @@ LexLPegjit.o: LexLPeg.cxx -DNO_SCITE -Iluajit/src $< -o $@ LexLPeg-curses.o: LexLPeg.cxx $(CROSS)$(CXX) -c $(CXXFLAGS) $(LUAFLAGS) $(sci_flags) -DLPEG_LEXER \ - -DNO_SCITE -DCURSES -Ilua/src $< -o $@ + -DNO_SCITE -DCURSES -Ilua/src $(curses_flags) $< -o $@ LexLPegjit-curses.o: LexLPeg.cxx $(CROSS)$(CXX) -c $(CXXFLAGS) $(LUAFLAGS) $(sci_flags) -DLPEG_LEXER \ - -DNO_SCITE -DCURSES -Iluajit/src $< -o $@ + -DNO_SCITE -DCURSES -Iluajit/src $(curses_flags) $< -o $@ textadept.o: textadept.c $(CROSS)$(CC) -c $(CFLAGS) $(ta_flags) -Ilua/src $(gtk_flags) $< textadeptjit.o: textadept.c @@ -224,13 +237,13 @@ textadeptjit.o: textadept.c -o $@ textadept-curses.o: textadept.c $(CROSS)$(CC) -c $(CFLAGS) $(ta_flags) -Ilua/src -Iscintilla/term -Itermkey \ - -Icdk $< -o $@ + -Icdk $(curses_flags) $< -o $@ textadeptjit-curses.o: textadept.c $(CROSS)$(CC) -c $(CFLAGS) $(ta_flags) -DLUAJIT -Iluajit/src \ - -Iscintilla/term -Itermkey -Icdk $< -o $@ -$(lua_objs): lua/src/*.c lua/src/lib/*.c #lua/src/lib/lpeg/*.c + -Iscintilla/term -Itermkey -Icdk $(curses_flags) $< -o $@ +$(lua_objs): lua/src/*.c lua/src/lib/*.c lua/src/lib/lpeg/*.c $(CROSS)$(CC) -c $(CFLAGS) $(LUAFLAGS) -Ilua/src $^ -$(luajit_objs): lua/src/lib/*.c #lua/src/lib/lpeg/*.c +$(luajit_objs): lua/src/lib/*.c lua/src/lib/lpeg/*.c $(CROSS)$(CC) -c $(CFLAGS) $(LUAFLAGS) -Iluajit/src $^ for lib in $(luajit_objs); do mv $$(echo $$lib | sed 's/jit//g') $$lib; done libluajit.a: @@ -252,11 +265,12 @@ libluajit.osx.a: gtdialog.o: gtdialog/gtdialog.c $(CROSS)$(CC) -c $(CFLAGS) -DGTK -DNOHELP -DLIBRARY $(gtk_flags) $< gtdialog-curses.o: gtdialog/gtdialog.c - $(CROSS)$(CC) -c $(CFLAGS) -DCURSES -DNOHELP -DLIBRARY -Icdk $< -o $@ + $(CROSS)$(CC) -c $(CFLAGS) -DCURSES -DNOHELP -DLIBRARY -Icdk $(curses_flags) \ + $< -o $@ $(termkey_objs): termkey/*.c $(CROSS)$(CC) -c $(CFLAGS) -std=c99 $^ $(cdk_objs): cdk/*.c - $(CROSS)$(CC) -c $(CFLAGS) -D_GNU_SOURCE -Icdk $^ + $(CROSS)$(CC) -c $(CFLAGS) -D_GNU_SOURCE -Icdk $(curses_flags) $^ textadept_rc.o: textadept.rc $(CROSS)$(WINDRES) $^ $@ @@ -271,11 +285,11 @@ textadeptjit: $(scintilla_objs) $(scintilla_gtk_objs) scintilla-marshal.o \ textadept-curses: $(scintilla_objs) ScintillaTerm.o LexLPeg-curses.o \ textadept-curses.o $(lua_objs) gtdialog-curses.o \ $(termkey_objs) $(cdk_objs) - $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(curses_lib) $(LDFLAGS) + $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(curses_libs) $(LDFLAGS) textadeptjit-curses: $(scintilla_objs) ScintillaTerm.o LexLPegjit-curses.o \ textadeptjit-curses.o $(luajit_objs) $(libluajit) \ gtdialog-curses.o $(termkey_objs) $(cdk_objs) - $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(curses_lib) $(LDFLAGS) + $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(curses_libs) $(LDFLAGS) textadept32: ../textadept; mv $< ../$@ textadeptjit32: ../textadeptjit; mv $< ../$@ textadept32-curses: ../textadept-curses; mv $< ../$@ @@ -287,6 +301,15 @@ textadeptjit.exe: $(scintilla_objs) $(scintilla_gtk_objs) scintilla-marshal.o \ LexLPegjit.o textadeptjit.o textadept_rc.o $(luajit_objs) \ lua51.dll gtdialog.o $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(gtk_libs) $(LDFLAGS) +textadept-curses.exe: $(scintilla_objs) ScintillaTerm.o LexLPeg-curses.o \ + textadept-curses.o textadept_rc.o $(lua_objs) \ + gtdialog-curses.o $(cdk_objs) + $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(curses_libs) $(LDFLAGS) +textadeptjit-curses.exe: $(scintilla_objs) ScintillaTerm.o \ + LexLPegjit-curses.o textadeptjit-curses.o \ + textadept_rc.o $(luajit_objs) lua51.dll \ + gtdialog-curses.o $(cdk_objs) + $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(curses_libs) $(LDFLAGS) textadept64.exe: $(scintilla_objs) $(scintilla_gtk_objs) scintilla-marshal.o \ LexLPeg.o textadept.o textadept_rc.o $(lua_objs) gtdialog.o $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(gtk_libs) $(LDFLAGS) @@ -294,6 +317,15 @@ textadeptjit64.exe: $(scintilla_objs) $(scintilla_gtk_objs) \ scintilla-marshal.o LexLPegjit.o textadeptjit.o \ textadept_rc.o $(luajit_objs) lua51_64.dll gtdialog.o $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(gtk_libs) $(LDFLAGS) +textadept64-curses.exe: $(scintilla_objs) ScintillaTerm.o LexLPeg-curses.o \ + textadept-curses.o textadept_rc.o $(lua_objs) \ + gtdialog-curses.o $(cdk_objs) + $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(curses_libs) $(LDFLAGS) +textadeptjit64-curses.exe: $(scintilla_objs) ScintillaTerm.o \ + LexLPegjit-curses.o textadeptjit-curses.o \ + textadept_rc.o $(luajit_objs) lua51_64.dll \ + gtdialog-curses.o $(cdk_objs) + $(CROSS)$(CXX) $(CXXFLAGS) -o ../$@ $^ $(curses_libs) $(LDFLAGS) textadept.osx: textadept; mv ../$< ../$@ textadeptjit.osx: textadeptjit; mv ../$< ../$@ textadept-curses.osx: textadept-curses; mv ../$< ../$@ @@ -344,7 +376,8 @@ modules = css hypertext java rails rhtml ruby php python release: ../textadept ../textadeptjit ../textadept-curses \ ../textadeptjit-curses ../textadept32 ../textadeptjit32 \ ../textadept32-curses ../textadeptjit32-curses ../textadept.exe \ - ../textadeptjit.exe ../textadept64.exe ../textadept.osx \ + ../textadeptjit.exe ../textadept-curses.exe \ + ../textadeptjit-curses.exe ../textadept64.exe ../textadept.osx \ ../textadeptjit.osx lua51.dll \ doc pkg_x86_64 pkg_i386 pkg_win32 pkg_win64 pkg_osx pkg_src \ pkg_modules cleanup @@ -363,7 +396,8 @@ $(basedir).i386: ../textadept32 ../textadeptjit32 ../textadept32-curses \ ../textadeptjit32-curses | $(basedir) cp -r $| $@ && cp $^ $@ for t in `ls $@/textadept*`; do mv $$t `echo $$t | sed -e 's/32//;'`; done -$(basedir).win32: ../textadept.exe ../textadeptjit.exe lua51.dll | $(basedir) +$(basedir).win32: ../textadept.exe ../textadeptjit.exe ../textadept-curses.exe \ + ../textadeptjit-curses.exe lua51.dll | $(basedir) cp -r $| $@ && cp $^ $@ cp win32gtk/bin/*.dll $@ && cp -r win32gtk/etc win32gtk/lib win32gtk/share $@ rm -r $@/lib/*.a $@/lib/glib-2.0 $@/lib/gtk-2.0/include $@/lib/pkgconfig diff --git a/src/textadept.c b/src/textadept.c index adc9469e..100b37b8 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -24,11 +24,14 @@ #if GTK #include <gtk/gtk.h> #elif CURSES +#if !_WIN32 #include <signal.h> #include <sys/ioctl.h> #include <termios.h> +#else +#undef main +#endif #include <curses.h> -#include "cdk_int.h" #endif #include "gtdialog.h" @@ -41,8 +44,11 @@ #include "ScintillaWidget.h" #elif CURSES #include "ScintillaTerm.h" +#include "cdk_int.h" +#if !_WIN32 #include "termkey.h" #endif +#endif #if GTK typedef GtkWidget Scintilla; @@ -63,7 +69,6 @@ typedef GtkWidget Scintilla; #define focus_view(v) \ SS(focused_view, SCI_SETFOCUS, 0, 0), SS(v, SCI_SETFOCUS, 1, 0) #define flushch() timeout(0), getch(), timeout(-1) -static struct termios term; #endif // Window @@ -72,9 +77,11 @@ static Scintilla *focused_view; #if GTK static GtkWidget *window, *menubar, *statusbar[2]; static GtkAccelGroup *accel; -#if (__APPLE__ && !CURSES) +#if __APPLE__ static GtkOSXApplication *osxapp; #endif +#elif CURSES && !_WIN32 +static struct termios term; #endif static void new_buffer(sptr_t); static Scintilla *new_view(sptr_t); @@ -377,7 +384,9 @@ static int lfind_focus(lua_State *L) { if (findbox) return 0; // already active wresize(scintilla_get_window(focused_view), LINES - 4, COLS); findbox = initCDKScreen(newwin(2, 0, LINES - 3, 0)), eraseCDKScreen(findbox); +#if !_WIN32 tcsetattr(0, TCSANOW, &term); +#endif int b_width = max(strlen(button_labels[0]), strlen(button_labels[1])) + max(strlen(button_labels[2]), strlen(button_labels[3])) + 3; int o_width = max(strlen(option_labels[0]), strlen(option_labels[1])) + @@ -564,7 +573,9 @@ static int lce_focus(lua_State *L) { #elif CURSES if (command_entry) return 0; // already active CDKSCREEN *screen = initCDKScreen(newwin(1, 0, LINES - 2, 0)); +#if !_WIN32 tcsetattr(0, TCSANOW, &term); +#endif command_entry = newCDKEntry(screen, LEFT, TOP, NULL, NULL, A_NORMAL, '_', vMIXED, 0, 0, 256, FALSE, FALSE); bindCDKObject(vENTRY, command_entry, KEY_TAB, c_keypress, NULL); @@ -1319,7 +1330,7 @@ static int lquit(lua_State *L) { GdkEventAny event = { GDK_DELETE, gtk_widget_get_window(window), TRUE }; gdk_event_put((GdkEvent *)(&event)); #elif CURSES - quit = true; + quit = TRUE; #endif return 0; } @@ -1519,22 +1530,23 @@ static int lL_init(lua_State *L, int argc, char **argv, int reinit) { lua_pushboolean(L, 1), lua_setglobal(L, "WIN32"); #elif (__APPLE__ && !CURSES) lua_pushboolean(L, 1), lua_setglobal(L, "OSX"); -#elif CURSES +#endif +#if CURSES lua_pushboolean(L, 1), lua_setglobal(L, "CURSES"); #endif const char *charset = NULL; #if GTK g_get_charset(&charset); -#elif CURSES +#elif (CURSES && !_WIN32) charset = getenv("CHARSET"); if (!charset || !*charset) { char *locale = getenv("LC_ALL"); if (!locale || !*locale) locale = getenv("LANG"); if (locale && (charset = strchr(locale, '.'))) charset++; } - // Note: _WIN32 uses GetACP() to determine codepage. - // If _WIN32 is ever supported, use a codepage -> charset look-up table like - // glib's `libcharset/localecharset.c`. +#elif (CURSES && _WIN32) + char codepage[8]; + sprintf(codepage, "CP%d", GetACP()), charset = codepage; #endif lua_pushstring(L, charset), lua_setglobal(L, "_CHARSET"); @@ -2189,7 +2201,7 @@ static void new_window() { #endif } -#if CURSES +#if (CURSES && !_WIN32) /** Signal for a terminal resize. */ static void resize(int signal) { struct winsize win; @@ -2212,12 +2224,17 @@ int main(int argc, char **argv) { #if GTK gtk_init(&argc, &argv); #elif CURSES +#if !_WIN32 static struct termios oldterm; tcgetattr(0, &oldterm); // save old terminal settings TermKey *tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS); +#endif setlocale(LC_CTYPE, ""); // for displaying UTF-8 characters properly initscr(); // raw()/cbreak() and noecho() are taken care of in libtermkey curs_set(0); // disable cursor when Scintilla has focus +#if _WIN32 + raw(), noecho(); +#endif #endif char *last_slash = NULL; @@ -2286,6 +2303,7 @@ int main(int argc, char **argv) { #elif CURSES scintilla_refresh(focused_view); +#if !_WIN32 stderr = freopen("/dev/null", "w", stderr); // redirect stderr // Ignore some termios (from GNU Nano). tcgetattr(0, &term); @@ -2297,7 +2315,57 @@ int main(int argc, char **argv) { struct sigaction act; memset(&act, 0, sizeof(struct sigaction)); act.sa_handler = resize, sigaction(SIGWINCH, &act, NULL); +#else + freopen("NUL", "w", stderr); // redirect stderr +#endif + int c = 0, shift, ctrl, alt, *mods[] = { &shift, &ctrl, &alt }; +#if _WIN32 + int keysyms[] = { + 0, SCK_DOWN, SCK_UP, SCK_LEFT, SCK_RIGHT, SCK_HOME, SCK_BACK, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, SCK_DELETE, SCK_INSERT, 0, 0, 0, 0, 0, 0, + SCK_NEXT, SCK_PRIOR, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + SCK_END + }, shift_keysyms[] = { + SCK_TAB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, SCK_DELETE, 0, 0, SCK_END, 0, 0, 0, SCK_HOME, + SCK_INSERT, 0, SCK_LEFT, 0, 0, 0, 0, 0, 0, 0, 0, SCK_RIGHT + }, ctrl_keysyms[] = { + SCK_LEFT, SCK_RIGHT, SCK_PRIOR, SCK_NEXT, SCK_HOME, SCK_END, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + SCK_INSERT, 0, 0, SCK_UP, SCK_DOWN, SCK_TAB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, SCK_BACK, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, SCK_DELETE, 0, SCK_RETURN + }, alt_keysyms[] = { + SCK_DELETE, SCK_INSERT, 0, 0, 0, SCK_TAB, '-', '=', SCK_HOME, SCK_PRIOR, + SCK_NEXT, SCK_END, SCK_UP, SCK_DOWN, SCK_RIGHT, SCK_LEFT, SCK_RETURN, + SCK_ESCAPE, '`', '[', ']', ';', '\'', ',', 0, '\\', SCK_BACK, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '/' + }; // '-', '=', SCK_RETURN, '`', ';', ',', '\\', '/' do not work for me + while ((c = wgetch(scintilla_get_window(focused_view))) != ERR) { + shift = ctrl = alt = FALSE; + if (c >= KEY_MIN && c <= KEY_END && keysyms[c - KEY_MIN]) + c = keysyms[c - KEY_MIN]; + else if (c >= KEY_F(1) && c <= KEY_F(48)) { + if (c > KEY_F(12)) *mods[(c - KEY_F(1)) / 12 - 1] = TRUE; + c = 0xFFBE + (c - KEY_F(1)) % 12; // use GDK keysym values for now + } else if (c >= KEY_BTAB && c <= KEY_SRIGHT && shift_keysyms[c - KEY_BTAB]) + c = shift_keysyms[c - KEY_BTAB], shift = TRUE; + else if (c >= ALT_0 && c <= ALT_9) + c = '0' + (c - ALT_0), alt = TRUE; + else if (c >= ALT_A && c <= ALT_Z) + c = 'a' + (c - ALT_A), alt = TRUE; + else if (c >= CTL_LEFT && c <= CTL_ENTER && ctrl_keysyms[c - CTL_LEFT]) + c = ctrl_keysyms[c - CTL_LEFT], ctrl = TRUE; + else if (c >= ALT_DEL && c <= ALT_BSLASH && alt_keysyms[c - ALT_DEL]) + c = alt_keysyms[c - ALT_DEL], alt = TRUE; + else if (c == KEY_SUP || c == KEY_SDOWN) + c = (c == KEY_SUP) ? SCK_UP : SCK_DOWN, shift = TRUE; + else if (c < 0x20 && c != 8 && c != 9 && c != 13 && c != 27) + c = tolower(c ^ 0x40), ctrl = TRUE; +#else TermKeyResult res; TermKeyKey key; int keysyms[] = { @@ -2305,7 +2373,6 @@ int main(int argc, char **argv) { SCK_LEFT, SCK_RIGHT, 0, 0, SCK_INSERT, SCK_DELETE, 0, SCK_PRIOR, SCK_NEXT, SCK_HOME, SCK_END }; - int c = 0; while ((res = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) { if (res == TERMKEY_RES_ERROR) continue; if (key.type == TERMKEY_TYPE_UNICODE) @@ -2315,13 +2382,13 @@ int main(int argc, char **argv) { else if (key.type == TERMKEY_TYPE_KEYSYM && key.code.sym >= 0 && key.code.sym <= TERMKEY_SYM_END) c = keysyms[key.code.sym]; - if (!lL_event(lua, "keypress", LUA_TNUMBER, c, LUA_TBOOLEAN, - key.modifiers & TERMKEY_KEYMOD_SHIFT, LUA_TBOOLEAN, - key.modifiers & TERMKEY_KEYMOD_CTRL, LUA_TBOOLEAN, - key.modifiers & TERMKEY_KEYMOD_ALT, LUA_TBOOLEAN, FALSE, -1)) - scintilla_send_key(focused_view, c, key.modifiers & TERMKEY_KEYMOD_SHIFT, - key.modifiers & TERMKEY_KEYMOD_CTRL, - key.modifiers & TERMKEY_KEYMOD_ALT); + shift = (key.modifiers & TERMKEY_KEYMOD_SHIFT) ? TRUE : FALSE; + ctrl = (key.modifiers & TERMKEY_KEYMOD_CTRL) ? TRUE : FALSE; + alt = (key.modifiers & TERMKEY_KEYMOD_ALT) ? TRUE : FALSE; +#endif + if (!lL_event(lua, "keypress", LUA_TNUMBER, c, LUA_TBOOLEAN, shift, + LUA_TBOOLEAN, ctrl, LUA_TBOOLEAN, alt, -1)) + scintilla_send_key(focused_view, c, shift, ctrl, alt); if (quit && lL_event(lua, "quit", -1)) { l_close(lua); // Free some memory. @@ -2342,15 +2409,17 @@ int main(int argc, char **argv) { scintilla_refresh(focused_view); } endwin(); +#if !_WIN32 termkey_destroy(tk); tcsetattr(0, TCSANOW, &oldterm); // restore old terminal settings #endif +#endif free(textadept_home); return 0; } -#if _WIN32 +#if (_WIN32 && !CURSES) /** * Runs Textadept in Windows. * @see main |