/*
 * Copyright (c) 2002-2006, 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 jline.example;

import jline.console.completer.*;
import jline.console.ConsoleReader;

import java.io.*;
import java.util.*;

public class Example
{
    public static void usage() {
        System.out.println("Usage: java " + Example.class.getName()
            + " [none/simple/files/dictionary [trigger mask]]");
        System.out.println("  none - no completors");
        System.out.println("  simple - a simple completor that comples "
            + "\"foo\", \"bar\", and \"baz\"");
        System.out
            .println("  files - a completor that comples " + "file names");
        System.out.println("  dictionary - a completor that comples "
            + "english dictionary words");
        System.out.println("  classes - a completor that comples "
            + "java class names");
        System.out
            .println("  trigger - a special word which causes it to assume "
                + "the next line is a password");
        System.out.println("  mask - is the character to print in place of "
            + "the actual password character");
        System.out.println("\n  E.g - java Example simple su '*'\n"
            + "will use the simple compleator with 'su' triggering\n"
            + "the use of '*' as a password mask.");
    }

    public static void main(String[] args) throws IOException {
        Character mask = null;
        String trigger = null;

        ConsoleReader reader = new ConsoleReader();
        
        reader.setBellEnabled(false);

        if ((args == null) || (args.length == 0)) {
            usage();

            return;
        }

        List<Completer> completors = new LinkedList<Completer>();

        if (args.length > 0) {
            if (args[0].equals("none")) {
            }
            else if (args[0].equals("files")) {
                completors.add(new FileNameCompleter());
            }
            else if (args[0].equals("simple")) {
                completors.add(new StringsCompleter("foo", "bar", "baz"));
            }
            else {
                usage();

                return;
            }
        }

        if (args.length == 3) {
            mask = args[2].charAt(0);
            trigger = args[1];
        }

        for (Completer c : completors) {
            reader.addCompleter(c);
        }

        String line;
        PrintWriter out = new PrintWriter(System.out);

        while ((line = reader.readLine("prompt> ")) != null) {
            out.println("======>\"" + line + "\"");
            out.flush();

            // If we input the special word then we will mask
            // the next line.
            if ((trigger != null) && (line.compareTo(trigger) == 0)) {
                line = reader.readLine("password> ", mask);
            }
            if (line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("exit")) {
                break;
            }
        }
    }
}

@@ -812,121 +812,8 @@
 %22);%0A
-        System.out.println(%22  dictionary - a completor that comples %22%0A            + %22english dictionary words%22);%0A
     
@@ -1177,24 +1177,93 @@
 haracter%22);%0A
+        System.out.println(%22  color - colored prompt and feedback%22);%0A
         Syst
@@ -1573,16 +1573,47 @@
  = null;
+%0A        boolean color = false;
 %0A%0A      
@@ -1704,16 +1704,54 @@
 (false);
+%0A        reader.setPrompt(%22prompt%3E %22);
 %0A%0A      
@@ -2252,32 +2252,212 @@
 ;%0A            %7D%0A
+            else if (args%5B0%5D.equals(%22color%22)) %7B%0A                color = true;%0A                reader.setPrompt(%22%5Cu001B%5B1mfoo%5Cu001B%5B0m@bar%5Cu001B%5B32m@baz%5Cu001B%5B0m%3E %22);%0A            %7D%0A
             else
@@ -2797,16 +2797,70 @@
 tWriter(
+%0A                reader.getTerminal().wrapOutIfNeeded(
 System.o
@@ -2862,16 +2862,17 @@
 tem.out)
+)
 ;%0A%0A     
@@ -2905,26 +2905,16 @@
 eadLine(
-%22prompt%3E %22
 )) != nu
@@ -2915,24 +2915,148 @@
  != null) %7B%0A
+            if (color)%7B%0A                out.println(%22%5Cu001B%5B33m======%3E%5Cu001B%5B0m%5C%22%22 + line + %22%5C%22%22);%0A            %7D else %7B%0A    
             
@@ -3087,32 +3087,46 @@
 + line + %22%5C%22%22);%0A
+            %7D%0A
             out.

Add example for ansi color usage.