diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
@@ -5,7 +5,7 @@ * Created on May 1, 2018, 6:18 PM */ -//#define DEBUG +// #define DEBUG // basic devices #include "hal/confbits.hpp" @@ -46,15 +46,6 @@ std::vector<std::string> split(const std::string& str, const char sep) return v; } -void strip(std::string &str) -{ - const std::string strip_chars = "\n\r\b\t\f"; - - for (const char &ch : strip_chars) { - str.erase(std::remove_if(str.begin(), str.end(), [ch](const char &c){ return c == ch; }), str.end()); - } -} - int main(int argc, char** argv) { osc::initialize(); @@ -86,22 +77,31 @@ int main(int argc, char** argv) std::string input = ""; // write prompt - uart::write<1>("\n\r> "); + uart::write<1>("> "); do { - input += uart::read_wait<1>(); + input += uart::read_wait<1>(); + + // DEL character + if (input.back() == '\x7f') { + input.pop_back(); + input.pop_back(); + uart::write<1>("\b \b"); + } } while (input.back() != '\r' && input.back() != '\n'); - + + uart::write<1>("\n\r"); + #ifdef DEBUG uart::write<1>("input: "); uart::print<1>(input); #endif - // remove weird symbols - strip(input); + // remove non printable symbols + input.erase(std::remove_if(input.begin(), input.end(), std::iscntrl), input.end()); // set to lowercase - std::transform(input.begin(), input.end(), input.begin(), ::tolower); + std::transform(input.begin(), input.end(), input.begin(), std::tolower); // split const std::vector<std::string> command = split(input, ' '); |