summaryrefslogtreecommitdiff
path: root/src/jline/src/main/java/scala/tools/jline/console/Key.java
blob: 26528555df0231a09510099e2f82927197176b8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright (c) 2002-2007, Marc Prud'hommeaux. All rights reserved.
 *
 * This software is distributable under the BSD license. See the terms of the
 * BSD license in the documentation provided with this software.
 */

package scala.tools.jline.console;

import java.util.HashMap;
import java.util.Map;

/**
 * Map from key name to key codes.
 *
 * @author <a href="mailto:mwp1@cornell.edu">Marc Prud'hommeaux</a>
 * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
 * @see java.awt.event.KeyEvent
 * @since 2.0
 */
public enum Key
{
    CTRL_A(1),

    CTRL_B(2),

    CTRL_C(3),

    CTRL_D(4),

    CTRL_E(5),

    CTRL_F(6),

    CTRL_G(7),

    CTRL_K(11),

    CTRL_L(12),

    CTRL_N(14),

    CTRL_O(15),

    CTRL_P(16),

    CTRL_T(20),

    CTRL_W(23),

    CTRL_OB(27),

    CTRL_QM(127),

    BACKSPACE('\b'),

    DELETE(127),;

    public final short code;

    Key(final int code) {
        this.code = (short) code;
    }

    private static final Map<Short, Key> codes;

    static {
        Map<Short, Key> map = new HashMap<Short, Key>();

        for (Key op : Key.values()) {
            map.put(op.code, op);
        }

        codes = map;
    }

    public static Key valueOf(final int code) {
        return codes.get((short) code);
    }
}