diff --git a/apps/code/console_controller.cpp b/apps/code/console_controller.cpp index 13acc6965..81c7c2b67 100644 --- a/apps/code/console_controller.cpp +++ b/apps/code/console_controller.cpp @@ -91,25 +91,46 @@ const char * ConsoleController::inputText(const char * prompt) { AppsContainer * a = (AppsContainer *)(app()->container()); m_inputRunLoopActive = true; - // Set the prompt text - m_selectableTableView.reloadData(); - m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines()); - m_editCell.setPrompt(prompt); + const char * promptText = prompt; + /* Set the prompt text. If the prompt text has a '\n', put the prompt text in + * the history until the last '\n', and put the remaining prompt text in the + * edit cell's prompt. */ + char * lastCarriageReturn = nullptr; + char * s = const_cast(prompt); + while (*s != 0) { + if (*s == '\n') { + lastCarriageReturn = s; + } + s++; + } + if (lastCarriageReturn != nullptr) { + printText(prompt, lastCarriageReturn-prompt+1); + promptText = lastCarriageReturn+1; + } + + m_editCell.setPrompt(promptText); m_editCell.setText(""); - // Run new input loop + // Reload the history + m_selectableTableView.reloadData(); + m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines()); a->redrawWindow(); + + // Launch a new input loop a->runWhile([](void * a){ ConsoleController * c = static_cast(a); return c->inputRunLoopActive(); }, this); - // Reset the prompt line + // Handle the input text + printText(promptText, s - promptText); + const char * text = m_editCell.text(); + printText(text, strlen(text)); flushOutputAccumulationBufferToStore(); - m_consoleStore.deleteLastLineIfEmpty(); + m_editCell.setPrompt(sStandardPromptText); - return m_editCell.text(); + return text; } void ConsoleController::viewWillAppear() { diff --git a/python/port/builtins.c b/python/port/builtins.c index a04ad75c6..fa0e1f3be 100644 --- a/python/port/builtins.c +++ b/python/port/builtins.c @@ -15,17 +15,11 @@ mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) { prompt = mp_obj_str_get_str(args[0]); } - // 2 - Perform the HAL input command + // 2 - Perform the HAL input command. This logs the prompt and the result const char * result = mp_hal_input(prompt); - // 3 - Log the prompt, result and flush a new line + // 3 - Return the input mp_obj_t resultStr = mp_obj_new_str(result, strlen(result)); - if (n_args == 1) { - mp_obj_print(args[0], PRINT_STR); - } - mp_obj_print(resultStr, PRINT_STR); - mp_print_str(MP_PYTHON_PRINTER, "\n"); - return resultStr; } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input);