Logo Search packages:      
Sourcecode: jline version File versions  Download package

jline::ConsoleReader::ConsoleReader ( InputStream  in,
Writer  out,
InputStream  bindings,
Terminal  term 
) throws IOException [inline]

Create a new reader.

Parameters:
in the input
out the output
bindings the key bindings to use
term the terminal to use

Loads the key bindings. Bindings file is in the format:

keycode: operation name

Definition at line 210 of file ConsoleReader.java.

References consumeException(), keybindings, KEYMAP_NAMES, setInput(), terminal, and jline::ConsoleOperations::UNKNOWN.

      {
            this.terminal = term;
            setInput (in);
            this.out = out;
            if (bindings == null)
            {
                  String bindingFile = System.getProperty ("jline.keybindings",
                        new File (System.getProperty ("user.home",
                              ".jlinebindings.properties")).getAbsolutePath ());

                  if (!(new File (bindingFile).isFile ()))
                        bindings = ConsoleReader.class.getResourceAsStream (
                              "keybindings.properties");
                  else
                        bindings = new FileInputStream (new File (bindingFile));
            }

            this.keybindings = new short[Byte.MAX_VALUE * 2];

            Arrays.fill (this.keybindings, UNKNOWN);

            /**
             *    Loads the key bindings. Bindings file is in the format:
             *
             *    keycode: operation name
             */
            if (bindings != null)
            {
                  Properties p = new Properties ();
                  p.load (bindings);
                  bindings.close ();

                  for (Iterator i = p.keySet ().iterator (); i.hasNext (); )
                  {
                        String val = (String)i.next ();
                        try
                        {
                              Short code = new Short (val);
                              String op = (String)p.getProperty (val);

                              Short opval = (Short)KEYMAP_NAMES.get (op);

                              if (opval != null)
                                    keybindings[code.shortValue ()] = opval.shortValue ();
                        }
                        catch (NumberFormatException nfe)
                        {
                              consumeException (nfe);
                        }
                  }

                  // hardwired arrow key bindings
                  // keybindings[VK_UP] = PREV_HISTORY;
                  // keybindings[VK_DOWN] = NEXT_HISTORY;
                  // keybindings[VK_LEFT] = PREV_CHAR;
                  // keybindings[VK_RIGHT] = NEXT_CHAR;
            }
      }


Generated by  Doxygen 1.6.0   Back to index