mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 04:00:02 +02:00
[python] "input" now displays the provided prompt
This commit is contained in:
committed by
EmilieNumworks
parent
314fde955a
commit
fd7516f8ac
@@ -14,6 +14,8 @@ extern "C" {
|
||||
|
||||
namespace Code {
|
||||
|
||||
static const char * sStandardPromptText = ">>> ";
|
||||
|
||||
ConsoleController::ConsoleController(Responder * parentResponder, ScriptStore * scriptStore) :
|
||||
ViewController(parentResponder),
|
||||
SelectableTableViewDataSource(),
|
||||
@@ -27,6 +29,7 @@ ConsoleController::ConsoleController(Responder * parentResponder, ScriptStore *
|
||||
m_scriptStore(scriptStore),
|
||||
m_sandboxController(this)
|
||||
{
|
||||
m_editCell.setPrompt(sStandardPromptText);
|
||||
for (int i = 0; i < k_numberOfLineCells; i++) {
|
||||
m_cells[i].setParentResponder(&m_selectableTableView);
|
||||
}
|
||||
@@ -75,18 +78,20 @@ void ConsoleController::autoImport() {
|
||||
void ConsoleController::runAndPrintForCommand(const char * command) {
|
||||
m_consoleStore.pushCommand(command, strlen(command));
|
||||
assert(m_outputAccumulationBuffer[0] == '\0');
|
||||
|
||||
runCode(command);
|
||||
flushOutputAccumulationBufferToStore();
|
||||
m_consoleStore.deleteLastLineIfEmpty();
|
||||
}
|
||||
|
||||
const char * ConsoleController::input() {
|
||||
const char * ConsoleController::inputText(const char * prompt) {
|
||||
AppsContainer * a = (AppsContainer *)(app()->container());
|
||||
m_inputRunLoopActive = true;
|
||||
|
||||
m_selectableTableView.reloadData();
|
||||
m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines());
|
||||
m_editCell.setText("???");
|
||||
m_editCell.setPrompt(prompt);
|
||||
m_editCell.setText("");
|
||||
|
||||
a->redrawWindow();
|
||||
a->runWhile([](void * a){
|
||||
@@ -96,6 +101,7 @@ const char * ConsoleController::input() {
|
||||
|
||||
flushOutputAccumulationBufferToStore();
|
||||
m_consoleStore.deleteLastLineIfEmpty();
|
||||
m_editCell.setPrompt(sStandardPromptText);
|
||||
|
||||
return m_editCell.text();
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
// MicroPython::ExecutionEnvironment
|
||||
void displaySandbox() override;
|
||||
void printText(const char * text, size_t length) override;
|
||||
const char * input() override;
|
||||
const char * inputText(const char * prompt) override;
|
||||
|
||||
private:
|
||||
bool inputRunLoopActive() { return m_inputRunLoopActive; }
|
||||
|
||||
@@ -10,7 +10,7 @@ ConsoleEditCell::ConsoleEditCell(Responder * parentResponder, TextFieldDelegate
|
||||
HighlightCell(),
|
||||
Responder(parentResponder),
|
||||
m_textBuffer{0},
|
||||
m_promptView(ConsoleController::k_fontSize, I18n::Message::ConsolePrompt, 0, 0.5),
|
||||
m_promptView(ConsoleController::k_fontSize, nullptr, 0, 0.5),
|
||||
m_textField(this, m_textBuffer, m_textBuffer, TextField::maxBufferSize(), delegate, false, ConsoleController::k_fontSize)
|
||||
{
|
||||
}
|
||||
@@ -29,9 +29,9 @@ View * ConsoleEditCell::subviewAtIndex(int index) {
|
||||
}
|
||||
|
||||
void ConsoleEditCell::layoutSubviews() {
|
||||
KDSize chevronsSize = KDText::stringSize(I18n::translate(I18n::Message::ConsolePrompt), ConsoleController::k_fontSize);
|
||||
m_promptView.setFrame(KDRect(KDPointZero, chevronsSize.width(), bounds().height()));
|
||||
m_textField.setFrame(KDRect(KDPoint(chevronsSize.width(), KDCoordinate(0)), bounds().width() - chevronsSize.width(), bounds().height()));
|
||||
KDSize promptSize = m_promptView.minimalSizeForOptimalDisplay();
|
||||
m_promptView.setFrame(KDRect(KDPointZero, promptSize.width(), bounds().height()));
|
||||
m_textField.setFrame(KDRect(KDPoint(promptSize.width(), KDCoordinate(0)), bounds().width() - promptSize.width(), bounds().height()));
|
||||
}
|
||||
|
||||
void ConsoleEditCell::didBecomeFirstResponder() {
|
||||
@@ -46,6 +46,11 @@ void ConsoleEditCell::setText(const char * text) {
|
||||
m_textField.setText(text);
|
||||
}
|
||||
|
||||
void ConsoleEditCell::setPrompt(const char * prompt) {
|
||||
m_promptView.setText(prompt);
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
bool ConsoleEditCell::insertText(const char * text) {
|
||||
bool didCopy = m_textField.insertTextAtLocation(text, m_textField.cursorLocation());
|
||||
if (didCopy) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <escher/highlight_cell.h>
|
||||
#include <escher/text_field.h>
|
||||
#include <escher/text_field_delegate.h>
|
||||
#include <escher/message_text_view.h>
|
||||
#include <escher/pointer_text_view.h>
|
||||
|
||||
namespace Code {
|
||||
|
||||
@@ -31,10 +31,10 @@ public:
|
||||
const char * text() const { return m_textField.text(); }
|
||||
void setText(const char * text);
|
||||
bool insertText(const char * text);
|
||||
|
||||
void setPrompt(const char * prompt);
|
||||
private:
|
||||
char m_textBuffer[TextField::maxBufferSize()];
|
||||
MessageTextView m_promptView;
|
||||
PointerTextView m_promptView;
|
||||
TextField m_textField;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user