KeyMap { public static String display(String key) { StringBuilder sb = new StringBuilder(); sb.append("\""); for (int i = 0; i < key.length(); i++) { char c = key.charAt(i); if (c < 32) { sb.append('^'); sb.append((char) (c + 'A' - 1)); } else if (c == 127) { sb.append("^?"); } else if (c == '^' || c == '\\') { sb.append('\\').append(c); } else if (c >= 128) { sb.append(String.format("\\u%04x", (int) c)); } else { sb.append(c); } } sb.append("\""); return sb.toString(); }  static String display(String key); static String translate(String str); static Collection<String> range(String range); static String esc(); static String alt(char c); static String alt(String c); static String del(); static String ctrl(char key); static String key(Terminal terminal, Capability capability); T getUnicode(); void setUnicode(T unicode); T getNomatch(); void setNomatch(T nomatch); long getAmbiguousTimeout(); void setAmbiguousTimeout(long ambiguousTimeout); T getAnotherKey(); Map<String, T> getBoundKeys(); @SuppressWarnings("unchecked") T getBound(CharSequence keySeq, int[] remaining); T getBound(CharSequence keySeq); void bindIfNotBound(T function, CharSequence keySeq); void bind(T function, CharSequence... keySeqs); void bind(T function, Iterable<? extends CharSequence> keySeqs); void bind(T function, CharSequence keySeq); void unbind(CharSequence... keySeqs); void unbind(CharSequence keySeq); static final int KEYMAP_LENGTH; static final long DEFAULT_AMBIGUOUS_TIMEOUT; static final Comparator<String> KEYSEQ_COMPARATOR; }
@Test public void testDisplay() { assertEquals("\"\\\\^G^H^[^L^J^M^I\\u0098\\u2345\"", display("\\\u0007\b\u001b\f\n\r\t\u0098\u2345")); assertEquals("\"^A^B^C^?\\^\\\\\"", display("\u0001\u0002\u0003\u007f^\\")); }