1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/hello/hello.cpp
2011-08-21 20:31:17 +02:00

38 lines
1.3 KiB
C++

#include <stdio.h>
#include <libmaxsi/sortix-keyboard.h>
int main(int argc, char* argv[])
{
printf("\e[m\e[0J");
printf("Hello World: Welcome to Sortix! This is a program running in user-space.\n"
"This program is a probably the worst text editor ever made.\n"
"You are currently using the buggy USA keyboard layout.\n"
"This terminal is controlled using ANSI Escape Sequences:\n"
" - Type \e[32mESC 2 J\e[m to clear the screen\n"
);
bool lastwasesc = false;
while (true)
{
unsigned method = System::Keyboard::POLL;
uint32_t codepoint = System::Keyboard::ReceieveKeystroke(method);
if ( codepoint == 0 ) { continue; }
if ( codepoint & Maxsi::Keyboard::DEPRESSED ) { continue; }
if ( codepoint == Maxsi::Keyboard::UP ) { printf("\e[A"); continue; }
if ( codepoint == Maxsi::Keyboard::DOWN ) { printf("\e[B"); continue; }
if ( codepoint == Maxsi::Keyboard::RIGHT ) { printf("\e[C"); continue; }
if ( codepoint == Maxsi::Keyboard::LEFT ) { printf("\e[D"); continue; }
if ( codepoint == Maxsi::Keyboard::ESC ) { printf("\e["); lastwasesc = true; continue; }
if ( lastwasesc && codepoint == '[' ) { continue; }
if ( codepoint >= 0x80 ) { continue; }
char msg[2]; msg[0] = codepoint; msg[1] = '\0';
printf(msg);
lastwasesc = false;
}
return 0;
}