Simple example not working when run from IntelliJ in Windows

503 views
Skip to first unread message

Alan Evans

unread,
Sep 13, 2015, 3:02:55 PM9/13/15
to jline-users
I am using IntelliJ on windows. I have based a simple example on the example here https://github.com/jline/jline2/blob/master/src/test/java/jline/example/Example.java

Jline 2.12

--
package com.example;

import jline.console.ConsoleReader;

import java.io.IOException;
import java.io.PrintWriter;

public class Main {
public static void main(String[] args) throws IOException {

ConsoleReader reader = new ConsoleReader();
reader.setPrompt("p> ");

String line;
PrintWriter out = new PrintWriter(reader.getOutput());

while ((line = reader.readLine()) != null) {
System.out.println(line);
out.println("Echo: " + line);
out.flush();
}
}
}
--

Nothing comes out after the first prompt when I run within IntelliJ.

"C:\Program ...
p> Nothing happens after return

It works when I run in a normal cmd window.

This is symptomatic of System.in not being wrapped in a BufferedReader like so:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Can I force this behavior somehow?



Andrew M

unread,
Jan 11, 2016, 6:26:22 PM1/11/16
to jline-users
Does anyone have a solution for using IntelliJ IDEA with JLine 2?  It seems to be impossible to run JLine apps in Intellil IDEA's debugger since the console input is not being read.  I can see characters I type but they have on effect.  My code looks like:

ConsoleReader console = new ConsoleReader();
console.setPrompt("> ");
String line = null;
while ( (line = console.readLine()) != null ) {
System.out.println("line='"+line+"'"); // <-- NEVER RUNS IN INTELLIJ
}
Reply all
Reply to author
Forward
0 new messages