More linebuffers to shell

This commit is contained in:
MichaelDvP
2021-04-21 07:43:03 +02:00
parent 462a91b122
commit cf641476bf
2 changed files with 28 additions and 9 deletions

View File

@@ -65,8 +65,10 @@ void Shell::start() {
#endif #endif
line_buffer_.reserve(maximum_command_line_length_); line_buffer_.reserve(maximum_command_line_length_);
line_old_.reserve(maximum_command_line_length_); for (uint8_t i = 0; i < MAX_LINES; i++) {
line_old_.clear(); line_old_[i].reserve(maximum_command_line_length_);
line_old_[i].clear();
}
display_banner(); display_banner();
display_prompt(); display_prompt();
shells_.insert(shared_from_this()); shells_.insert(shared_from_this());
@@ -214,10 +216,20 @@ void Shell::loop_normal() {
default: default:
if (esc_) { if (esc_) {
if (c == 'A') { // cursor up if (c == 'A') { // cursor up
line_buffer_ = line_old_; line_buffer_ = line_old_[line_no_];
if (line_no_ < MAX_LINES - 1) {
line_no_++;
}
cursor_ = 0; cursor_ = 0;
} else if (c == 'B') { // cursor down } else if (c == 'B') { // cursor down
if (line_no_) {
line_no_--;
}
if (line_no_) {
line_buffer_ = line_old_[line_no_ - 1];
} else {
line_buffer_.clear(); line_buffer_.clear();
}
cursor_ = 0; cursor_ = 0;
} else if (c == 'C') { // cursor right } else if (c == 'C') { // cursor right
if (cursor_) { if (cursor_) {
@@ -498,7 +510,12 @@ void Shell::process_command() {
println(); println();
return; return;
} }
line_old_ = line_buffer_; uint8_t no = line_no_ ? line_no_ : MAX_LINES;
while (--no) {
line_old_[no] = line_old_[no - 1];
}
line_no_ = 0;
line_old_[0] = line_buffer_;
while (!line_buffer_.empty()) { while (!line_buffer_.empty()) {
size_t pos = line_buffer_.find(';'); size_t pos = line_buffer_.find(';');
std::string line1; std::string line1;

View File

@@ -63,6 +63,7 @@ class Shell : public std::enable_shared_from_this<Shell>, public uuid::log::Hand
public: public:
static constexpr size_t MAX_COMMAND_LINE_LENGTH = 80; /*!< Maximum length of a command line. @since 0.1.0 */ static constexpr size_t MAX_COMMAND_LINE_LENGTH = 80; /*!< Maximum length of a command line. @since 0.1.0 */
static constexpr size_t MAX_LOG_MESSAGES = 20; /*!< Maximum number of log messages to buffer before they are output. @since 0.1.0 */ static constexpr size_t MAX_LOG_MESSAGES = 20; /*!< Maximum number of log messages to buffer before they are output. @since 0.1.0 */
static constexpr uint8_t MAX_LINES = 5; /*!< Maximum lines in buffer */
/** /**
* Function to handle the response to a password entry prompt. * Function to handle the response to a password entry prompt.
@@ -904,7 +905,8 @@ class Shell : public std::enable_shared_from_this<Shell>, public uuid::log::Hand
std::list<QueuedLogMessage> log_messages_; /*!< Queued log messages, in the order they were received. @since 0.1.0 */ std::list<QueuedLogMessage> log_messages_; /*!< Queued log messages, in the order they were received. @since 0.1.0 */
size_t maximum_log_messages_ = MAX_LOG_MESSAGES; /*!< Maximum command line length in bytes. @since 0.6.0 */ size_t maximum_log_messages_ = MAX_LOG_MESSAGES; /*!< Maximum command line length in bytes. @since 0.6.0 */
std::string line_buffer_; /*!< Command line buffer. Limited to maximum_command_line_length() bytes. @since 0.1.0 */ std::string line_buffer_; /*!< Command line buffer. Limited to maximum_command_line_length() bytes. @since 0.1.0 */
std::string line_old_; /*!< old Command line buffer.*/ std::string line_old_[MAX_LINES]; /*!< old Command line buffer.*/
uint8_t line_no_ = 0;
size_t maximum_command_line_length_ = MAX_COMMAND_LINE_LENGTH; /*!< Maximum command line length in bytes. @since 0.6.0 */ size_t maximum_command_line_length_ = MAX_COMMAND_LINE_LENGTH; /*!< Maximum command line length in bytes. @since 0.6.0 */
unsigned char previous_ = 0; /*!< Previous character that was entered on the command line. Used to detect CRLF line endings. @since 0.1.0 */ unsigned char previous_ = 0; /*!< Previous character that was entered on the command line. Used to detect CRLF line endings. @since 0.1.0 */
uint8_t cursor_ = 0; /*!< cursor position from end of line */ uint8_t cursor_ = 0; /*!< cursor position from end of line */