Skip to content

Commit ce61942

Browse files
author
Roberto De Ioris
committed
added support for multiline commands in the python console
1 parent 605f89a commit ce61942

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Source/PythonConsole/Private/SPythonLog.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ void SPythonConsoleInputBox::Construct(const FArguments& InArgs)
172172

173173
SPythonConsoleEditableTextBox *TextBox = (SPythonConsoleEditableTextBox *)InputText.Get();
174174
TextBox->SetPythonBox(this);
175+
IsMultiline = false;
175176
}
176177
void SPythonConsoleInputBox::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
177178
{
@@ -211,10 +212,30 @@ void SPythonConsoleInputBox::OnTextCommitted(const FText& InText, ETextCommit::T
211212
// Here run the python code
212213
//
213214
FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>("UnrealEnginePython");
214-
PythonModule.RunString(TCHAR_TO_UTF8(*ExecString));
215215

216+
if (IsMultiline) {
217+
if (ExecString.StartsWith(" ")) {
218+
MultilineString += FString("\n") + ExecString;
219+
}
220+
else {
221+
IsMultiline = false;
222+
PythonModule.RunString(TCHAR_TO_UTF8(*MultilineString));
223+
}
224+
}
225+
else if (ExecString.EndsWith(":")) {
226+
IsMultiline = true;
227+
MultilineString = ExecString;
228+
}
229+
else {
230+
PythonModule.RunString(TCHAR_TO_UTF8(*ExecString));
231+
}
216232

217233
}
234+
else if (IsMultiline) {
235+
IsMultiline = false;
236+
FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>("UnrealEnginePython");
237+
PythonModule.RunString(TCHAR_TO_UTF8(*MultilineString));
238+
}
218239

219240
}
220241

Source/PythonConsole/Private/SPythonLog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class SPythonConsoleInputBox
6464
TArray<FString> History;
6565
int HistoryPosition;
6666

67+
FString MultilineString;
68+
bool IsMultiline;
69+
6770

6871
protected:
6972

0 commit comments

Comments
 (0)