aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core-commands.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-02-02 13:17:51 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-02-16 02:20:39 +0300
commitb87c56799ab6f6d651e1dc6c712a625545a4ad5f (patch)
tree726a36ede8cf7a9d310c4299f5fadef6398dcda0 /src/core-commands.c
parent6c500d60eb7df65b0c71e9b0e0955ff581fc3f5a (diff)
downloadsciteco-b87c56799ab6f6d651e1dc6c712a625545a4ad5f.tar.gz
implemented mouse support via special ^KMOUSE and <EJ> with negative keys
* You need to set 0,64ED to enable mouse processing in Curses. It is always enabled in Gtk as it should never make the experience worse. sample.teco_ini enables mouse support, since this should be the new default. `sciteco --no-profile` won't have it enabled, though. * On curses, it requires the ncurses mouse protocol version 2, which will also be supported by PDCurses. * Similar to the Curses API, a special key macro ^KMOUSE is inserted if any of the supported mouse events has been detected. * You can then use -EJ to get the type of mouse event, which can be used with a computed goto in the command-line editing macro. Alternatively, this could have been solved with separate ^KMOUSE:PRESSED, ^KMOUSE:RELEASED etc. pseudo-key macros. * The default ^KMOUSE implementation in fnkeys.tes supports the following: * Left click: Edit command line to jump to position. * Ctrl+left click: Jump to beginning of line. * Right click: Insert position or position range (when dragging). * Double right click: insert range for word under cursor * Ctrl+right click: Insert beginning of line * Scroll wheel: scrolls (faster with shift) * Ctrl+scroll wheel: zoom (GTK-only) * Currently, there is no visual feedback when "selecting" ranges via right-click+drag. This would be tricky to do and most terminal emulators do not appear to support continuous mouse updates.
Diffstat (limited to 'src/core-commands.c')
-rw-r--r--src/core-commands.c146
1 files changed, 109 insertions, 37 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index f74b5f2..0d23adb 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -2221,37 +2221,50 @@ TECO_DEFINE_STATE_CASEINSENSITIVE(teco_state_escape,
* Without any argument ED returns the current flags.
*
* Currently, the following flags are used by \*(ST:
- * - 4: If enabled, prefer raw single-byte ANSI encoding
- * for all new buffers and registers.
- * This does not change the encoding of any existing
- * buffers and any initialized default register when set via
- * \fBED\fP, so you might want to launch \*(ST with \fB--8bit\fP.
- * - 8: Enable/disable automatic folding of case-insensitive
- * command characters during interactive key translation.
- * The case of letter keys is inverted, so one or two
- * character commands will typically be inserted upper-case,
- * but you can still press Shift to insert lower-case letters.
- * Case-insensitive Q-Register specifications are not
- * case folded.
- * This is thought to improve the readability of the command
- * line macro.
- * - 16: Enable/disable automatic translation of end of
- * line sequences to and from line feed.
- * Disabling this flag allows 8-bit clean loading and saving
- * of files.
- * - 32: Enable/Disable buffer editing hooks
- * (via execution of macro in global Q-Register \(lqED\(rq)
- * - 128: Enable/Disable enforcement of UNIX98
- * \(lq/bin/sh\(rq emulation for operating system command
- * executions
- * - 256: Enable/Disable OSC-52 clipboard support.
- * Must only be enabled if the terminal emulator is configured
- * properly.
- * - 512: Enable/Disable Unicode icons in the Curses UI.
- * This requires a capable font, like the ones provided
- * by the \(lqNerd Fonts\(rq project.
- * Changes to this flag in interactive mode may not become
- * effective immediately.
+ * .IP 4: 5
+ * If enabled, prefer raw single-byte ANSI encoding
+ * for all new buffers and registers.
+ * This does not change the encoding of any existing
+ * buffers and any initialized default register when set via
+ * \fBED\fP, so you might want to launch \*(ST with \fB--8bit\fP.
+ * .IP 8:
+ * Enable/disable automatic folding of case-insensitive
+ * command characters during interactive key translation.
+ * The case of letter keys is inverted, so one or two
+ * character commands will typically be inserted upper-case,
+ * but you can still press Shift to insert lower-case letters.
+ * Case-insensitive Q-Register specifications are not
+ * case folded.
+ * This is thought to improve the readability of the command
+ * line macro.
+ * .IP 16:
+ * Enable/disable automatic translation of end of
+ * line sequences to and from line feed.
+ * Disabling this flag allows 8-bit clean loading and saving
+ * of files.
+ * .IP 32:
+ * Enable/Disable buffer editing hooks
+ * (via execution of macro in global Q-Register \(lqED\(rq)
+ * .IP 64:
+ * .SCITECO_TOPIC mouse
+ * Enable/Disable processing and delivery of mouse events in
+ * the Curses UI.
+ * If enabled, the terminal emulator's default mouse behavior
+ * may be inhibited.
+ * .IP 128:
+ * Enable/Disable enforcement of UNIX98
+ * \(lq/bin/sh\(rq emulation for operating system command
+ * executions
+ * .IP 256:
+ * Enable/Disable OSC-52 clipboard support.
+ * Must only be enabled if the terminal emulator is configured
+ * properly.
+ * .IP 512:
+ * Enable/Disable Unicode icons in the Curses UI.
+ * This requires a capable font, like the ones provided
+ * by the \(lqNerd Fonts\(rq project.
+ * Changes to this flag in interactive mode may not become
+ * effective immediately.
*
* The features controlled thus are discribed in other sections
* of this manual.
@@ -2277,9 +2290,10 @@ teco_state_ecommand_flags(teco_machine_main_t *ctx, GError **error)
/*$ EJ properties
* [key]EJ -> value -- Get and set system properties
- * -EJ -> value
* value,keyEJ
* rgb,color,3EJ
+ * -EJ -> event
+ * -2EJ -> y, x
*
* This command may be used to get and set system
* properties.
@@ -2293,16 +2307,16 @@ teco_state_ecommand_flags(teco_machine_main_t *ctx, GError **error)
* write-only or read-only.
*
* The following property keys are defined:
- * .IP 0 4
+ * .IP 0: 4
* The current user interface: 1 for Curses, 2 for GTK
* (\fBread-only\fP)
- * .IP 1
+ * .IP 1:
* The current numbfer of buffers: Also the numeric id
* of the last buffer in the ring. This is implied if
* no argument is given, so \(lqEJ\(rq returns the number
* of buffers in the ring.
* (\fBread-only\fP)
- * .IP 2
+ * .IP 2:
* The current memory limit in bytes.
* This limit helps to prevent dangerous out-of-memory
* conditions (e.g. resulting from infinite loops) by
@@ -2328,7 +2342,7 @@ teco_state_ecommand_flags(teco_machine_main_t *ctx, GError **error)
* this happens you may have to clear your command-line
* first.
* Memory limiting is enabled by default.
- * .IP 3
+ * .IP 3:
* This \fBwrite-only\fP property allows redefining the
* first 16 entries of the terminal color palette \(em a
* feature required by some
@@ -2369,17 +2383,60 @@ teco_state_ecommand_flags(teco_machine_main_t *ctx, GError **error)
* on exit the author is aware of is \fBxterm\fP(1) and
* the Linux console driver.
* You have been warned. Good luck.
- * .IP 4
+ * .IP 4:
* The column after the last horizontal movement.
* This is only used by \fBfnkeys.tes\fP and is similar to the Scintilla-internal
* setting \fBSCI_CHOOSECARETX\fP.
* Unless most other settings, this is on purpose not restored on rubout,
* so it "survives" command line replacements.
+ * .
+ * .IP -1:
+ * Type of the last mouse event (\fBread-only\fP).
+ * One of the following values will be returned:
+ * .RS
+ * . IP 1: 4
+ * Some button has been pressed
+ * . IP 2:
+ * Some button has been released
+ * . IP 3:
+ * Scroll up
+ * . IP 4:
+ * Scroll down
+ * .RE
+ * .IP -2:
+ * Coordinates of the mouse pointer relative to the Scintilla view
+ * at the time of the last mouse event.
+ * This is in pixels or cells depending on the UI.
+ * First the Y coordinate is pushed, followed by the X coordinate,
+ * allowing you to pass them on directly to the \fBSCI_POSITIONFROMPOINT\fP
+ * and similar Scintilla messages using the \fBES\fP command.
+ * (\fBread-only\fP)
+ * .IP -3:
+ * Number of the mouse button involved in the last mouse event, beginning with 1.
+ * Can be -1 if the button cannot be determined or is irrelevant.
+ * (\fBread-only\fP)
+ * .IP -4:
+ * Bit mask describing the key modifiers at the time of the last
+ * mouse event (\fBread-only\fP).
+ * Currently, the following flags are used:
+ * .RS
+ * . IP 1: 4
+ * Shift key
+ * . IP 2:
+ * Control key (CTRL)
+ * . IP 4:
+ * Alt key
+ * .RE
*/
static void
teco_state_ecommand_properties(teco_machine_main_t *ctx, GError **error)
{
enum {
+ EJ_MOUSE_MODS = -4,
+ EJ_MOUSE_BUTTON,
+ EJ_MOUSE_COORD,
+ EJ_MOUSE_TYPE,
+
EJ_USER_INTERFACE = 0,
EJ_BUFFERS,
EJ_MEMORY_LIMIT,
@@ -2442,6 +2499,21 @@ teco_state_ecommand_properties(teco_machine_main_t *ctx, GError **error)
* Get property
*/
switch (property) {
+ case EJ_MOUSE_TYPE:
+ teco_expressions_push(teco_mouse.type);
+ break;
+ case EJ_MOUSE_COORD:
+ /* can be passed down to @ES/POSITIONFROMPOINT// */
+ teco_expressions_push(teco_mouse.y);
+ teco_expressions_push(teco_mouse.x);
+ break;
+ case EJ_MOUSE_BUTTON:
+ teco_expressions_push(teco_mouse.button);
+ break;
+ case EJ_MOUSE_MODS:
+ teco_expressions_push(teco_mouse.mods);
+ break;
+
case EJ_USER_INTERFACE:
/*
* FIXME: Replace INTERFACE_* macros with