mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
add cursor up for last command #587
This commit is contained in:
@@ -61,10 +61,12 @@ void Shell::start() {
|
|||||||
uuid::log::Logger::register_handler(this, uuid::log::Level::DEBUG); // added by proddy
|
uuid::log::Logger::register_handler(this, uuid::log::Level::DEBUG); // added by proddy
|
||||||
//uuid::log::Logger::register_handler(this, uuid::log::Level::INFO); // added by proddy
|
//uuid::log::Logger::register_handler(this, uuid::log::Level::INFO); // added by proddy
|
||||||
#else
|
#else
|
||||||
uuid::log::Logger::register_handler(this, uuid::log::Level::NOTICE);
|
uuid::log::Logger::register_handler(this, uuid::log::Level::INFO);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
line_buffer_.reserve(maximum_command_line_length_);
|
line_buffer_.reserve(maximum_command_line_length_);
|
||||||
|
oldline_.reserve(maximum_command_line_length_);
|
||||||
|
oldline_.clear();
|
||||||
display_banner();
|
display_banner();
|
||||||
display_prompt();
|
display_prompt();
|
||||||
shells_.insert(shared_from_this());
|
shells_.insert(shared_from_this());
|
||||||
@@ -175,6 +177,9 @@ void Shell::loop_normal() {
|
|||||||
case '\x0A':
|
case '\x0A':
|
||||||
// Line feed (^J)
|
// Line feed (^J)
|
||||||
if (previous_ != '\x0D') {
|
if (previous_ != '\x0D') {
|
||||||
|
if (!line_buffer_.empty()) {
|
||||||
|
oldline_ = line_buffer_;
|
||||||
|
}
|
||||||
process_command();
|
process_command();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -187,6 +192,9 @@ void Shell::loop_normal() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '\x0D':
|
case '\x0D':
|
||||||
|
if (!line_buffer_.empty()) {
|
||||||
|
oldline_ = line_buffer_;
|
||||||
|
}
|
||||||
// Carriage return (^M)
|
// Carriage return (^M)
|
||||||
process_command();
|
process_command();
|
||||||
break;
|
break;
|
||||||
@@ -211,6 +219,20 @@ void Shell::loop_normal() {
|
|||||||
line_buffer_.push_back(c);
|
line_buffer_.push_back(c);
|
||||||
write((uint8_t)c);
|
write((uint8_t)c);
|
||||||
}
|
}
|
||||||
|
// cursor up, get last command
|
||||||
|
if ((c == 'A') && (previous_ == '[')) {
|
||||||
|
erase_current_line();
|
||||||
|
prompt_displayed_ = false;
|
||||||
|
line_buffer_ = oldline_;
|
||||||
|
display_prompt();
|
||||||
|
}
|
||||||
|
// cursor back, forw or down: Delete line
|
||||||
|
if (((c == 'B') || (c == 'C') || (c == 'D')) && (previous_ == '[')) {
|
||||||
|
erase_current_line();
|
||||||
|
prompt_displayed_ = false;
|
||||||
|
line_buffer_.clear();
|
||||||
|
display_prompt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -905,6 +905,7 @@ class Shell : public std::enable_shared_from_this<Shell>, public uuid::log::Hand
|
|||||||
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 */
|
||||||
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 */
|
||||||
|
std::string oldline_; /*!< old Command line buffer.*/
|
||||||
Mode mode_ = Mode::NORMAL; /*!< Current execution mode. @since 0.1.0 */
|
Mode mode_ = Mode::NORMAL; /*!< Current execution mode. @since 0.1.0 */
|
||||||
std::unique_ptr<ModeData> mode_data_ = nullptr; /*!< Data associated with the current execution mode. @since 0.1.0 */
|
std::unique_ptr<ModeData> mode_data_ = nullptr; /*!< Data associated with the current execution mode. @since 0.1.0 */
|
||||||
bool stopped_ = false; /*!< Indicates that the shell has been stopped. @since 0.1.0 */
|
bool stopped_ = false; /*!< Indicates that the shell has been stopped. @since 0.1.0 */
|
||||||
|
|||||||
Reference in New Issue
Block a user