| 36 | std::string Term::cursor_left(std::size_t columns) { return "\033[" + std::to_string(columns) + 'D'; } |
| 37 | |
| 38 | std::pair<std::size_t, std::size_t> Term::cursor_position() { |
| 39 | // write cursor position report |
| 40 | std::cout << cursor_position_report() << std::flush; |
| 41 | // read input buffer |
| 42 | std::string buf; |
| 43 | char c{'\0'}; |
| 44 | do { |
| 45 | while (!Platform::read_raw(&c)) {} |
| 46 | buf.push_back(c); |
| 47 | } while (c != 'R'); |
| 48 | bool found{false}; |
| 49 | std::size_t row{0}; |
| 50 | std::size_t column{0}; |
| 51 | for (std::size_t i = 2; i < buf.size(); i++) { |
| 52 | if (buf[i] == ';') { |
| 53 | found = true; |
| 54 | } else if (!found && buf[i] >= '0' && buf[i] <= '9') { |
| 55 | row = row * 10 + (buf[i] - '0'); |
| 56 | } else if (found && buf[i] >= '0' && buf[i] <= '9') { |
| 57 | column = column * 10 + (buf[i] - '0'); |
| 58 | } |
| 59 | } |
| 60 | return {row, column}; |
| 61 | } |
| 62 | |
| 63 | std::string Term::cursor_position_report() { return "\x1b[6n"; } |
| 64 | |