How to intercept changes in the Console?

When I run a console app in intelliJ, it opens up the Console window where I can have input and output, with the input typically colored green. My question: is it possible to intercept these changes in the same way that I can intercept document changes with EditorFactory.eventMulticaster? The critical difference to the multicaster is that I also need to distinguish between program output and user input.

0
5 comments
Avatar
Permanently deleted user

For example, you can register ConsoleInputFilterProvider and provide your own InputFilter just to pass all events through it. InputFiter gets 'an event' as String and ConsoleViewContentType where you can tell predefined USER_INPUT from NORMAL_OUTPUT, ERROR_OUTPUT and others.

0
Avatar
Permanently deleted user

I have implemented it exactly as you suggested, but unfortunately some events seem to be missing. Here's an example, suppose I execute the following:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your name");
String name = br.readLine();
System.out.println("Hello, " + name);

Now, having implemented the provider thus

class ConsoleTracker : ConsoleInputFilterProvider, InputFilter
{
override fun applyFilter(line: String, type: ConsoleViewContentType?): MutableList<Pair<String, ConsoleViewContentType>>
{
println("===== " + line + ";; type = " + type)
return mutableListOf(Pair(line, type!!))
}

override fun getDefaultFilters(project: Project): Array<InputFilter>
{
return arrayOf(this)
}
}

I am expecting the line variable to have the text J, then Jo, then Jon. Instead, when I check the output, I get the following:

===== "C:\Program Files\Java\jdk-9\bin\java" -javaagent:C:\Users\Dmitri\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\173.3727.127\lib\idea_rt.jar=38471:C:\Users\Dmitri\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\173.3727.127\bin -Dfile.encoding=UTF-8 -classpath C:\Users\Dmitri\IdeaProjects\DeleteMe\out\production\DeleteMe com.company.Main
;; type = SYSTEM_OUTPUT
===== Enter your name
;; type = NORMAL_OUTPUT
===== J;; type = USER_INPUT
=====
;; type = USER_INPUT
===== Hello, Jon
;; type = NORMAL_OUTPUT
=====
Process finished with exit code 0
;; type = SYSTEM_OUTPUT

This... makes no sense. Where is 'Jo' and 'Jon'? Am I doing something wrong?

0
Avatar
Permanently deleted user

Yes, now I see, there we have pretty unexpected behavior, namely with USER_INPUT.

We're going to fix the problem soon, thank you!

0
Avatar
Permanently deleted user

Can you give me the name of the issue in the tracker so I can subscribe to the updates? Thanks!

0

Please sign in to leave a comment.