Sergey
Sergey

Reputation: 1089

How to change output of ant <input> task?

Output of task by default look like that:

target name:
     [input] some message:
your input
     [next task]

I'd like to see something like this:

target name:
     [input] some message: your input
     [next task]

How can I make, that task does not put cursor to the new line after message?

Upvotes: 0

Views: 931

Answers (1)

user829876
user829876

Reputation: 733

It can be done, but it is a little bit involved. There is no option on the input task itself for easily doing what you want.

However, in Ant 1.7 or greater, you can control the output (and input) of the input task by providing an input handler. Ant comes shipped with a few input handlers, for example one for secure input that does not echo what you type to the screen. You can, if you want, write your own input handler, and in that way gain full control of what input and output looks like.

To write an input handler you must write a class that implements the InputHandler interface. I recommend you download the Ant source code and take a look at the DefaultInputHandler and create your own version of that, modifying it to suit your needs. In the source for Ant v1.8.3, the prompt and input is implemented like this:

r = new BufferedReader(new InputStreamReader(getInputStream()));
do {
    System.err.println(prompt);
    System.err.flush();
    try {
        String input = r.readLine();
        request.setInput(input);
    } catch (IOException e) {
        throw new BuildException("Failed to read input from"
                                 + " Console.", e);
    }
} while (!request.isInputValid());

I haven't tried it, but changing the println to a print seems like a good idea.

When done, you can point Ant's input task to your compiled input handler using the classname and (for instance) classpath parameters.

Upvotes: 2

Related Questions