From 948ec4aa5bdf28226cf610232e1e2dcec587952d Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Thu, 4 May 2017 20:42:36 +0300 Subject: [PATCH] [groovy] console: updates - print line after command end instead of printing before each command - print result only when it's present - prepend all user input with '> ' --- .../groovy-psi/resources/conf/console.txt | 5 ++- .../plugins/groovy/console/GroovyConsole.java | 19 +++------ .../groovy/console/GroovyConsoleView.kt | 41 +++++++++++++++++++ 3 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsoleView.kt diff --git a/plugins/groovy/groovy-psi/resources/conf/console.txt b/plugins/groovy/groovy-psi/resources/conf/console.txt index 168b9bb44a47..0a14be0433b7 100644 --- a/plugins/groovy/groovy-psi/resources/conf/console.txt +++ b/plugins/groovy/groovy-psi/resources/conf/console.txt @@ -24,9 +24,10 @@ catch (MissingPropertyException ignore) { try { def result = new GroovyShell(bind).run(((String)line).replaceAll('###\\\\n', '\n'), 'ideaGroovyConsole.groovy') if (result != null) { - System.out.println result + System.out.println 'ee2d5778-e2f4-4705-84ef-0847535c32f4' + result } } catch (Throwable e) { e.printStackTrace() -} \ No newline at end of file +} +System.out.println '01bd8da7-84b0-4f52-9f98-fd15f4dbc1a7' diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java index 55b5b18d406d..521e067b1879 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,8 +64,6 @@ public class GroovyConsole { private final ConsoleView myConsoleView; private final ProcessHandler myProcessHandler; - private boolean first = true; - public GroovyConsole(Project project, RunContentDescriptor descriptor, ConsoleView view, ProcessHandler handler) { myProject = project; myContentDescriptor = descriptor; @@ -74,18 +72,11 @@ public class GroovyConsole { } private void doExecute(@NotNull String command) { - // dirty hack - if (first) { - first = false; - } - else { + for (String line : command.trim().split("\n")) { + myConsoleView.print("> ", ConsoleViewContentType.USER_INPUT); + myConsoleView.print(line, ConsoleViewContentType.USER_INPUT); myConsoleView.print("\n", ConsoleViewContentType.NORMAL_OUTPUT); } - if (!command.endsWith("\n")) command += "\n"; - myConsoleView.print("> ", ConsoleViewContentType.USER_INPUT); - myConsoleView.print(command, ConsoleViewContentType.NORMAL_OUTPUT); - myConsoleView.print("\n", ConsoleViewContentType.NORMAL_OUTPUT); - myConsoleView.print("Result: ", ConsoleViewContentType.SYSTEM_OUTPUT); send(myProcessHandler, StringUtil.replace(command, "\n", "###\\n")); } @@ -150,7 +141,7 @@ public class GroovyConsole { consoleStateService.setFileModule(contentFile, module); final String title = consoleStateService.getSelectedModuleTitle(contentFile); - final ConsoleViewImpl consoleView = new ConsoleViewImpl(project, true); + final ConsoleViewImpl consoleView = new GroovyConsoleView(project); final RunContentDescriptor descriptor = new RunContentDescriptor(consoleView, processHandler, new JPanel(new BorderLayout()), title); final GroovyConsole console = new GroovyConsole(project, descriptor, consoleView, processHandler); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsoleView.kt b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsoleView.kt new file mode 100644 index 000000000000..a174e5e24a77 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsoleView.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.groovy.console + +import com.intellij.execution.impl.ConsoleViewImpl +import com.intellij.execution.ui.ConsoleViewContentType +import com.intellij.openapi.project.Project + +class GroovyConsoleView(project: Project) : ConsoleViewImpl(project, true) { + + companion object { + private val RESULT_MARKER = "ee2d5778-e2f4-4705-84ef-0847535c32f4" + private val COMMAND_END_MARKER = "01bd8da7-84b0-4f52-9f98-fd15f4dbc1a7" + } + + override fun print(text: String, contentType: ConsoleViewContentType) { + if (text.startsWith(RESULT_MARKER)) { + super.print("Result: ", ConsoleViewContentType.SYSTEM_OUTPUT) + super.print(text.substring(RESULT_MARKER.length), contentType) + } + else if (text.startsWith(COMMAND_END_MARKER)) { + super.print("\n", contentType) + } + else { + super.print(text, contentType) + } + } +}