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.
Please sign in to leave a comment.
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.
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:
Now, having implemented the provider thus
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?
Yes, now I see, there we have pretty unexpected behavior, namely with USER_INPUT.
We're going to fix the problem soon, thank you!
Can you give me the name of the issue in the tracker so I can subscribe to the updates? Thanks!
https://youtrack.jetbrains.com/issue/IDEA-183871