| 1 | /* |
| 2 | * This file is part of lanterna (http://code.google.com/p/lanterna/). |
| 3 | * |
| 4 | * lanterna is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Lesser General Public License as published by |
| 6 | * the Free Software Foundation, either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * Copyright (C) 2010-2015 Martin |
| 18 | */ |
| 19 | package com.googlecode.lanterna.input; |
| 20 | |
| 21 | import com.googlecode.lanterna.TerminalPosition; |
| 22 | |
| 23 | /** |
| 24 | * This class recognizes character combinations which are actually a cursor position report. See |
| 25 | * <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">Wikipedia</a>'s article on ANSI escape codes for more |
| 26 | * information about how cursor position reporting works ("DSR – Device Status Report"). |
| 27 | * |
| 28 | * @author Martin, Andreas |
| 29 | */ |
| 30 | public class ScreenInfoCharacterPattern extends EscapeSequenceCharacterPattern { |
| 31 | public ScreenInfoCharacterPattern() { |
| 32 | useEscEsc = false; // stdMap and finMap don't matter here. |
| 33 | } |
| 34 | protected KeyStroke getKeyStrokeRaw(char first,int num1,int num2,char last,boolean bEsc) { |
| 35 | if (first != '[' || last != 'R' || num1 == 0 || num2 == 0 || bEsc) { |
| 36 | return null; // nope |
| 37 | } |
| 38 | if (num1 == 1 && num2 <= 8) { |
| 39 | return null; // nope: much more likely it's an F3 with modifiers |
| 40 | } |
| 41 | TerminalPosition pos = new TerminalPosition(num2, num1); |
| 42 | return new ScreenInfoAction(pos); // yep |
| 43 | } |
| 44 | |
| 45 | public static ScreenInfoAction tryToAdopt(KeyStroke ks) { |
| 46 | switch (ks.getKeyType()) { |
| 47 | case CursorLocation: return (ScreenInfoAction)ks; |
| 48 | case F3: // reconstruct position from F3's modifiers. |
| 49 | int col = 1 + (ks.isAltDown() ? ALT : 0) |
| 50 | + (ks.isCtrlDown() ? CTRL : 0) |
| 51 | + (ks.isShiftDown()? SHIFT: 0); |
| 52 | TerminalPosition pos = new TerminalPosition(col,1); |
| 53 | return new ScreenInfoAction(pos); |
| 54 | default: return null; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | |
| 59 | } |