1'use strict';
2
3var EscapeSequences = require('xterm/lib/common/data/EscapeSequences');
4
5var BACKSPACE = 8;
6var PAGE_UP = 33;
7var PAGE_DOWN = 34;
8var END = 35;
9var HOME = 36;
10var INSERT = 45;
11var DEL = 46;
12var F1 = 112;
13var F2 = 113;
14var F3 = 114;
15var F4 = 115;
16var F5 = 116;
17var F6 = 117;
18var F7 = 118;
19var F8 = 119;
20var F9 = 120;
21var F10 = 121;
22var F11 = 122;
23var F12 = 123;
24
25/*
26VT100+ Character and Key Extensions
27
28Character or key  | Character sequence
29---------------------------------------
30HOME key          | <ESC>h
31END key           | <ESC>k
32INSERT key        | <ESC>+
33DELETE key        | <ESC>-
34PAGE UP key       | <ESC>?
35PAGE DOWN key     | <ESC>/
36F1 key            | <ESC>1
37F2 key            | <ESC>2
38F3 key            | <ESC>3
39F4 key            | <ESC>4
40F5 key            | <ESC>5
41F6 key            | <ESC>6
42F7 key            | <ESC>7
43F8 key            | <ESC>8
44F9 key            | <ESC>9
45F10 key           | <ESC>0
46F11 key           | <ESC>!
47F12 key           | <ESC>@
48
49*/
50
51function customVT100PlusKey(ev, term) {
52  var modifiers = (ev.shiftKey ? 1 : 0) | (ev.altKey ? 2 : 0) |
53      (ev.ctrlKey ? 4 : 0) | (ev.metaKey ? 8 : 0);
54  if (((modifiers) && (ev.keyCode != BACKSPACE)) || (ev.type != 'keydown')) {
55    return true;
56  }
57  switch (ev.keyCode) {
58    case BACKSPACE:
59      if (ev.altKey) {
60        return true;
61      } else if (!ev.shiftKey) {
62        term.handler(EscapeSequences.C0.BS);  // Backspace
63      } else {
64        term.handler(EscapeSequences.C0.DEL);  // Delete
65      }
66      break;
67    case PAGE_UP:
68      term.handler(EscapeSequences.C0.ESC + '?');
69      break;
70    case PAGE_DOWN:
71      term.handler(EscapeSequences.C0.ESC + '/');
72      break;
73    case END:
74      term.handler(EscapeSequences.C0.ESC + 'k');
75      break;
76    case HOME:
77      term.handler(EscapeSequences.C0.ESC + 'h');
78      break;
79    case INSERT:
80      term.handler(EscapeSequences.C0.ESC + '+');
81      break;
82    case DEL:
83      term.handler(EscapeSequences.C0.ESC + '-');
84      break;
85    case F1:
86      term.handler(EscapeSequences.C0.ESC + '1');
87      break;
88    case F2:
89      term.handler(EscapeSequences.C0.ESC + '2');
90      break;
91    case F3:
92      term.handler(EscapeSequences.C0.ESC + '3');
93      break;
94    case F4:
95      term.handler(EscapeSequences.C0.ESC + '4');
96      break;
97    case F5:
98      term.handler(EscapeSequences.C0.ESC + '5');
99      break;
100    case F6:
101      term.handler(EscapeSequences.C0.ESC + '6');
102      break;
103    case F7:
104      term.handler(EscapeSequences.C0.ESC + '7');
105      break;
106    case F8:
107      term.handler(EscapeSequences.C0.ESC + '8');
108      break;
109    case F9:
110      term.handler(EscapeSequences.C0.ESC + '9');
111      break;
112    case F10:
113      term.handler(EscapeSequences.C0.ESC + '0');
114      break;
115    case F11:
116      term.handler(EscapeSequences.C0.ESC + '!');
117      break;
118    case F12:
119      term.handler(EscapeSequences.C0.ESC + '@');
120      break;
121    default:
122      return true;
123  }
124  return false;
125}
126exports.customVT100PlusKey = customVT100PlusKey;
127