wip
This commit is contained in:
@@ -40,6 +40,36 @@ type csiuKey struct {
|
||||
event int
|
||||
}
|
||||
|
||||
// parseSGRMouseWheel decodes the parameter run from an SGR-encoded
|
||||
// mouse press (`CSI < button ; col ; row M`) and returns a row delta
|
||||
// when the event is a scroll wheel. Wheel-up returns -wheelStep,
|
||||
// wheel-down returns +wheelStep. Modifier bits in the button code
|
||||
// (shift=4, alt=8, ctrl=16) are stripped before matching, so e.g.
|
||||
// shift+wheel still scrolls. Non-wheel buttons return false.
|
||||
func parseSGRMouseWheel(params []byte) (int, bool) {
|
||||
const wheelStep = 3
|
||||
// Button code runs up to the first ';'.
|
||||
end := 0
|
||||
for end < len(params) && params[end] != ';' {
|
||||
end++
|
||||
}
|
||||
if end == 0 {
|
||||
return 0, false
|
||||
}
|
||||
btn, err := strconv.Atoi(string(params[:end]))
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
if btn&64 == 0 {
|
||||
return 0, false
|
||||
}
|
||||
// Bit 0 selects up (0) vs down (1) for wheel events.
|
||||
if btn&1 == 0 {
|
||||
return -wheelStep, true
|
||||
}
|
||||
return wheelStep, true
|
||||
}
|
||||
|
||||
// decodeCSIu parses the parameter string of a `CSI ... u` sequence.
|
||||
// The kitty shape is:
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user