From dbc05e8224c3bfec3b6e5930f7e34e63e6d67302 Mon Sep 17 00:00:00 2001 From: Vladimir Koshelev Date: Fri, 28 Jun 2019 18:29:10 +0300 Subject: [PATCH] fix prompt setting in PydevConsoleExecuteActionHandler GitOrigin-RevId: 97cf650b67a6bf2e2ff04ec80667ddfc017e26b1 --- .../console/ConsolePromptDecorator.kt | 14 ++------ .../PydevConsoleExecuteActionHandler.kt | 36 ++++++++++--------- .../python/console/PythonConsoleView.java | 5 +-- 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/console/ConsolePromptDecorator.kt b/platform/lang-impl/src/com/intellij/execution/console/ConsolePromptDecorator.kt index 5cbbfcfab39d..5e920c45a868 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/ConsolePromptDecorator.kt +++ b/platform/lang-impl/src/com/intellij/execution/console/ConsolePromptDecorator.kt @@ -24,6 +24,8 @@ class ConsolePromptDecorator(private val myEditorEx: EditorEx) : EditorLinePaint var mainPrompt: String = "" set(mainPrompt) { if (this.mainPrompt != mainPrompt) { + // to be compatible with LanguageConsoleView we should reset the indent prompt + indentPrompt = "" field = mainPrompt update() } @@ -38,7 +40,7 @@ class ConsolePromptDecorator(private val myEditorEx: EditorEx) : EditorLinePaint var indentPrompt: String = "" set(indentPrompt) { - field = extend(indentPrompt, mainPrompt.length) + field = indentPrompt update() } @@ -80,16 +82,6 @@ class ConsolePromptDecorator(private val myEditorEx: EditorEx) : EditorLinePaint companion object { private val promptColor = ColorKey.createColorKey("CONSOLE_PROMPT_COLOR") - - private fun extend(s: String, len: Int): String { - var res = s - while (res.length < len) { - res = " $res" - } - - return res - - } } } diff --git a/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.kt b/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.kt index e1826ca1ee90..942725332f44 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.kt +++ b/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.kt @@ -1,21 +1,8 @@ -/* - * Copyright 2000-2014 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. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.console import com.intellij.codeInsight.hint.HintManager +import com.intellij.execution.console.LanguageConsoleImpl import com.intellij.execution.console.LanguageConsoleView import com.intellij.execution.process.ProcessHandler import com.intellij.execution.ui.ConsoleViewContentType @@ -116,6 +103,7 @@ open class PydevConsoleExecuteActionHandler(private val myConsoleView: LanguageC private fun ordinaryPrompt() { if (PyConsoleUtil.ORDINARY_PROMPT != myConsoleView.prompt) { myConsoleView.prompt = PyConsoleUtil.ORDINARY_PROMPT + myConsoleView.indentPrompt = PyConsoleUtil.INDENT_PROMPT PyConsoleUtil.scrollDown(myConsoleView.currentEditor) } } @@ -124,7 +112,7 @@ open class PydevConsoleExecuteActionHandler(private val myConsoleView: LanguageC get() = PyConsoleUtil.getOrCreateIPythonData(myConsoleView.virtualFile).isIPythonEnabled private fun ipythonInPrompt() { - myConsoleView.setPromptAttributes(object : ConsoleViewContentType("", ConsoleViewContentType.USER_INPUT_KEY) { + myConsoleView.setPromptAttributes(object : ConsoleViewContentType("", USER_INPUT_KEY) { override fun getAttributes(): TextAttributes { val attrs = super.getAttributes() attrs.fontType = Font.PLAIN @@ -132,17 +120,22 @@ open class PydevConsoleExecuteActionHandler(private val myConsoleView: LanguageC } }) - myConsoleView.prompt = "In[$myIpythonInputPromptCount]:" + val prompt = "In[$myIpythonInputPromptCount]:" + val indentPrompt = PyConsoleUtil.IPYTHON_INDENT_PROMPT.padStart(prompt.length) + myConsoleView.prompt = prompt + myConsoleView.indentPrompt = indentPrompt PyConsoleUtil.scrollDown(myConsoleView.currentEditor) } private fun executingPrompt() { myConsoleView.prompt = PyConsoleUtil.EXECUTING_PROMPT + myConsoleView.indentPrompt = PyConsoleUtil.EXECUTING_PROMPT } private fun waitingForInputPrompt() { if (PyConsoleUtil.INPUT_PROMPT != myConsoleView.prompt && PyConsoleUtil.HELP_PROMPT != myConsoleView.prompt) { myConsoleView.prompt = PyConsoleUtil.INPUT_PROMPT + myConsoleView.indentPrompt = PyConsoleUtil.INPUT_PROMPT PyConsoleUtil.scrollDown(myConsoleView.currentEditor) } } @@ -156,6 +149,7 @@ open class PydevConsoleExecuteActionHandler(private val myConsoleView: LanguageC } if (prompt != myConsoleView.prompt) { myConsoleView.prompt = prompt + myConsoleView.indentPrompt = prompt PyConsoleUtil.scrollDown(myConsoleView.currentEditor) } } @@ -237,3 +231,11 @@ open class PydevConsoleExecuteActionHandler(private val myConsoleView: LanguageC } } } + +private var LanguageConsoleView.indentPrompt: String + get() { + return (this as? LanguageConsoleImpl)?.consolePromptDecorator?.indentPrompt ?: "" + } + set(value) { + (this as? LanguageConsoleImpl)?.consolePromptDecorator?.indentPrompt = value + } diff --git a/python/src/com/jetbrains/python/console/PythonConsoleView.java b/python/src/com/jetbrains/python/console/PythonConsoleView.java index 645167ca4e5a..ed7c5b49b5de 100644 --- a/python/src/com/jetbrains/python/console/PythonConsoleView.java +++ b/python/src/com/jetbrains/python/console/PythonConsoleView.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.console; import com.intellij.execution.console.ConsolePromptDecorator; @@ -82,7 +82,6 @@ public class PythonConsoleView extends LanguageConsoleImpl implements Observable */ public PythonConsoleView(final Project project, final String title, @Nullable final Sdk sdk, final boolean testMode) { super(project, title, PythonLanguage.getInstance()); - ConsolePromptDecorator promptDecorator = getConsolePromptDecorator(); myTestMode = testMode; isShowVars = PyConsoleOptions.getInstance(project).isShowVariableByDefault(); VirtualFile virtualFile = getVirtualFile(); @@ -103,8 +102,6 @@ public class PythonConsoleView extends LanguageConsoleImpl implements Observable } myPyHighlighter = new PyHighlighter(languageLevel); myScheme = getConsoleEditor().getColorsScheme(); - PythonConsoleData data = PyConsoleUtil.getOrCreateIPythonData(getVirtualFile()); - promptDecorator.setIndentPrompt((data.isIPythonEnabled()) ? PyConsoleUtil.IPYTHON_INDENT_PROMPT : PyConsoleUtil.INDENT_PROMPT); } public void setConsoleCommunication(final ConsoleCommunication communication) {