1 package com
.googlecode
.lanterna
.input
;
3 import com
.googlecode
.lanterna
.TerminalPosition
;
8 * Pattern used to detect Xterm-protocol mouse events coming in on the standard input channel
9 * Created by martin on 19/07/15.
11 * @author Martin, Andreas
13 public class MouseCharacterPattern
implements CharacterPattern
{
14 private static final char[] PATTERN
= { KeyDecodingProfile
.ESC_CODE
, '[', 'M' };
17 public Matching
match(List
<Character
> seq
) {
18 int size
= seq
.size();
22 // check first 3 chars:
23 for (int i
= 0; i
< 3; i
++) {
25 return Matching
.NOT_YET
; // maybe later
27 if ( seq
.get(i
) != PATTERN
[i
] ) {
32 return Matching
.NOT_YET
; // maybe later
34 MouseActionType actionType
= null;
35 int button
= (seq
.get(3) & 0x3) + 1;
37 //If last two bits are both set, it means button click release
40 int actionCode
= (seq
.get(3) & 0x60) >> 5;
44 actionType
= MouseActionType
.CLICK_DOWN
;
47 actionType
= MouseActionType
.CLICK_RELEASE
;
52 actionType
= MouseActionType
.MOVE
;
55 actionType
= MouseActionType
.DRAG
;
60 actionType
= MouseActionType
.SCROLL_UP
;
64 actionType
= MouseActionType
.SCROLL_DOWN
;
69 TerminalPosition pos
= new TerminalPosition( seq
.get(4) - 33, seq
.get(5) - 33 );
71 MouseAction ma
= new MouseAction(actionType
, button
, pos
);
72 return new Matching( ma
); // yep