mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[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 '> '
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
System.out.println '01bd8da7-84b0-4f52-9f98-fd15f4dbc1a7'
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user