mirror of https://gitlab.com/nakst/essence
script console: clearing output
This commit is contained in:
parent
dab1cf3efa
commit
27b2c00b97
|
@ -1,14 +1,18 @@
|
||||||
#define ES_INSTANCE_TYPE Instance
|
#define ES_INSTANCE_TYPE Instance
|
||||||
#include <essence.h>
|
#include <essence.h>
|
||||||
|
#include <shared/array.cpp>
|
||||||
|
|
||||||
// TODO Check for heap allocation leaks.
|
// TODO Check for heap allocation leaks.
|
||||||
|
|
||||||
struct Instance : EsInstance {
|
struct Instance : EsInstance {
|
||||||
|
EsCommand commandClearOutput;
|
||||||
|
|
||||||
EsThreadInformation scriptThread;
|
EsThreadInformation scriptThread;
|
||||||
char *inputText;
|
char *inputText;
|
||||||
size_t inputBytes;
|
size_t inputBytes;
|
||||||
|
|
||||||
EsPanel *root;
|
EsPanel *root;
|
||||||
|
EsElement *defaultPrefixDisplay;
|
||||||
EsPanel *inputRow;
|
EsPanel *inputRow;
|
||||||
EsPanel *outputPanel;
|
EsPanel *outputPanel;
|
||||||
EsSpacer *outputDecoration;
|
EsSpacer *outputDecoration;
|
||||||
|
@ -19,6 +23,8 @@ struct Instance : EsInstance {
|
||||||
size_t outputLineBufferAllocated;
|
size_t outputLineBufferAllocated;
|
||||||
bool anyOutput;
|
bool anyOutput;
|
||||||
bool gotREPLResult;
|
bool gotREPLResult;
|
||||||
|
|
||||||
|
Array<EsElement *> outputElements;
|
||||||
};
|
};
|
||||||
|
|
||||||
void AddPrompt(Instance *instance);
|
void AddPrompt(Instance *instance);
|
||||||
|
@ -755,6 +761,7 @@ void ScriptThread(EsGeneric _instance) {
|
||||||
|
|
||||||
if (!instance->anyOutput) {
|
if (!instance->anyOutput) {
|
||||||
EsElementDestroy(EsElementGetLayoutParent(instance->outputPanel));
|
EsElementDestroy(EsElementGetLayoutParent(instance->outputPanel));
|
||||||
|
instance->outputPanel = nullptr;
|
||||||
} else {
|
} else {
|
||||||
instance->anyOutput = false;
|
instance->anyOutput = false;
|
||||||
}
|
}
|
||||||
|
@ -767,7 +774,7 @@ void ScriptThread(EsGeneric _instance) {
|
||||||
EsSpacerChangeStyle(instance->outputDecoration, &styleOutputDecorationFailure);
|
EsSpacerChangeStyle(instance->outputDecoration, &styleOutputDecorationFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
EsSpacerCreate(instance->root, ES_CELL_H_FILL, &styleInterCommandSpacer);
|
instance->outputElements.Add(EsSpacerCreate(instance->root, ES_CELL_H_FILL, &styleInterCommandSpacer));
|
||||||
AddPrompt(instance);
|
AddPrompt(instance);
|
||||||
|
|
||||||
EsMessageMutexRelease();
|
EsMessageMutexRelease();
|
||||||
|
@ -776,15 +783,19 @@ void ScriptThread(EsGeneric _instance) {
|
||||||
void EnterCommand(Instance *instance) {
|
void EnterCommand(Instance *instance) {
|
||||||
EsAssert(instance->inputTextbox);
|
EsAssert(instance->inputTextbox);
|
||||||
EsAssert(instance->inputRow);
|
EsAssert(instance->inputRow);
|
||||||
|
EsAssert(instance->defaultPrefixDisplay);
|
||||||
size_t dataBytes;
|
size_t dataBytes;
|
||||||
char *data = EsTextboxGetContents(instance->inputTextbox, &dataBytes, ES_FLAGS_DEFAULT);
|
char *data = EsTextboxGetContents(instance->inputTextbox, &dataBytes, ES_FLAGS_DEFAULT);
|
||||||
EsElementDestroy(instance->inputRow);
|
EsElementDestroy(instance->inputRow);
|
||||||
|
instance->outputElements.Add(instance->defaultPrefixDisplay);
|
||||||
instance->inputTextbox = nullptr;
|
instance->inputTextbox = nullptr;
|
||||||
instance->inputRow = nullptr;
|
instance->inputRow = nullptr;
|
||||||
|
instance->defaultPrefixDisplay = nullptr;
|
||||||
|
|
||||||
EsPanel *commandLogRow = EsPanelCreate(instance->root, ES_CELL_H_FILL | ES_PANEL_STACK | ES_PANEL_HORIZONTAL, &styleInputRow);
|
EsPanel *commandLogRow = EsPanelCreate(instance->root, ES_CELL_H_FILL | ES_PANEL_STACK | ES_PANEL_HORIZONTAL, &styleInputRow);
|
||||||
EsTextDisplayCreate(commandLogRow, ES_FLAGS_DEFAULT, &stylePromptText, "\u2661");
|
EsTextDisplayCreate(commandLogRow, ES_FLAGS_DEFAULT, &stylePromptText, "\u2661");
|
||||||
EsTextDisplayCreate(commandLogRow, ES_CELL_H_FILL, &styleCommandLogText, data, dataBytes);
|
EsTextDisplayCreate(commandLogRow, ES_CELL_H_FILL, &styleCommandLogText, data, dataBytes);
|
||||||
|
instance->outputElements.Add(commandLogRow);
|
||||||
|
|
||||||
EsAssert(!instance->outputPanel);
|
EsAssert(!instance->outputPanel);
|
||||||
EsAssert(!instance->outputDecoration);
|
EsAssert(!instance->outputDecoration);
|
||||||
|
@ -839,12 +850,17 @@ void AddOutput(Instance *instance, const char *text, size_t textBytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddPrompt(Instance *instance) {
|
void AddPrompt(Instance *instance) {
|
||||||
|
if (instance->outputPanel) {
|
||||||
|
instance->outputElements.Add(EsElementGetLayoutParent(instance->outputPanel));
|
||||||
|
}
|
||||||
|
|
||||||
EsAssert(!instance->inputTextbox);
|
EsAssert(!instance->inputTextbox);
|
||||||
EsAssert(!instance->inputRow);
|
EsAssert(!instance->inputRow);
|
||||||
|
EsAssert(!instance->defaultPrefixDisplay);
|
||||||
instance->outputPanel = nullptr;
|
instance->outputPanel = nullptr;
|
||||||
instance->outputDecoration = nullptr;
|
instance->outputDecoration = nullptr;
|
||||||
|
|
||||||
EsTextDisplayCreate(instance->root, ES_CELL_H_FILL, &stylePathDefaultPrefixDisplay, "Essence HD (0:)");
|
instance->defaultPrefixDisplay = EsTextDisplayCreate(instance->root, ES_CELL_H_FILL, &stylePathDefaultPrefixDisplay, "Essence HD (0:)");
|
||||||
instance->inputRow = EsPanelCreate(instance->root, ES_CELL_H_FILL | ES_PANEL_STACK | ES_PANEL_HORIZONTAL, &styleInputRow);
|
instance->inputRow = EsPanelCreate(instance->root, ES_CELL_H_FILL | ES_PANEL_STACK | ES_PANEL_HORIZONTAL, &styleInputRow);
|
||||||
EsTextDisplayCreate(instance->inputRow, ES_FLAGS_DEFAULT, &stylePromptText, "\u2665");
|
EsTextDisplayCreate(instance->inputRow, ES_FLAGS_DEFAULT, &stylePromptText, "\u2665");
|
||||||
instance->inputTextbox = EsTextboxCreate(instance->inputRow, ES_CELL_H_FILL, &styleInputTextbox);
|
instance->inputTextbox = EsTextboxCreate(instance->inputRow, ES_CELL_H_FILL, &styleInputTextbox);
|
||||||
|
@ -853,10 +869,19 @@ void AddPrompt(Instance *instance) {
|
||||||
EsElementFocus(instance->inputTextbox, ES_ELEMENT_FOCUS_ENSURE_VISIBLE);
|
EsElementFocus(instance->inputTextbox, ES_ELEMENT_FOCUS_ENSURE_VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommandClearOutput(Instance *instance, EsElement *, EsCommand *) {
|
||||||
|
for (uintptr_t i = 0; i < instance->outputElements.Length(); i++) {
|
||||||
|
EsElementDestroy(instance->outputElements[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
instance->outputElements.Free();
|
||||||
|
}
|
||||||
|
|
||||||
int InstanceCallback(Instance *instance, EsMessage *message) {
|
int InstanceCallback(Instance *instance, EsMessage *message) {
|
||||||
if (message->type == ES_MSG_INSTANCE_DESTROY) {
|
if (message->type == ES_MSG_INSTANCE_DESTROY) {
|
||||||
// TODO Stopping the script thread.
|
// TODO Stopping the script thread.
|
||||||
EsHeapFree(instance->outputLineBuffer);
|
EsHeapFree(instance->outputLineBuffer);
|
||||||
|
instance->outputElements.Free();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -879,11 +904,16 @@ void _start() {
|
||||||
if (message->type == ES_MSG_INSTANCE_CREATE) {
|
if (message->type == ES_MSG_INSTANCE_CREATE) {
|
||||||
Instance *instance = EsInstanceCreate(message, "Script Console", -1);
|
Instance *instance = EsInstanceCreate(message, "Script Console", -1);
|
||||||
instance->callback = InstanceCallback;
|
instance->callback = InstanceCallback;
|
||||||
|
EsCommandRegister(&instance->commandClearOutput, instance, EsLiteral("Clear output"), CommandClearOutput,
|
||||||
|
1 /* stableID */, "Ctrl+Shift+L", true /* enabled */);
|
||||||
EsWindowSetIcon(instance->window, ES_ICON_UTILITIES_TERMINAL);
|
EsWindowSetIcon(instance->window, ES_ICON_UTILITIES_TERMINAL);
|
||||||
EsPanel *wrapper = EsPanelCreate(instance->window, ES_CELL_FILL, ES_STYLE_PANEL_WINDOW_DIVIDER);
|
EsPanel *wrapper = EsPanelCreate(instance->window, ES_CELL_FILL, ES_STYLE_PANEL_WINDOW_DIVIDER);
|
||||||
EsPanel *background = EsPanelCreate(wrapper, ES_CELL_FILL | ES_PANEL_V_SCROLL_AUTO, &styleBackground);
|
EsPanel *background = EsPanelCreate(wrapper, ES_CELL_FILL | ES_PANEL_V_SCROLL_AUTO, &styleBackground);
|
||||||
instance->root = EsPanelCreate(background, ES_CELL_H_FILL | ES_PANEL_STACK | ES_PANEL_VERTICAL, &styleRoot);
|
instance->root = EsPanelCreate(background, ES_CELL_H_FILL | ES_PANEL_STACK | ES_PANEL_VERTICAL, &styleRoot);
|
||||||
AddPrompt(instance);
|
AddPrompt(instance);
|
||||||
|
EsElement *toolbar = EsWindowGetToolbar(instance->window);
|
||||||
|
EsCommandAddButton(&instance->commandClearOutput,
|
||||||
|
EsButtonCreate(toolbar, ES_FLAGS_DEFAULT, ES_NULL, EsLiteral("Clear output")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue