예제 #1
0
  public static void main(String[] args) {
    KeyBinding bind;
    if ("-tsv".equals(args[0])) {
      bind = loadKeyBindingFromTsv(args[1], args[2], args[3]);
      bind.save(args[4]);
      return;
    } else {
      try {
        bind = KeyBinding.load(args[0]);
      } catch (LoadingException ex) {
        throw new RuntimeException(ex);
      }
    }

    if ("-value".equals(args[1])) {
      KeyBinding ret = KeyBinding.newLike(bind);
      Output out = new OutputKeyBinding(ret);

      Pusher p = new Pusher();
      for (int i = 2; i < args.length; i++) {
        p.onlyIf(new IfEquals(bind.getColumnName(1), args[i]), out);
      }
      p.push(new InputKeyBinding(bind));
      ret.dumpTsv(System.out);
    } else if ("-count".equals(args[1])) {
      Pusher p = new Pusher();
      for (int i = 2; i < args.length; i++) {
        p.onlyIf(new IfEquals(bind.getColumnName(1), args[i]), new BreakAfter(args[i]));
      }
      p.push(new InputKeyBinding(bind));
    } else if ("-dump".equals(args[1])) {
      bind.dumpTsv(System.out);
    } else if ("-prompt".equals(args[1])) {
      try {
        jline.ConsoleReader reader = new jline.ConsoleReader();
        reader.setBellEnabled(false);
        reader.getHistory().setHistoryFile(new File(".KeyBinding.history"));
        String line = null;
        System.err.println("=== Enter Keys ===");
        while ((line = reader.readLine("keys> ")) != null) {
          if (!line.trim().isEmpty()) {
            for (String k : line.split("\\s+")) {
              System.out.print(k);
              System.out.print('\t');
              if (bind.contains(k)) {
                System.out.print(bind.get(k));
              } else {
                System.out.print("false");
              }
              System.out.println();
            }
          }
        }
      } catch (IOException ioex) {
        ioex.printStackTrace();
      }
    } else {
      int i = 1;
      if ("-key".equals(args[1])) {
        i = 2;
      }
      for (; i < args.length; i++) {
        System.out.print(args[i]);
        System.out.print('\t');
        if (bind.contains(args[i])) {
          System.out.print(bind.get(args[i]));
        } else {
          System.out.print("false");
        }
        System.out.println();
      }
    }
  }
예제 #2
0
 public static KeyBinding newLike(KeyBinding like) {
   return new KeyBinding(like.getColumnName(0), like.getColumnName(1));
 }