From c6c3e3f34029500f4c0e308bdece2d1a95ec9fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 17 Jan 2020 14:06:15 +0100 Subject: [PATCH] [apps/code] Hide prompt when running script --- apps/code/console_controller.cpp | 20 ++++++++++++++++---- apps/code/console_controller.h | 1 + apps/code/console_store.cpp | 7 ++++--- apps/code/console_store.h | 4 ++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/apps/code/console_controller.cpp b/apps/code/console_controller.cpp index fe6009bcc..0b7796273 100644 --- a/apps/code/console_controller.cpp +++ b/apps/code/console_controller.cpp @@ -34,7 +34,8 @@ ConsoleController::ConsoleController(Responder * parentResponder, App * pythonDe m_editCell(this, pythonDelegate, this), m_scriptStore(scriptStore), m_sandboxController(this, this), - m_inputRunLoopActive(false) + m_inputRunLoopActive(false), + m_preventEdition(false) #if EPSILON_GETOPT , m_locked(lockOnConsole) #endif @@ -76,16 +77,24 @@ void ConsoleController::autoImport() { } void ConsoleController::runAndPrintForCommand(const char * command) { - m_consoleStore.pushCommand(command, strlen(command)); + const char * storedCommand = m_consoleStore.pushCommand(command, strlen(command)); assert(m_outputAccumulationBuffer[0] == '\0'); // Draw the console before running the code - // TODO LEA Hide the input line? m_selectableTableView.reloadData(); m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines()); + m_editCell.setEditing(false); + m_editCell.setText(""); + m_editCell.setPrompt(""); + m_preventEdition = true; AppsContainer::sharedAppsContainer()->redrawWindow(); - runCode(command); + runCode(storedCommand); + + m_preventEdition = false; + m_editCell.setPrompt(sStandardPromptText); + m_editCell.setEditing(true); + flushOutputAccumulationBufferToStore(); m_consoleStore.deleteLastLineIfEmpty(); } @@ -368,6 +377,9 @@ void ConsoleController::resetSandbox() { void ConsoleController::refreshPrintOutput() { m_selectableTableView.reloadData(); m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines()); + if (m_preventEdition) { + m_editCell.setEditing(false); + } AppsContainer::sharedAppsContainer()->redrawWindow(); } diff --git a/apps/code/console_controller.h b/apps/code/console_controller.h index b6a9df39b..49d5a6de8 100644 --- a/apps/code/console_controller.h +++ b/apps/code/console_controller.h @@ -101,6 +101,7 @@ private: SandboxController m_sandboxController; bool m_inputRunLoopActive; bool m_autoImportScripts; + bool m_preventEdition; #if EPSILON_GETOPT bool m_locked; #endif diff --git a/apps/code/console_store.cpp b/apps/code/console_store.cpp index cd3d0445d..8217ce638 100644 --- a/apps/code/console_store.cpp +++ b/apps/code/console_store.cpp @@ -55,8 +55,8 @@ int ConsoleStore::numberOfLines() const { return 0; } -void ConsoleStore::pushCommand(const char * text, size_t length) { - push(CurrentSessionCommandMarker, text, length); +const char * ConsoleStore::pushCommand(const char * text, size_t length) { + return push(CurrentSessionCommandMarker, text, length); } void ConsoleStore::pushResult(const char * text, size_t length) { @@ -91,7 +91,7 @@ int ConsoleStore::deleteCommandAndResultsAtIndex(int index) { return indexOfLineToDelete; } -void ConsoleStore::push(const char marker, const char * text, size_t length) { +const char * ConsoleStore::push(const char marker, const char * text, size_t length) { size_t textLength = length; if (ConsoleLine::sizeOfConsoleLine(length) > k_historySize - 1) { textLength = k_historySize - 1 - 1 - 1; // Marker, null termination and null marker. @@ -105,6 +105,7 @@ void ConsoleStore::push(const char marker, const char * text, size_t length) { m_history[i] = marker; strlcpy(&m_history[i+1], text, minInt(k_historySize-(i+1),textLength+1)); m_history[i+1+textLength+1] = 0; + return &m_history[i+1]; } ConsoleLine::Type ConsoleStore::lineTypeForMarker(char marker) const { diff --git a/apps/code/console_store.h b/apps/code/console_store.h index f5ae9c2b7..ef9bb0ca9 100644 --- a/apps/code/console_store.h +++ b/apps/code/console_store.h @@ -14,7 +14,7 @@ public: void startNewSession(); ConsoleLine lineAtIndex(int i) const; int numberOfLines() const; - void pushCommand(const char * text, size_t length); + const char * pushCommand(const char * text, size_t length); void pushResult(const char * text, size_t length); void deleteLastLineIfEmpty(); int deleteCommandAndResultsAtIndex(int index); @@ -30,7 +30,7 @@ private: } return marker; } - void push(const char marker, const char * text, size_t length); + const char * push(const char marker, const char * text, size_t length); ConsoleLine::Type lineTypeForMarker(char marker) const; int indexOfNullMarker() const; void deleteLineAtIndex(int index);