Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move CLI history into the heap #83

Merged
merged 4 commits into from
Oct 20, 2024
Merged

Move CLI history into the heap #83

merged 4 commits into from
Oct 20, 2024

Conversation

stevesims
Copy link
Contributor

Changes how CLI history is recorded, moving it from a static fixed length array of chars to storing pointers to variable length strings in the heap

Duplicate history items are no longer pushed, altho this check is only against the most recent history entry

This gives us a chunk more heap space

first step in moving history to heap
uses less memory :D
when going up/down if the current buffer is smaller than the history entry we need to truncate, otherwise we will overflow and corrupt our heap
@@ -43,7 +43,7 @@ extern BYTE scrcols;

// Storage for the command history
//
static char cmd_history[cmd_historyDepth][cmd_historyWidth + 1];
static char * cmd_history[cmd_historyDepth];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the approach taken here is to use an array of pointers to strings for history entries

I did consider using a linked list, where we'd just store a pointer to the first history entry. this would remove the need to shuffle history entries when we've reached our size limit. for now that approach hasn't been taken

strncpy(cmd_history[history_size++], buffer, cmd_historyWidth); // Save in the history
history_no = history_size;
}
editHistoryPush(buffer);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this switch got refactored to use functions for each history action so as to allow those functions to more easily be refactored to use a different way to store history items

Comment on lines +610 to +619
int i;
umm_free(cmd_history[0]);
for (i = 1; i < history_size; i++) {
cmd_history[i - 1] = cmd_history[i];
}
history_size--;
}
cmd_history[history_size++] = newEntry;
history_no = history_size;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we were using a linked list approach for the history this would be simplified to replace the current "head" of the history list with the new entry (which would point to the previous head), and optionally to trim the list

future ideas/plans for exposing history via system variables could be complicated by that tho, so for now we're using a simple array. when system variables are added and if/when the history gets exposed this idea may be revisited

@stevesims stevesims merged commit 7205031 into main Oct 20, 2024
@stevesims stevesims deleted the rainbow-exp-history branch October 20, 2024 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant