18 if (k_historySize < 1) {
22 m_history[0] = makePrevious(m_history[0]);
24 for (
int i = 0; i < k_historySize - 1; i++) {
25 if (m_history[i] == 0) {
26 if (m_history[i+1] == 0) {
29 m_history[i+1] = makePrevious(m_history[i+1]);
36 int currentLineIndex = 0;
37 for (
int j=0; j<k_historySize; j++) {
38 if (m_history[j] == 0) {
42 if (currentLineIndex == i) {
43 return ConsoleLine(lineTypeForMarker(m_history[j]), m_history+j+1);
51 if (m_history[0] == 0) {
55 for (
int i = 0; i < k_historySize - 1; i++) {
56 if (m_history[i] == 0) {
58 if (m_history[i+1] == 0) {
68 push(CurrentSessionCommandMarker, text, length);
72 push(CurrentSessionResultMarker, text, length);
77 char lastLineFirstChar = lastLine.
text()[0];
78 if (lastLineFirstChar == 0 || lastLineFirstChar ==
'\n') {
85 assert(index >= 0 && index < numberOfLinesAtStart);
86 int indexOfLineToDelete = index;
87 while (indexOfLineToDelete < numberOfLinesAtStart - 1) {
88 if (
lineAtIndex(indexOfLineToDelete + 1).isCommand()) {
91 indexOfLineToDelete++;
94 while (indexOfLineToDelete > 0 && !
lineAtIndex(indexOfLineToDelete).isCommand()) {
95 deleteLineAtIndex(indexOfLineToDelete);
96 indexOfLineToDelete--;
99 deleteLineAtIndex(indexOfLineToDelete);
100 return indexOfLineToDelete;
103 void ConsoleStore::push(
const char marker,
const char * text,
size_t length) {
104 size_t textLength = length;
106 textLength = k_historySize - 1 - 1 - 1;
108 int i = indexOfNullMarker();
112 i = indexOfNullMarker();
114 m_history[i] = marker;
115 strlcpy(&m_history[i+1], text, textLength+1);
116 m_history[i+1+length+1] = 0;
120 assert(marker == CurrentSessionCommandMarker || marker == CurrentSessionResultMarker || marker == PreviousSessionCommandMarker || marker == PreviousSessionResultMarker);
124 int ConsoleStore::indexOfNullMarker()
const {
125 if (m_history[0] == 0) {
128 for (
int i=0; i<k_historySize; i++) {
129 if (m_history[i] == 0 && m_history[i+1] == 0) {
137 void ConsoleStore::deleteLineAtIndex(
int index) {
139 int currentLineIndex = 0;
140 for (
int i = 0; i < k_historySize - 1; i++) {
141 if (m_history[i] == 0) {
145 if (currentLineIndex == index) {
146 int nextLineStart = i;
147 while (m_history[nextLineStart] != 0 && nextLineStart < k_historySize - 2) {
151 memcpy(&m_history[i], &m_history[nextLineStart], (k_historySize - 1) - nextLineStart + 1);
157 void ConsoleStore::deleteFirstLine() {
158 if (m_history[0] == 0) {
161 int secondLineMarkerIndex = 1;
162 while (m_history[secondLineMarkerIndex] != 0) {
163 secondLineMarkerIndex++;
165 secondLineMarkerIndex++;
166 for (
int i=0; i<k_historySize - secondLineMarkerIndex; i++) {
167 m_history[i] = m_history[secondLineMarkerIndex+i];
171 void ConsoleStore::deleteLastLine() {
176 if (lineCount == 1) {
180 int currentLineIndex = 1;
181 int lastLineMarkerIndex = 0;
182 for (
int i=0; i<k_historySize; i++) {
183 if (m_history[i] == 0) {
185 if (currentLineIndex == lineCount) {
186 lastLineMarkerIndex = i+1;
191 m_history[lastLineMarkerIndex] = 0;
static size_t sizeOfConsoleLine(size_t textLength)
int deleteCommandAndResultsAtIndex(int index)
int numberOfLines() const
size_t strlcpy(char *dst, const char *src, size_t len)
const char * text() const
void deleteLastLineIfEmpty()
void pushCommand(const char *text, size_t length)
void pushResult(const char *text, size_t length)
ConsoleLine lineAtIndex(int i) const
void * memcpy(void *dst, const void *src, size_t n)