add support for mouse buttons and wheels

cc #268
This commit is contained in:
Gokcehan 2021-01-19 01:20:05 +03:00
parent af988284a4
commit a13c14fb07
5 changed files with 98 additions and 0 deletions

View File

@ -21,6 +21,7 @@ func run() {
} else if err = screen.Init(); err != nil { } else if err = screen.Init(); err != nil {
log.Fatalf("initializing screen: %s", err) log.Fatalf("initializing screen: %s", err)
} }
screen.EnableMouse()
f, err := os.Create(gLogPath) f, err := os.Create(gLogPath)
if err != nil { if err != nil {

18
doc.go
View File

@ -835,6 +835,24 @@ On these terminals, keys combined with the alt key are prefixed with 'a' charact
Please note that, some key combinations are not possible due to the way terminals work (e.g. control and h combination sends a backspace key instead). Please note that, some key combinations are not possible due to the way terminals work (e.g. control and h combination sends a backspace key instead).
The easiest way to find the name of a key combination is to press the key while lf is running and read the name of the key from the unknown mapping error. The easiest way to find the name of a key combination is to press the key while lf is running and read the name of the key from the unknown mapping error.
Mouse buttons are prefixed with 'm' character:
map <m-1> down # primary
map <m-2> down # secondary
map <m-3> down # middle
map <m-4> down
map <m-5> down
map <m-6> down
map <m-7> down
map <m-8> down
Mouse wheel events are also prefixed with 'm' character:
map <m-up> down
map <m-down> down
map <m-left> down
map <m-right> down
Push Mappings Push Mappings
The usual way to map a key sequence is to assign it to a named or unnamed command. The usual way to map a key sequence is to assign it to a named or unnamed command.

View File

@ -909,6 +909,24 @@ instead). The easiest way to find the name of a key combination is to press
the key while lf is running and read the name of the key from the unknown the key while lf is running and read the name of the key from the unknown
mapping error. mapping error.
Mouse buttons are prefixed with 'm' character:
map <m-1> down # primary
map <m-2> down # secondary
map <m-3> down # middle
map <m-4> down
map <m-5> down
map <m-6> down
map <m-7> down
map <m-8> down
Mouse wheel events are also prefixed with 'm' character:
map <m-up> down
map <m-down> down
map <m-left> down
map <m-right> down
Push Mappings Push Mappings

22
lf.1
View File

@ -1004,6 +1004,28 @@ Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key when
.EE .EE
.PP .PP
Please note that, some key combinations are not possible due to the way terminals work (e.g. control and h combination sends a backspace key instead). The easiest way to find the name of a key combination is to press the key while lf is running and read the name of the key from the unknown mapping error. Please note that, some key combinations are not possible due to the way terminals work (e.g. control and h combination sends a backspace key instead). The easiest way to find the name of a key combination is to press the key while lf is running and read the name of the key from the unknown mapping error.
.PP
Mouse buttons are prefixed with 'm' character:
.PP
.EX
map <m-1> down # primary
map <m-2> down # secondary
map <m-3> down # middle
map <m-4> down
map <m-5> down
map <m-6> down
map <m-7> down
map <m-8> down
.EE
.PP
Mouse wheel events are also prefixed with 'm' character:
.PP
.EX
map <m-up> down
map <m-down> down
map <m-left> down
map <m-right> down
.EE
.SH PUSH MAPPINGS .SH PUSH MAPPINGS
The usual way to map a key sequence is to assign it to a named or unnamed command. While this provides a clean way to remap builtin keys as well as other commands, it can be limiting at times. For this reason 'push' command is provided by lf. This command is used to simulate key pushes given as its arguments. You can 'map' a key to a 'push' command with an argument to create various keybindings. The usual way to map a key sequence is to assign it to a named or unnamed command. While this provides a clean way to remap builtin keys as well as other commands, it can be limiting at times. For this reason 'push' command is provided by lf. This command is used to simulate key pushes given as its arguments. You can 'map' a key to a 'push' command with an argument to create various keybindings.
.PP .PP

39
ui.go
View File

@ -1018,6 +1018,44 @@ func (ui *ui) readNormalEvent(ev tcell.Event) expr {
ui.menuBuf = listBinds(binds) ui.menuBuf = listBinds(binds)
return draw return draw
} }
case *tcell.EventMouse:
var button string
switch tev.Buttons() {
case tcell.Button1:
button = "<m-1>"
case tcell.Button2:
button = "<m-2>"
case tcell.Button3:
button = "<m-3>"
case tcell.Button4:
button = "<m-4>"
case tcell.Button5:
button = "<m-5>"
case tcell.Button6:
button = "<m-6>"
case tcell.Button7:
button = "<m-7>"
case tcell.Button8:
button = "<m-8>"
case tcell.WheelUp:
button = "<m-up>"
case tcell.WheelDown:
button = "<m-down>"
case tcell.WheelLeft:
button = "<m-left>"
case tcell.WheelRight:
button = "<m-right>"
case tcell.ButtonNone:
return nil
}
expr, ok := gOpts.keys[button]
if ok {
return expr
}
return nil
case *tcell.EventResize: case *tcell.EventResize:
return &callExpr{"redraw", nil, 1} return &callExpr{"redraw", nil, 1}
case *tcell.EventError: case *tcell.EventError:
@ -1084,6 +1122,7 @@ func (ui *ui) resume() {
} else if err = screen.Init(); err != nil { } else if err = screen.Init(); err != nil {
log.Fatalf("initializing screen: %s", err) log.Fatalf("initializing screen: %s", err)
} }
screen.EnableMouse()
ui.screen = screen ui.screen = screen