| 494 | |
| 495 | extern "C" |
| 496 | int main(int argc, char** argv){ |
| 497 | window = new Lemon::GUI::Window("Terminal", {720, 480}); |
| 498 | |
| 499 | terminalFont = Lemon::Graphics::LoadFont("/initrd/sourcecodepro.ttf", "termmonospace"); |
| 500 | if(!terminalFont){ |
| 501 | terminalFont = Lemon::Graphics::GetFont("default"); |
| 502 | } |
| 503 | |
| 504 | rowCount = 480 / terminalFont->lineHeight - 1; |
| 505 | columnCount = 720 / 8; |
| 506 | |
| 507 | curPos = {0, 0}; |
| 508 | |
| 509 | for(int i = 0; i < rowCount; i++){ |
| 510 | buffer.push_back(std::vector<TerminalChar>()); |
| 511 | } |
| 512 | |
| 513 | |
| 514 | int masterPTYFd; |
| 515 | syscall(SYS_GRANT_PTY, (uintptr_t)&masterPTYFd, 0, 0, 0, 0); |
| 516 | |
| 517 | setenv("TERM", "xterm-256color", 1); // the Lemon OS terminal is (fairly) xterm compatible (256 colour, etc.) |
| 518 | |
| 519 | char* const _argv[] = {const_cast<char*>("/system/bin/lsh.lef")}; |
| 520 | lemon_spawn(_argv[0], 1, _argv, 1); |
| 521 | |
| 522 | window->OnPaint = OnPaint; |
| 523 | |
| 524 | char* _buf = (char*)malloc(512); |
| 525 | |
| 526 | winsize wSz = { |
| 527 | .ws_row = static_cast<unsigned short>(rowCount), |
| 528 | .ws_col = static_cast<unsigned short>(columnCount), |
| 529 | .ws_xpixel = static_cast<unsigned short>(window->GetSize().x), |
| 530 | .ws_ypixel = static_cast<unsigned short>(window->GetSize().y), |
| 531 | }; |
| 532 | |
| 533 | ioctl(masterPTYFd, TIOCSWINSZ, &wSz); |
| 534 | |
| 535 | std::vector<pollfd> fds; |
| 536 | fds.push_back({.fd = masterPTYFd, .events = POLLIN, .revents = 0}); |
| 537 | |
| 538 | //auto& wMHandler = window->GetHandler(); |
| 539 | //fds.insert(fds.begin(), wMHandler.GetFileDescriptors().begin(), wMHandler.GetFileDescriptors().end()); |
| 540 | for(;;){ |
| 541 | Lemon::LemonEvent ev; |
| 542 | while(window->PollEvent(ev)){ |
| 543 | if(ev.event == Lemon::EventKeyPressed){ |
| 544 | if(ev.key == KEY_ARROW_UP){ |
| 545 | const char* esc = "\e[A"; |
| 546 | write(masterPTYFd, esc, strlen(esc)); |
| 547 | } else if(ev.key == KEY_ARROW_DOWN){ |
| 548 | const char* esc = "\e[B"; |
| 549 | write(masterPTYFd, esc, strlen(esc)); |
| 550 | } else if(ev.key == KEY_ARROW_RIGHT){ |
| 551 | const char* esc = "\e[C"; |
| 552 | write(masterPTYFd, esc, strlen(esc)); |
| 553 | } else if(ev.key == KEY_ARROW_LEFT){ |