Skip to content

Commit

Permalink
Add --wheel-lines option.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Nov 7, 2018
1 parent 8a604bb commit dd8c4cd
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 21 deletions.
2 changes: 2 additions & 0 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
#define A_CLRMARK 62
#define A_SETMARKBOT 63
#define A_X11MOUSE_IN 64
#define A_F_MOUSE 65
#define A_B_MOUSE 66

#define A_INVALID 100
#define A_NOACTION 101
Expand Down
17 changes: 17 additions & 0 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern struct scrpos initial_scrpos;
extern IFILE curr_ifile;
extern void *ml_search;
extern void *ml_examine;
extern int mouse_lines;
#if SHELL_ESCAPE || PIPEC
extern void *ml_shell;
#endif
Expand Down Expand Up @@ -1280,6 +1281,22 @@ commands()
backward((int) number, 0, 0);
break;

case A_F_MOUSE:
/*
* Forward mouse_lines lines.
*/
cmd_exec();
forward(mouse_lines, 0, 0);
break;

case A_B_MOUSE:
/*
* Backward mouse_lines lines.
*/
cmd_exec();
backward(mouse_lines, 0, 0);
break;

case A_FF_LINE:
/*
* Force forward N (default 1) line.
Expand Down
4 changes: 2 additions & 2 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ x11mouse_action()
default:
return (A_NOACTION);
case X11MOUSE_WHEEL_DOWN:
return ((mousecap == OPT_ONPLUS) ? A_B_LINE : A_F_LINE);
return ((mousecap == OPT_ONPLUS) ? A_B_MOUSE : A_F_MOUSE);
case X11MOUSE_WHEEL_UP:
return ((mousecap == OPT_ONPLUS) ? A_F_LINE : A_B_LINE);
return ((mousecap == OPT_ONPLUS) ? A_F_MOUSE : A_B_MOUSE);
case X11MOUSE_BUTTON_REL:
/*
* {{ It would be better to do this in commands()
Expand Down
44 changes: 26 additions & 18 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -938,35 +938,43 @@ If the reopen succeeds and the file is a different file from the original
with the same name as the original (now renamed) file),
.I less
will display the contents of that new file.
.IP "\-\-mouse"
Enables mouse input:
scrolling the mouse wheel down moves forward in the file,
scrolling the mouse wheel up moves backwards in the file,
and clicking the mouse will set the "#" mark to the line
on which the mouse cursor sits.
The number of lines to scroll when the wheel is moved
can be set by the \-\-wheel-lines option.
Mouse input works only on terminals which support X11 mouse reporting
and on the Windows version.
.IP "\-\-MOUSE"
Like \-\-mouse, except the scrolling direction is reversed.
.IP "\-\-no-keypad"
Disables sending the keypad initialization and deinitialization strings
to the terminal.
This is sometimes useful if the keypad strings make the numeric
keypad behave in an undesirable manner.
.IP "\-\-use-backslash"
This option changes the interpretations of options which follow this one.
After the \-\-use-backslash option, any backslash in an option string is
removed and the following character is taken literally.
This allows a dollar sign to be included in option strings.
.IP "\-\-rscroll"
This option changes the character used to mark truncated lines.
It may begin with a two-character attribute indicator like LESSBINFMT does.
If there is no attribute indicator, standout is used.
If set to "-", truncated lines are not marked.
.IP "\-\-nohistdups"
This option changes the behavior so that if a search string or
file name is typed in, and the same string is already in the history list,
the existing copy is removed from the history list before the new one is added.
Thus, a given string will appear only once in the history list.
Normally, a string may appear multiple times.
.IP "\-\-mouse"
Enables mouse input:
scrolling the mouse wheel down moves forward in the file,
scrolling the mouse wheel up moves backwards in the file,
and clicking the mouse will set the "#" mark to the line on which the mouse cursor sits.
Mouse input works only on terminals which support X11 mouse reporting.
.IP "\-\-MOUSE"
Like \-\-mouse, except the scrolling direction is reversed.
.IP "\-\-rscroll"
This option changes the character used to mark truncated lines.
It may begin with a two-character attribute indicator like LESSBINFMT does.
If there is no attribute indicator, standout is used.
If set to "-", truncated lines are not marked.
.IP "\-\-use-backslash"
This option changes the interpretations of options which follow this one.
After the \-\-use-backslash option, any backslash in an option string is
removed and the following character is taken literally.
This allows a dollar sign to be included in option strings.
.IP "\-\-wheel-lines=\fIn\fP"
Set the number of lines to scroll when the mouse wheel is scrolled
and the \-\-mouse or \-\-MOUSE option is in effect.
The default is 1 line.
.IP \-\-
A command line argument of "\-\-" marks the end of option arguments.
Any arguments following this are interpreted as filenames.
Expand Down
32 changes: 32 additions & 0 deletions optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

#include "less.h"
#include "option.h"
#if MSDOS_COMPILER==WIN32C
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x400
#include <windows.h>
#endif

extern int nbufs;
extern int bufspace;
Expand All @@ -45,6 +50,7 @@ extern int shift_count;
extern long shift_count_fraction;
extern char rscroll_char;
extern int rscroll_attr;
extern int mouse_lines;
extern int less_is_more;
#if LOGFILE
extern char *namelogfile;
Expand Down Expand Up @@ -809,6 +815,32 @@ opt_query(type, s)
}
}

/*
* Handler for the --wheel-lines option.
*/
/*ARGSUSED*/
public void
opt_mouselines(type, s)
int type;
char *s;
{
switch (type)
{
case INIT:
case TOGGLE:
if (mouse_lines <= 0)
{
mouse_lines = 1;
#if MSDOS_COMPILER==WIN32C
SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &mouse_lines, 0);
#endif
}
break;
case QUERY:
break;
}
}

/*
* Get the "screen window" size.
*/
Expand Down
12 changes: 11 additions & 1 deletion opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public char rscroll_char; /* Char which marks chopped lines with -S */
public int rscroll_attr; /* Attribute of rscroll_char */
public int no_hist_dups; /* Remove dups from history list */
public int mousecap; /* Allow mouse for scrolling */
public int mouse_lines; /* Number of lines to scroll on mouse scroll */
#if HILITE_SEARCH
public int hilite_search; /* Highlight matched search patterns? */
#endif
Expand Down Expand Up @@ -117,6 +118,7 @@ static struct optname use_backslash_optname = { "use-backslash", NULL };
static struct optname rscroll_optname = { "rscroll", NULL };
static struct optname nohistdups_optname = { "nohistdups", NULL };
static struct optname mousecap_optname = { "mouse", NULL };
static struct optname mouse_lines_optname = { "wheel-lines", NULL };


/*
Expand Down Expand Up @@ -469,13 +471,21 @@ static struct loption option[] =
}
},
{ OLETTER_NONE, &mousecap_optname,
TRIPLE, OPT_OFF, &mousecap, NULL,
TRIPLE|NO_TOGGLE, OPT_OFF, &mousecap, NULL,
{
"Ignore mouse input",
"Use the mouse for scrolling",
"Use the mouse for scrolling (reverse)"
}
},
{ OLETTER_NONE, &mouse_lines_optname,
NUMBER|INIT_HANDLER, 0, &mouse_lines, opt_mouselines,
{
"Lines to scroll on mouse wheel: ",
"Scroll %d line(s) on mouse wheel",
NULL
}
},
{ '\0', NULL, NOVAR, 0, NULL, NULL, { NULL, NULL, NULL } }
};

Expand Down

0 comments on commit dd8c4cd

Please sign in to comment.