aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/interface-curses.cpp
AgeCommit message (Collapse)AuthorFilesLines
2015-07-14programmable terminal color redefinition and theming SciTECO curses UI based ↵Robin Haberkorn1-89/+301
on Scintilla styles * The first 16 colors of the terminal palette can be redefined using the 3EJ property - with all restrictions that ncurses and UNIX terminals impose on us. It is still important to be able to redefine the palette for some color schemes like Solarized since it may be difficult for users to set up the terminal emulator's palette manually. Also when using PDCurses, setting the palette is port-specific or only possible using init_color(). In order to allow color redefinitions across all curses ports it makes sense if SciTECO gives access to the color initialization of curses even if it can guarantee very little about its semantics in general. * 3EJ is completely ignored for GTK+ * use the STYLE_DEFAULT of the current document to style the message line. Fg and bg colors are reversed to guarantee a good contrast to the Scintilla view. Errors are still hardcoded to a red background, warnings to yellow and info messages to green. This allows color-scheming more of SciTECO given that the red, yellow and green terminal colors are not changed fundamentally in the terminal's palette. * info line is now also styled using STYLE_DEFAULT (reverse colors). The Q-Register and buffer names are now written out using format_str() which means that control characters are written out in REVERSE just like in the command line. String::canonicalize_ctl() is still used to canonicalize window titles. * Command line is now modelled as a curses Pad and "blitted" to the command line window. This allowed simplification of the command line drawing code and introduction of format_str(). The command line is now styled according to STYLE_DEFAULT (original fg and bg colors). The rubbed-out part of the command line can now longer be shown in bold black - or even bold light black - since that is not visible in all color themes. Instead it is now only shown in bold. Command line theming problems will be gone once we use a Scintilla view for the command line. * The popup widget is now styled according to STYLE_CALLTIP. * This means that all relevant parts of SciTECO's user interface can now be themed. This allows the creation of themes that redefine the terminal palette radically (e.g. Solarized) and the creation of "bright" themes (e.g. Solarized/bright). * theming of the non-scintilla-view parts of SciTECO is currently unsupported on GTK+. The reason is that both the popup widget and command line widgets have to be rewritten completely in GTK+ and are work in progress, so adapting the current code would be a waste of time. * Added a manual section about the UI and theming.
2015-06-24added "^FCLOSE" function key macro and defined SIGTERM behaviourRobin Haberkorn1-0/+1
* ^FCLOSE is inserted when the "Close" key is pressed. It is used by the GTK+ UI to deliver window close requests and SIGTERM occurrences. (this replaces the "Break" key used before in the GTK+ UI). * The default action of ^FCLOSE is to quit SciTECO, therefore window closing is possible even in --no-profile mode for instance. * fixed a minor memleak in Cmdline::fnmacro() * added ^FCLOSE implementation to fnkeys.tes to insert EX. This currently has the disadvantage of overwriting the error message with syntax errors if there are modified buffers but it will at least not close the window if there are modified buffers. * SIGTERM will now be similar to SIGINT by default instead of terminating SciTECO right away. * the GTK+ UI handles SIGTERM by emulating the "close" key while still interrupting like SIGINT. * GTK+: SIGTERM and ^C will interrupt by sending SIGINT to the entire process group instead of simply setting `sigint_occurred`. This fixes interrupting EC and EG commands with long-running or hanging programs and is relevant to the solution of #4.
2015-06-24fixed SEGFAULTs in InterfaceCurses::vmsg()Robin Haberkorn1-8/+9
* both vmsg() and stdio_msg() behave like vprintf() are allowed to leave their `va_list` in an undefined state. * therefore when writing messages to stdio in addition to the message line, we have to copy the argument list. * fixes SEGFAULTs when trying to log any message (but this bug did not manifest on every test system)
2015-06-22disable PDCurses/win32a "function keys"Robin Haberkorn1-1/+25
* this fixes the CTRL+V command * PDC_set_function_key() may be used to implement a "shutdown" function key macro later on. * interruptions via CTRL+C are not (easily) possible in this port of PDCurses - similar to XCurses. However, I may ask the author if this is possible.
2015-06-22improved ncurses/win32 supportRobin Haberkorn1-16/+10
* CTRL+C interruptions are now possible. ncurses/win32 needs a noraw() (bug!?) and the console_ctrl_handler for this to work. * setting the window title is not possible on this port * stdio output can be redirected, even in interactive mode. Also, we can write to stdout/stderr even in interactive mode without disrupting the terminal. After endwin(), the user will see these messages (if they haven't been redirected). * there's one bug left: the Scintilla cursor is not drawn correctly at the end of lines. * part of the solution to #4
2015-06-22added XCurses supportRobin Haberkorn1-3/+36
* enabled via --with-interface=xcurses, so we can configure it automatically via xcurses-config. This also adds XCURSES_CFLAGS and XCURSES_LIBS. * The X11 window class name is set to "SciTECO". X11 resource overrides can currently not be set via sciteco's command line. The user may use .Xdefaults though. * interruptions via CTRL+C are currently not supported. Apparently, XCurses also does send SIGINT in cbreak() mode. An XCurses-specific hack would be cumbersome. * ~InterfaceCurses() should probably be rewritten. Curses cleanup should be completely in restore_batch() as the destructor may be called after Curses-cleanup handlers. E.g. isendwin() SEGFAULTs on XCurses when called from the destructor.
2015-06-22use WIN32_LEAN_AND_MEAN macro when including windows.hRobin Haberkorn1-6/+1
this avoids some problematic includes, so we no longer have to #undef interface. Also it should speed up building a bit.
2015-06-22fixed flickering in InterfaceCurses::set_window_title()Robin Haberkorn1-0/+15
* this was an issue at least in PDCurses/win32
2015-06-22fixed CTRL+C handling on PDCurses/win32 portRobin Haberkorn1-4/+67
* it now works as in the ncurses port: ^C during macro execution interrupts just as SIGINT does; else it is read as a character. * On Windows we need to register a special "console ctrl handler" which is the analogue to a signal handler. * It must be tested how ncurses/win32 and PDCurses/win32a behaves in this regard. PDCurses/win32a is still actively maintained, so we can also patch its source base. * See #4
2015-06-22major Curses UI revision: initialize curses as late as possibleRobin Haberkorn1-197/+216
* relies on a patched version of Scinterm that allows you to construct Scintilla objects, send messages etc. before Curses is initialized. The Scintilla and Scinterm submodules have been updated. * This once and for all fixes batch mode and stdio redirections in batch mode on all Curses platforms and operating systems. * Fixes the ^C-does-not-interrupt bug on ncurses/UNIX. See #4. * On ncurses/UNIX we will still do a newterm()-initialization. This allows us to keep stdout/stderr alone in case they are redirected. This effectively allows redirecting SciTECO's output into a file even in interactive mode. ncurses/UNIX now behaves like, e.g. PDCurses/win32a and GTK+ in this regard. * Curses environment variable handling fixed. The environment registers are exported into the process environment so that Curses environment variables can be set/modified by the SciTECO profile. * Use term.h for accessing terminfo now. Explained set_window_title() limitations. * fixed interruption via SIGINT. If the UI is waiting for user input, SIGINT is effectively ignored instead of letting the next character fail always. * Updated sciteco(1) and sciteco(7): More options, environment variables and signals documented. Also rewritten DESCRIPTION section (different modes of operation).
2015-06-14handle environment variables more consistentlyRobin Haberkorn1-1/+18
* the registers beginning with "$" are exported into sub-process environments. Therefore macros can now modify the environment (variables) of commands executed via EC/EG. A variable can be modified temporarily, e.g.: [[$FOO] ^U[$FOO]bar$ EC...$ ][$FOO] * SciTECO accesses the global environment registers instead of using g_getenv(). Therefore now, tilde-expansion will always use the current value of the "$HOME" register. Previously, both register and environment variable could diverge. * This effectively fully maps the process environment to a subset of Q-Registers beginning with "$". * This hasn't been implemented by mapping those registers to special implementations that updates the process environment directly, since g_setenv() is non-thread-safe on UNIX and we're expected to have threads soon - at least in the GTK+ UI.
2015-03-18ncurses: fixed batch mode initialization for unset or broken $TERMRobin Haberkorn1-10/+56
* If TERM is set but wrong, it might still fail. Errors are reported now. * If $TERM is unset or empty, we refuse to start the interactive mode. Unfortunately, we cannot easily let curses decide this since newterm() does not work as expected. * However this solution should be quite good: Either $TERM is empty - then batch mode will work but not interactive mode. Or it is not empty, then it is checked by the first call to newterm() when initializing batch mode. The chance of starting up interactive mode with a wrong $TERM or in head-less environments is now quite low. * This is most likely responsible for the PPA build issues.
2015-03-17support for ncurses/win32Robin Haberkorn1-3/+15
Unfortunately, I cannot really test this curses port since it is not supported by Windows 2000 (missing AttachConsole() API) and it does not run very well in Wine. Under Wine, it does not require the LINES and COLS variable to be set. However, endwin() and the refresh later on result in a very unusable state of operation. I cannot currently check whether this is true on Windows XP or later.
2015-03-16clarify comment of why newterm() cannot be used on PDCursesRobin Haberkorn1-4/+6
2015-03-16fixed curses prog-mode reinitializationRobin Haberkorn1-4/+11
when SciTECO interactive mode is started, the curses prog mode is restored automatically. Therefore it should already be set up correctly (after SciTECO batch mode initialization). This fixes console glitches on MinGW/PDCurses. partial revert of commit 4dced2
2015-03-16implemented automatic EOL translation supportRobin Haberkorn1-1/+1
* activated via bit 4 of the ED flag (enabled by default) * automatic EOL guessing on file loading and translation to LFs. * works with files that have inconsistent EOL sequences. * automatic translation to original EOL sequences on file saving * works with inconsistent EOL sequences in the buffer. This should usually not happen if the file was read in with automatic EOL translation enabled. * also works with the EC and EG commands * performance is OK, depending on the file being translated. When reading files with UNIX EOLs, the overhead is minimal typically-sized files. For DOS EOLs the overhead is larger but still acceptable. * Return (line feed) is now an immediate editing command. This centralizes EOL sequence insertion. Later, other features like auto-indent could be added to the editing command. * get_eol() has been moved to main.cpp (now called get_eol_seq() * Warn if file ownership could not be preserved when saving files. * IOView has been almost completely rewritten based on GIOChannels. The EOL translation code is also in IOView.
2015-03-16when initializing ncurses, make sure that the output stream is fully bufferedRobin Haberkorn1-0/+1
2015-03-16also set window title on ncurses, by querying terminfo capabilitiesRobin Haberkorn1-3/+62
2015-03-14use g_strerror() instead of strerror() in interface-curses.cppRobin Haberkorn1-1/+1
2015-03-12improved ncurses batch mode initializationRobin Haberkorn1-21/+62
* I now understand better why the old initialization worked ;-) By not calling initscr(), we could prevent some terminal setup and screen clearing usually performed which would interfere with with having a clean stdout stream. However the Curses screen was still basically attached to the terminal. * That's why there was screen flickering in urxvt when calling sciteco (even in batch mode). Also that's why calling batch-mode SciTECO did not work from other Curses programs (including SciTECO). * The new implementation directs Curses at /dev/null, so it will completely stay away from /dev/tty. * /dev/tty is associated with the Curses screen only when the interactive mode is initialized. This works elegantly via freopen() - there's no need to create a new Curses screen. * This does currently not work on PDCurses where the batch mode will still initscr() followed by endwin(). I should investigate how newterm() behaves there - especially on Windows.
2015-03-11Curses UI: beep() on errorRobin Haberkorn1-0/+3
2015-03-11fixed weird colors in rubbed-out command line on PDCurses/win32Robin Haberkorn1-13/+35
2015-03-10avoid frequent info line redraws in Curses and GTK+ UIsRobin Haberkorn1-4/+9
* it is now redrawn once after each key press, even if the info line has not changed. * This is because Interface::update_info() is called very often in interactive mode, so it makes more sense to redraw it after user interaction (where even unnecessary delays are not noticed so easily), than thousands of times in a macro. * This is especially important since InterfaceCurses::update_info() now also sets the Window title on PDCurses - this is a very costly operation. * The same optimization was applied to InterfaceGtk where it is probably greatly responsible for the sluggishness of the UI. The GTK+ changes are currently UNTESTED.
2015-03-10optimized Interface::info_update() implementationsRobin Haberkorn1-5/+5
* use g_strconcat() instead of g_strdup_printf() * InterfaceGtk::info_update() now longer has an arbitrary 255 byte limit on the length of the info line.
2015-03-09fixed displaying of control characters in the "info" line (and window title)Robin Haberkorn1-2/+16
* this relied on Curses' control character drawing on Curses. However it treats tab and line feed differently than other control characters, so registers like "^Mfoo" could not be displayed properly. Even if we can configure Curses to display them correctly, we need a "canonicalized", flat form of strings for other purposes (like setting window titles. This is form is different from the formatting used for command lines which may change anyway once we introduce Scintilla mini buffers. * therefore String::canonicalize_ctl() was introduced * also set window title on PDCurses
2015-03-07fixed crashes on PDCurses/win32 when SciTECO terminates before ↵Robin Haberkorn1-1/+2
Interface::main() was called esp. fixes command line --help on PDCurses/win32
2015-03-07Curses UI: fixed translation of the backspace keyRobin Haberkorn1-2/+11
* for historic reasons, the backspace key can be transmitted as ^H by the terminal. Some terminal emulators might do that - these are fixed by this commit. * Use CTL_KEY('H') instead of standard C '\b' as the former is less ambiguous given the confusion around the backspace character.
2015-03-07cleaned up usage of the escape control character: introduced CTL_KEY_ESC and ↵Robin Haberkorn1-1/+1
CTL_KEY_ESC_STR * the reason for the CTL_KEY() macro is to get the control character resulting from a CTRL+Key press -- at least this is how SciTECO presents these key presses. It is also a macro and may be resolved to a constant expression, so it can be used in switch-case statements. Sometimes it is clearer to use standard C escape sequences (like '\t'). * CTL_KEY('[') for escape is hard to read, so I always used '\x1B' which is even more cryptic.
2015-03-02fixed function key handling on GTK UIRobin Haberkorn1-0/+6
* we cannot prevent GTK from delivering the function key presses, as we can on Curses. Therefore Cmdline::fnmacro() checks again if function keys are enabled.
2015-03-01keep rubbed out command line for later re-insertion and massive Cmdline ↵Robin Haberkorn1-28/+105
cleanup/refactoring * characters rubbed out are not totally removed from the command line, but only from the *effective* command line. * The rubbed out command line is displayed after the command line cursor. On Curses it is grey and underlined. * When characters are inserted that are on the rubbed out part of the command line, the cursor simply moves forward. NOTE: There's currently no immediate editing command for reinserting the next character/word from the rubbed out command line. * Characters resulting in errors are no longer simply discarded but rubbed out, so they will stay in the rubbed out part of the command line, reminding you which character caused the error. * Improved Cmdline formatting on Curses UI: * Asterisk is printed bold * Control characters are printed in REVERSE style, similar to what Scinterm does. The controll character formatting has thus been moved from macro_echo() in cmdline.cpp to the UI implementations. * Updated the GTK+ UI (UNTESTED): I did only, the most important API adaptions. The command line still does not use any colors. * Refactored entire command line handling: * The command line is now a class (Cmdline), and most functions in cmdline.cpp have been converted to methods. * Esp. process_edit_cmd() (now Cmdline::process_edit_cmd()) has been simplified. There is no longer the possibility of a buffer overflow because of static insertion buffer sizes * Cleaned up usage of the cmdline_pos variable (now Cmdline::pc) which is really a program counter that used a different origin as macro_pc which was really confusing. * The new Cmdline class is theoretically 8-bit clean. However all of this will change again when we introduce Scintilla views for the command line. * Added 8-bit clean (null-byte aware) versions of QRegisterData::set_string() and QRegisterData::append_string()
2015-02-11updated copyright to 2015Robin Haberkorn1-1/+1
2014-12-09Curses: support cycling through long lists of possible auto-completions and ↵Robin Haberkorn1-42/+67
optimized screen refreshing/redrawing * pressing e.g. TAB when the popup is showing a list of auto-completions will show the next page, eventually beginning at the first one again. * do not redraw curses windows in the UI methods directly. this resulted in flickering during command-line editing macros and ordinary macro calls because the physical screen was updated immediately. Instead, window refreshing and updated is done centrally in event_loop_iter() only after a key has been processed. Also we use wnoutrefresh() and doupdate() to send as little to the terminal (emulator) as possible.
2014-12-08Curses: fixed formatting of popup windowsRobin Haberkorn1-24/+20
* simplified code * fixed spurious empty lines in the popup which truncated file names/tokens that would otherwise be displayed * fixed memleak when freeing the popup entry list
2014-11-21finally implemented the CLOSE and QUIT hooksRobin Haberkorn1-2/+22
the QUIT hook is actually not that trivial and required some architectural changes. First, the QUIT hook execution and any error that might occurr cannot always be attached to an existing error stack frame. Thereforce, to give a stack frame for QUIT hooks and to improve the readability of error traces for ED hooks in general, a special EDHookFrame is added to every ED hook execution error. Secondly, since QUIT hooks can themselves throw errors, we cannot run it from an atexit() handler. Instead it's always called manually before __successful__ program termination. An error in a QUIT hook will result in a failure return code nevertheless. Thirdly, errors in QUIT hooks should not prevent program termination (in interactive mode), therefore they are only invoked from main() and always in batch mode. I.e. if the interactive mode is terminated (EX$$), SciTECO will switch back to batch mode and run the QUIT hook there. This is also symmetric to program startup, which is always in batch mode. This means that Interface::event_loop() no longer runs indefinitely. If it returns, this signals that the interface shut down and batch mode may be restored by SciTECO.
2014-11-17renamed the "NCurses" UI to "Curses" internallyRobin Haberkorn1-0/+525
* does not change ./configure parameters You still have to specifiy --with-interface=ncurses for the Curses interface with default settings * the "NCurses" UI was used for many different Curses variants, so plain "Curses" is a better name.