Files
Upsilon/apps/code/console_store.h
Léa Saviot 35520fb3d4 [code] Scripts can be automatically imported when the console is opened.
Editing, renaming, deleting or changing the auto-importation of a script
triggers the reloading of the console (the history is cleared, Python
restarted and the scripts re-imported).

Change-Id: If8b933cc077ecd36cab09214b5e7a181aa3ae030
2017-11-17 11:59:50 +01:00

43 lines
1.4 KiB
C++

#ifndef CODE_CONSOLE_STORE_H
#define CODE_CONSOLE_STORE_H
#include "console_line.h"
#include <stddef.h>
namespace Code {
class ConsoleStore {
public:
ConsoleStore();
void clear();
ConsoleLine lineAtIndex(int i) const;
int numberOfLines() const;
void pushCommand(const char * text, size_t length);
void pushResult(const char * text, size_t length);
void deleteLastLineIfEmpty();
private:
static constexpr char CommandMarker = 0x01;
static constexpr char ResultMarker = 0x02;
static constexpr int k_historySize = 1024;
void push(const char marker, const char * text, size_t length);
ConsoleLine::Type lineTypeForMarker(char marker) const;
int indexOfNullMarker() const;
void deleteFirstLine();
/* When there is no room left to store a new ConsoleLine, we have to delete
* old ConsoleLines. deleteFirstLine() deletes the first ConsoleLine of
* m_history and shifts the rest of the ConsoleLines towards the beginning of
* m_history. */
void deleteLastLine();
char m_history[k_historySize];
/* The m_history variable sequentially stores an array of ConsoleLine objects.
* Each ConsoleLine is stored as follow:
* - First, a char that says whether the ConsoleLine is a Command or a Result
* - Then, the text content of the ConsoleLine
* - Last but not least, a null byte.
* The buffer ends whenever the marker char is null. */
};
}
#endif