mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
F-Keys Linux+Putty, multible commands with ';'
This commit is contained in:
@@ -213,82 +213,70 @@ void Shell::loop_normal() {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
if (esc_) {
|
if (esc_) {
|
||||||
if ((c == '[') || (c == 'O')) {
|
if (c == 'A') { // cursor up
|
||||||
// start of sequence
|
|
||||||
} else if (c >= '0' && (c <= '9')) {
|
|
||||||
// numbers
|
|
||||||
esc_ = (esc_ & 0x7F) * 10 + c - '0';
|
|
||||||
} else if (c == 'A') {
|
|
||||||
// cursor up
|
|
||||||
line_buffer_ = line_old_;
|
line_buffer_ = line_old_;
|
||||||
cursor_ = 0;
|
cursor_ = 0;
|
||||||
esc_ = 0;
|
} else if (c == 'B') { // cursor down
|
||||||
} else if (c == 'B') {
|
|
||||||
// cursor down
|
|
||||||
line_buffer_.clear();
|
line_buffer_.clear();
|
||||||
cursor_ = 0;
|
cursor_ = 0;
|
||||||
esc_ = 0;
|
} else if (c == 'C') { // cursor right
|
||||||
} else if (c == 'C') {
|
|
||||||
// cursor right
|
|
||||||
if (cursor_) {
|
if (cursor_) {
|
||||||
cursor_--;
|
cursor_--;
|
||||||
}
|
}
|
||||||
esc_ = 0;
|
} else if (c == 'D') { // cursor left
|
||||||
} else if (c == 'D') {
|
|
||||||
// cursor left
|
|
||||||
if (cursor_ < line_buffer_.length()) {
|
if (cursor_ < line_buffer_.length()) {
|
||||||
cursor_++;
|
cursor_++;
|
||||||
}
|
}
|
||||||
esc_ = 0;
|
} else if (c == 'H') { // Home
|
||||||
} else if (c == 'H') {
|
|
||||||
// Home
|
|
||||||
cursor_ = line_buffer_.length();
|
cursor_ = line_buffer_.length();
|
||||||
esc_ = 0;
|
} else if (c == 'F') { // End
|
||||||
} else if (c == 'F') {
|
|
||||||
// End
|
|
||||||
cursor_ = 0;
|
cursor_ = 0;
|
||||||
esc_ = 0;
|
} else if (c >= 'P' && c <= 'Z') { // F1 - F11, Linux, VT100
|
||||||
} else if (c == 'P') {
|
// set esc-number like ESCn~
|
||||||
// F1
|
esc_ = 11 + c - 'P';
|
||||||
set_command_str(F("help"));
|
}
|
||||||
esc_ = 0;
|
if (c == '~' || (c >= 'P' && c <= 'Z')) { // function keys with number ESCn~
|
||||||
} else if (c == 'Q') {
|
if ((esc_ == 3) && cursor_) { // del
|
||||||
// F2
|
|
||||||
set_command_str(F("show"));
|
|
||||||
esc_ = 0;
|
|
||||||
} else if (c == '~') {
|
|
||||||
// function keys with number
|
|
||||||
if ((esc_ == 3) && cursor_) {
|
|
||||||
// del
|
|
||||||
cursor_--;
|
cursor_--;
|
||||||
line_buffer_.erase(line_buffer_.length() - cursor_ - 1, 1);
|
line_buffer_.erase(line_buffer_.length() - cursor_ - 1, 1);
|
||||||
} else if (esc_ == 4) {
|
} else if (esc_ == 4) { // end
|
||||||
// end
|
|
||||||
cursor_ = 0;
|
cursor_ = 0;
|
||||||
} else if (esc_ == 1) {
|
} else if (esc_ == 1) { // pos1
|
||||||
// pos1
|
|
||||||
cursor_ = line_buffer_.length();
|
cursor_ = line_buffer_.length();
|
||||||
} else if (esc_ == 11) {
|
} else if (esc_ == 11) { // F1
|
||||||
// F1 and F10
|
|
||||||
set_command_str(F("help"));
|
set_command_str(F("help"));
|
||||||
} else if (esc_ == 12) {
|
} else if (esc_ == 12) { // F2
|
||||||
// F2
|
|
||||||
set_command_str(F("show"));
|
set_command_str(F("show"));
|
||||||
} else if (esc_ == 20) {
|
} else if (esc_ == 13) { // F3
|
||||||
// F9
|
set_command_str(F("log notice"));
|
||||||
|
} else if (esc_ == 14) { // F4
|
||||||
|
set_command_str(F("log info"));
|
||||||
|
} else if (esc_ == 15) { // F5
|
||||||
|
set_command_str(F("log debug"));
|
||||||
|
} else if (esc_ == 17) { // F6
|
||||||
|
set_command_str(F("watch off"));
|
||||||
|
} else if (esc_ == 18) { // F7
|
||||||
|
set_command_str(F("watch on"));
|
||||||
|
} else if (esc_ == 19) { // F8
|
||||||
|
set_command_str(F("watch raw"));
|
||||||
|
} else if (esc_ == 20) { // F9
|
||||||
|
set_command_str(F("call system info"));
|
||||||
|
} else if (esc_ == 21) { // F10
|
||||||
|
set_command_str(F("call system report"));
|
||||||
|
} else if (esc_ == 23) { // F11
|
||||||
line_buffer_ = read_flash_string(F("send telegram \"0B \""));
|
line_buffer_ = read_flash_string(F("send telegram \"0B \""));
|
||||||
cursor_ = 1;
|
cursor_ = 1;
|
||||||
} else if (esc_ == 15) {
|
} else if (esc_ == 24) { // F12
|
||||||
// F5
|
set_command_str(F("log debug; watch raw"));
|
||||||
set_command_str(F("call system report"));
|
|
||||||
}
|
}
|
||||||
esc_ = 0;
|
esc_ = 0;
|
||||||
} else {
|
} else if (c >= '0' && (c <= '9')) { // numbers
|
||||||
// all other chars end sequence
|
esc_ = (esc_ & 0x7F) * 10 + c - '0';
|
||||||
|
} else if ((c != '[') && (c != 'O')) { // all other chars except start of sequence
|
||||||
esc_ = 0;
|
esc_ = 0;
|
||||||
}
|
}
|
||||||
|
// process normal ascii text
|
||||||
} else if (c >= '\x20' && c <= '\x7E') {
|
} else if (c >= '\x20' && c <= '\x7E') {
|
||||||
// ASCII text
|
|
||||||
if (line_buffer_.length() < maximum_command_line_length_) {
|
if (line_buffer_.length() < maximum_command_line_length_) {
|
||||||
line_buffer_.insert(line_buffer_.length() - cursor_, 1, c);
|
line_buffer_.insert(line_buffer_.length() - cursor_, 1, c);
|
||||||
}
|
}
|
||||||
@@ -506,31 +494,41 @@ void Shell::maximum_command_line_length(size_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Shell::process_command() {
|
void Shell::process_command() {
|
||||||
CommandLine command_line{line_buffer_};
|
if (line_buffer_.empty()) {
|
||||||
|
return;
|
||||||
println();
|
}
|
||||||
prompt_displayed_ = false;
|
line_old_ = line_buffer_;
|
||||||
|
while (!line_buffer_.empty()) {
|
||||||
if (!command_line->empty()) {
|
size_t pos = line_buffer_.find(';');
|
||||||
if (commands_) {
|
std::string line1;
|
||||||
auto execution = commands_->execute_command(*this, std::move(command_line));
|
if (pos < line_buffer_.length()) {
|
||||||
|
line1 = line_buffer_.substr(0, pos);
|
||||||
if (execution.error != nullptr) {
|
line_buffer_.erase(0, pos + 1);
|
||||||
println(execution.error);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
println(F("No commands configured"));
|
line1 = line_buffer_;
|
||||||
|
line_buffer_.clear();
|
||||||
|
cursor_ = 0;
|
||||||
}
|
}
|
||||||
line_old_ = line_buffer_;
|
CommandLine command_line{line1};
|
||||||
}
|
|
||||||
|
|
||||||
cursor_ = 0;
|
println();
|
||||||
line_buffer_.clear();
|
prompt_displayed_ = false;
|
||||||
|
|
||||||
if (running()) {
|
if (!command_line->empty()) {
|
||||||
display_prompt();
|
if (commands_) {
|
||||||
|
auto execution = commands_->execute_command(*this, std::move(command_line));
|
||||||
|
if (execution.error != nullptr) {
|
||||||
|
println(execution.error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println(F("No commands configured"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
::yield();
|
||||||
}
|
}
|
||||||
::yield();
|
// if (running()) {
|
||||||
|
// display_prompt();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shell::process_completion() {
|
void Shell::process_completion() {
|
||||||
@@ -538,11 +536,9 @@ void Shell::process_completion() {
|
|||||||
|
|
||||||
if (!command_line->empty() && commands_) {
|
if (!command_line->empty() && commands_) {
|
||||||
auto completion = commands_->complete_command(*this, command_line);
|
auto completion = commands_->complete_command(*this, command_line);
|
||||||
bool redisplay = false;
|
|
||||||
|
|
||||||
if (!completion.help.empty()) {
|
if (!completion.help.empty()) {
|
||||||
println();
|
println();
|
||||||
redisplay = true;
|
|
||||||
|
|
||||||
for (auto & help : completion.help) {
|
for (auto & help : completion.help) {
|
||||||
std::string help_line = help.to_string(maximum_command_line_length_);
|
std::string help_line = help.to_string(maximum_command_line_length_);
|
||||||
@@ -552,18 +548,8 @@ void Shell::process_completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!completion.replacement->empty()) {
|
if (!completion.replacement->empty()) {
|
||||||
if (!redisplay) {
|
|
||||||
erase_current_line();
|
|
||||||
prompt_displayed_ = false;
|
|
||||||
redisplay = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
line_buffer_ = completion.replacement.to_string(maximum_command_line_length_);
|
line_buffer_ = completion.replacement.to_string(maximum_command_line_length_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redisplay) {
|
|
||||||
display_prompt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
::yield();
|
::yield();
|
||||||
@@ -587,15 +573,10 @@ void Shell::process_password(bool completed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Shell::invoke_command(const std::string & line) {
|
void Shell::invoke_command(const std::string & line) {
|
||||||
if (!line_buffer_.empty()) {
|
erase_current_line();
|
||||||
println();
|
prompt_displayed_ = false;
|
||||||
prompt_displayed_ = false;
|
|
||||||
}
|
|
||||||
if (!prompt_displayed_) {
|
|
||||||
display_prompt();
|
|
||||||
}
|
|
||||||
line_buffer_ = line;
|
line_buffer_ = line;
|
||||||
print(line_buffer_);
|
display_prompt();
|
||||||
process_command();
|
process_command();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user