Ported the user-space programs to use stdin for keyboard access.
The old keyboard API is hereby deprecated and unused.
This commit is contained in:
parent
fa9c7007b4
commit
c4264d9c2a
|
@ -1,10 +1,7 @@
|
||||||
#include <libmaxsi/platform.h>
|
#include <libmaxsi/platform.h>
|
||||||
#include <libmaxsi/io.h>
|
|
||||||
#include <libmaxsi/thread.h>
|
|
||||||
#include <libmaxsi/keyboard.h>
|
|
||||||
#include <libmaxsi/string.h>
|
|
||||||
#include <libmaxsi/sortix-vga.h>
|
#include <libmaxsi/sortix-vga.h>
|
||||||
#include <libmaxsi/sortix-keyboard.h>
|
#include <sys/keycodes.h>
|
||||||
|
#include <sys/termmode.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -13,9 +10,6 @@
|
||||||
#include <error.h>
|
#include <error.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
using namespace Maxsi;
|
|
||||||
using namespace Maxsi::Keyboard;
|
|
||||||
|
|
||||||
const int width = 80;
|
const int width = 80;
|
||||||
const int height = 25;
|
const int height = 25;
|
||||||
|
|
||||||
|
@ -118,24 +112,28 @@ void Render()
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
// Read the keyboard input from the user.
|
// Read the keyboard input from the user.
|
||||||
unsigned method = System::Keyboard::POLL;
|
unsigned termmode = TERMMODE_KBKEY
|
||||||
uint32_t codepoint;
|
| TERMMODE_UNICODE
|
||||||
while ( (codepoint = System::Keyboard::ReceiveKeystroke(method) ) != 0 )
|
| TERMMODE_SIGNAL
|
||||||
|
| TERMMODE_NONBLOCK;
|
||||||
|
if ( settermmode(0, termmode) ) { error(1, errno, "settermmode"); }
|
||||||
|
while ( true )
|
||||||
{
|
{
|
||||||
bool keyup = codepoint & DEPRESSED;
|
uint32_t codepoint;
|
||||||
if ( keyup ) { continue; }
|
ssize_t numbytes = read(0, &codepoint, sizeof(codepoint));
|
||||||
codepoint &= ~DEPRESSED;
|
if ( !numbytes ) { break; }
|
||||||
|
if ( numbytes < 0 ) { break; }
|
||||||
if ( codepoint == 'r' || codepoint == 'R' ) { running = !running; }
|
int kbkey = KBKEY_DECODE(codepoint);
|
||||||
|
if ( kbkey == KBKEY_R ) { running = !running; }
|
||||||
if ( !running )
|
if ( running ) { continue; }
|
||||||
|
if ( kbkey == KBKEY_C ) { Clear(); }
|
||||||
|
if ( kbkey == KBKEY_W ) { if ( posy > 1 ) { posy--; } }
|
||||||
|
if ( kbkey == KBKEY_A ) { if ( posx > 1 ) { posx--; } }
|
||||||
|
if ( kbkey == KBKEY_S ) { if ( posy < height ) { posy++; } }
|
||||||
|
if ( kbkey == KBKEY_D ) { if ( posx < width ) { posx++; } }
|
||||||
|
if ( kbkey == KBKEY_SPACE )
|
||||||
{
|
{
|
||||||
if ( codepoint == 'c' || codepoint == 'C' ) { Clear(); }
|
lastframe[posy * rowstride + posx] = 1 - lastframe[posy * rowstride + posx];
|
||||||
if ( codepoint == 'w' || codepoint == 'W' ) { if ( posy > 1 ) { posy--; } }
|
|
||||||
if ( codepoint == 's' || codepoint == 'S' ) { if ( posy < height ) { posy++; } }
|
|
||||||
if ( codepoint == 'a' || codepoint == 'A' ) { if ( posx > 1 ) { posx--; } }
|
|
||||||
if ( codepoint == 'd' || codepoint == 'D' ) { if ( posx < width ) { posx++; } }
|
|
||||||
if ( codepoint == ' ' ) { lastframe[posy * rowstride + posx] = 1 - lastframe[posy * rowstride + posx]; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,11 +159,11 @@ int main(int argc, char* argv[])
|
||||||
int sleepms = 50;
|
int sleepms = 50;
|
||||||
for ( int i = 1; i < argc; i++ )
|
for ( int i = 1; i < argc; i++ )
|
||||||
{
|
{
|
||||||
if ( String::Compare(argv[i], "--help") == 0 ) { return usage(argc, argv); }
|
if ( strcmp(argv[i], "--help") == 0 ) { return usage(argc, argv); }
|
||||||
if ( String::Compare(argv[i], "--usage") == 0 ) { return usage(argc, argv); }
|
if ( strcmp(argv[i], "--usage") == 0 ) { return usage(argc, argv); }
|
||||||
if ( String::Compare(argv[i], "--speed") == 0 && 1 < argc-i )
|
if ( strcmp(argv[i], "--speed") == 0 && 1 < argc-i )
|
||||||
{
|
{
|
||||||
sleepms = String::ToInt(argv[++i]);
|
sleepms = atoi(argv[++i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +173,7 @@ int main(int argc, char* argv[])
|
||||||
// Update the game every 50th milisecond.
|
// Update the game every 50th milisecond.
|
||||||
while ( true )
|
while ( true )
|
||||||
{
|
{
|
||||||
Thread::USleep(sleepms * 1000);
|
usleep(sleepms * 1000);
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include <libmaxsi/platform.h>
|
#include <libmaxsi/platform.h>
|
||||||
#include <libmaxsi/io.h>
|
#include <libmaxsi/io.h>
|
||||||
#include <libmaxsi/thread.h>
|
#include <libmaxsi/thread.h>
|
||||||
#include <libmaxsi/keyboard.h>
|
|
||||||
#include <libmaxsi/string.h>
|
#include <libmaxsi/string.h>
|
||||||
#include <libmaxsi/sortix-vga.h>
|
#include <libmaxsi/sortix-vga.h>
|
||||||
#include <libmaxsi/sortix-keyboard.h>
|
|
||||||
#include <libmaxsi/sortix-sound.h>
|
#include <libmaxsi/sortix-sound.h>
|
||||||
|
#include <sys/keycodes.h>
|
||||||
|
#include <sys/termmode.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -15,7 +15,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
using namespace Maxsi;
|
using namespace Maxsi;
|
||||||
using namespace Maxsi::Keyboard;
|
|
||||||
|
|
||||||
int Init();
|
int Init();
|
||||||
void Reset();
|
void Reset();
|
||||||
|
@ -196,18 +195,24 @@ void Update()
|
||||||
|
|
||||||
void ReadInput()
|
void ReadInput()
|
||||||
{
|
{
|
||||||
unsigned method = System::Keyboard::POLL;
|
unsigned termmode = TERMMODE_KBKEY
|
||||||
uint32_t codepoint;
|
| TERMMODE_UNICODE
|
||||||
while ( (codepoint = System::Keyboard::ReceiveKeystroke(method) ) != 0 )
|
| TERMMODE_SIGNAL
|
||||||
|
| TERMMODE_NONBLOCK;
|
||||||
|
if ( settermmode(0, termmode) ) { error(1, errno, "settermmode"); }
|
||||||
|
while ( true )
|
||||||
{
|
{
|
||||||
bool keyup = codepoint & DEPRESSED;
|
uint32_t codepoint;
|
||||||
codepoint &= ~DEPRESSED;
|
ssize_t numbytes = read(0, &codepoint, sizeof(codepoint));
|
||||||
|
if ( !numbytes ) { return; }
|
||||||
if ( codepoint == '\n' && keyup ) { Reset(); }
|
if ( numbytes < 0 ) { return; }
|
||||||
if ( codepoint == 'w' || codepoint == 'W' ) { p1vup = !keyup; }
|
int kbkey = KBKEY_DECODE(codepoint);
|
||||||
if ( codepoint == 's' || codepoint == 'S' ) { p1vdown = !keyup; }
|
int abskbkey = (kbkey < 0) ? -kbkey : kbkey;
|
||||||
if ( codepoint == UP ) { p2vup = !keyup; }
|
if ( kbkey == KBKEY_ENTER ) { Reset(); }
|
||||||
if ( codepoint == DOWN ) { p2vdown = !keyup; }
|
if ( abskbkey == KBKEY_W ) { p1vup = (0 < kbkey); }
|
||||||
|
if ( abskbkey == KBKEY_S ) { p1vdown = (0 < kbkey); }
|
||||||
|
if ( abskbkey == KBKEY_UP ) { p2vup = (0 < kbkey); }
|
||||||
|
if ( abskbkey == KBKEY_DOWN ) { p2vdown = (0 < kbkey); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
#include <libmaxsi/platform.h>
|
#include <libmaxsi/platform.h>
|
||||||
#include <libmaxsi/io.h>
|
|
||||||
#include <libmaxsi/thread.h>
|
|
||||||
#include <libmaxsi/keyboard.h>
|
|
||||||
#include <libmaxsi/sortix-vga.h>
|
#include <libmaxsi/sortix-vga.h>
|
||||||
#include <libmaxsi/sortix-keyboard.h>
|
#include <sys/keycodes.h>
|
||||||
|
#include <sys/termmode.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -12,9 +10,6 @@
|
||||||
#include <error.h>
|
#include <error.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
using namespace Maxsi;
|
|
||||||
using namespace Maxsi::Keyboard;
|
|
||||||
|
|
||||||
const int width = 80;
|
const int width = 80;
|
||||||
const int height = 25;
|
const int height = 25;
|
||||||
|
|
||||||
|
@ -99,21 +94,25 @@ void Update()
|
||||||
int newvely = vely;
|
int newvely = vely;
|
||||||
|
|
||||||
// Read the keyboard input from the user.
|
// Read the keyboard input from the user.
|
||||||
unsigned method = System::Keyboard::POLL;
|
unsigned termmode = TERMMODE_KBKEY
|
||||||
uint32_t codepoint;
|
| TERMMODE_UNICODE
|
||||||
while ( (codepoint = System::Keyboard::ReceiveKeystroke(method) ) != 0 )
|
| TERMMODE_SIGNAL
|
||||||
|
| TERMMODE_NONBLOCK;
|
||||||
|
if ( settermmode(0, termmode) ) { error(1, errno, "settermmode"); }
|
||||||
|
while ( true )
|
||||||
{
|
{
|
||||||
if ( tabhack && codepoint == '\t' ) { tabhacking = true; }
|
uint32_t codepoint;
|
||||||
if ( tabhack && codepoint == ('\t' | DEPRESSED ) ) { tabhacking = false; }
|
ssize_t numbytes = read(0, &codepoint, sizeof(codepoint));
|
||||||
bool keyup = codepoint & DEPRESSED;
|
if ( !numbytes ) { break; }
|
||||||
if ( keyup ) { continue; }
|
if ( numbytes < 0 ) { break; }
|
||||||
codepoint &= ~DEPRESSED;
|
int kbkey = KBKEY_DECODE(codepoint);
|
||||||
|
int abskbkey = (kbkey < 0) ? -kbkey : kbkey;
|
||||||
if ( codepoint == '\n' ) { Reset(); return; }
|
if ( tabhack && abskbkey == KBKEY_TAB ) { tabhacking = (0 < kbkey); }
|
||||||
if ( codepoint == 'w' || codepoint == 'W' ) { newvelx = 0; newvely = -1; }
|
if ( kbkey == KBKEY_ENTER ) { Reset(); return; }
|
||||||
if ( codepoint == 'a' || codepoint == 'A' ) { newvelx = -1; newvely = 0; }
|
if ( kbkey == KBKEY_W ) { newvelx = 0; newvely = -1; }
|
||||||
if ( codepoint == 's' || codepoint == 'S' ) { newvelx = 0; newvely = 1; }
|
if ( kbkey == KBKEY_A ) { newvelx = -1; newvely = 0; }
|
||||||
if ( codepoint == 'd' || codepoint == 'D' ) { newvelx = 1; newvely = 0; }
|
if ( kbkey == KBKEY_S ) { newvelx = 0; newvely = 1; }
|
||||||
|
if ( kbkey == KBKEY_D ) { newvelx = 1; newvely = 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( tabhack && tabhacking )
|
if ( tabhack && tabhacking )
|
||||||
|
@ -196,7 +195,7 @@ int main(int argc, char* argv[])
|
||||||
// Update the game every once in a while.
|
// Update the game every once in a while.
|
||||||
while ( true )
|
while ( true )
|
||||||
{
|
{
|
||||||
Thread::USleep(speed * 1000);
|
usleep(speed * 1000);
|
||||||
Update();
|
Update();
|
||||||
FlushVGA();
|
FlushVGA();
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,6 +370,8 @@ namespace Sortix
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern DevTerminal* tty;
|
||||||
|
|
||||||
Device* DevDevFS::Open(const char* path, int flags, mode_t mode)
|
Device* DevDevFS::Open(const char* path, int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
if ( (flags & O_LOWERFLAGS) == O_SEARCH )
|
if ( (flags & O_LOWERFLAGS) == O_SEARCH )
|
||||||
|
@ -380,7 +382,7 @@ namespace Sortix
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( String::Compare(path, "/null") == 0 ) { return new DevNull; }
|
if ( String::Compare(path, "/null") == 0 ) { return new DevNull; }
|
||||||
if ( String::Compare(path, "/tty") == 0 ) { return new DevLogTTY; }
|
if ( String::Compare(path, "/tty") == 0 ) { tty->Refer(); return tty; }
|
||||||
if ( String::Compare(path, "/vga") == 0 ) { return new DevVGA; }
|
if ( String::Compare(path, "/vga") == 0 ) { return new DevVGA; }
|
||||||
if ( path[0] == '/' && path[1] == 'a' && path[2] == 't' && path[3] == 'a' && path[4] && !path[5] )
|
if ( path[0] == '/' && path[1] == 'a' && path[2] == 't' && path[3] == 'a' && path[4] && !path[5] )
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,15 +28,16 @@
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
#include "kb/ps2.h"
|
#include "kb/ps2.h"
|
||||||
#include "kb/layout/us.h"
|
#include "kb/layout/us.h"
|
||||||
#include "kbapiadapter.h"
|
#include "logterminal.h"
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix
|
||||||
{
|
{
|
||||||
KBAPIAdapter* tty;
|
DevTerminal* tty;
|
||||||
|
|
||||||
uint32_t SysReceiveKeystroke()
|
uint32_t SysReceiveKeystroke()
|
||||||
{
|
{
|
||||||
return tty->DequeueKeystroke();
|
// TODO: Deprecated, please remove this.
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Keyboard::Init()
|
void Keyboard::Init()
|
||||||
|
@ -47,7 +48,7 @@ namespace Sortix
|
||||||
KeyboardLayout* kblayout = new KBLayoutUS;
|
KeyboardLayout* kblayout = new KBLayoutUS;
|
||||||
if ( !kblayout ) { Panic("Could not allocate keyboard layout driver"); }
|
if ( !kblayout ) { Panic("Could not allocate keyboard layout driver"); }
|
||||||
|
|
||||||
tty = new KBAPIAdapter(keyboard, kblayout);
|
tty = new LogTerminal(keyboard, kblayout);
|
||||||
if ( !tty ) { Panic("Could not allocate a simple terminal"); }
|
if ( !tty ) { Panic("Could not allocate a simple terminal"); }
|
||||||
|
|
||||||
Syscall::Register(SYSCALL_RECEIVE_KEYSTROKE, (void*) SysReceiveKeystroke);
|
Syscall::Register(SYSCALL_RECEIVE_KEYSTROKE, (void*) SysReceiveKeystroke);
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
#include <sys/keycodes.h>
|
||||||
|
#include <sys/termmode.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <error.h>
|
#include <error.h>
|
||||||
#include <libmaxsi/sortix-keyboard.h>
|
|
||||||
|
|
||||||
int cat(int argc, char* argv[])
|
int cat(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
@ -55,19 +56,27 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
bool lastwasesc = false;
|
bool lastwasesc = false;
|
||||||
|
|
||||||
while (true)
|
// TODO: This is just compatibility with how cat worked in early versions of
|
||||||
|
// Sortix. Ideally, this should be removed and just cat the raw stdin.
|
||||||
|
// Read the keyboard input from the user.
|
||||||
|
unsigned termmode = TERMMODE_KBKEY | TERMMODE_UNICODE | TERMMODE_SIGNAL;
|
||||||
|
if ( settermmode(0, termmode) ) { error(1, errno, "settermmode"); }
|
||||||
|
while ( true )
|
||||||
{
|
{
|
||||||
unsigned method = System::Keyboard::POLL;
|
uint32_t codepoint;
|
||||||
uint32_t codepoint = System::Keyboard::ReceiveKeystroke(method);
|
ssize_t numbytes = read(0, &codepoint, sizeof(codepoint));
|
||||||
|
if ( !numbytes ) { break; }
|
||||||
if ( codepoint == 0 ) { continue; }
|
if ( numbytes < 0 ) { break; }
|
||||||
if ( codepoint & Maxsi::Keyboard::DEPRESSED ) { continue; }
|
int kbkey = KBKEY_DECODE(codepoint);
|
||||||
if ( codepoint == Maxsi::Keyboard::UP ) { printf("\e[A"); fflush(stdout); continue; }
|
if ( kbkey < 0 ) { continue; }
|
||||||
if ( codepoint == Maxsi::Keyboard::DOWN ) { printf("\e[B"); fflush(stdout); continue; }
|
if ( kbkey == KBKEY_UP ) { printf("\e[A"); fflush(stdout); continue; }
|
||||||
if ( codepoint == Maxsi::Keyboard::RIGHT ) { printf("\e[C"); fflush(stdout); continue; }
|
if ( kbkey == KBKEY_DOWN ) { printf("\e[B"); fflush(stdout); continue; }
|
||||||
if ( codepoint == Maxsi::Keyboard::LEFT ) { printf("\e[D"); fflush(stdout); continue; }
|
if ( kbkey == KBKEY_RIGHT ) { printf("\e[C"); fflush(stdout); continue; }
|
||||||
if ( codepoint == Maxsi::Keyboard::ESC ) { printf("\e["); fflush(stdout); lastwasesc = true; continue; }
|
if ( kbkey == KBKEY_LEFT ) { printf("\e[D"); fflush(stdout); continue; }
|
||||||
|
if ( kbkey == KBKEY_ESC ) { printf("\e["); fflush(stdout); lastwasesc = true; continue; }
|
||||||
|
if ( kbkey ) { continue; }
|
||||||
if ( lastwasesc && codepoint == '[' ) { continue; }
|
if ( lastwasesc && codepoint == '[' ) { continue; }
|
||||||
|
|
||||||
if ( codepoint >= 0x80 ) { continue; }
|
if ( codepoint >= 0x80 ) { continue; }
|
||||||
|
|
||||||
char msg[2]; msg[0] = codepoint; msg[1] = '\0';
|
char msg[2]; msg[0] = codepoint; msg[1] = '\0';
|
||||||
|
|
288
utils/editor.cpp
288
utils/editor.cpp
|
@ -1,17 +1,18 @@
|
||||||
|
#include <sys/keycodes.h>
|
||||||
|
#include <sys/termmode.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <error.h>
|
#include <error.h>
|
||||||
#include <libmaxsi/platform.h>
|
|
||||||
#include <libmaxsi/sortix-keyboard.h>
|
|
||||||
|
|
||||||
const int MODE_QUIT = 0;
|
const int MODE_QUIT = 1;
|
||||||
const int MODE_TEXT = 1;
|
const int MODE_TEXT = 2;
|
||||||
const int MODE_CONFIRM_QUIT = 2;
|
const int MODE_CONFIRM_QUIT = 3;
|
||||||
const int MODE_SAVE = 3;
|
const int MODE_SAVE = 4;
|
||||||
const int MODE_LOAD = 4;
|
const int MODE_LOAD = 5;
|
||||||
|
|
||||||
const unsigned WIDTH = 80;
|
const unsigned WIDTH = 80;
|
||||||
const unsigned HEIGHT = 24;
|
const unsigned HEIGHT = 24;
|
||||||
|
@ -23,7 +24,7 @@ unsigned numlines = 1;
|
||||||
|
|
||||||
char filename[256];
|
char filename[256];
|
||||||
|
|
||||||
bool bufferchanged;
|
bool bufferchanged = false;
|
||||||
|
|
||||||
void clearbuffers()
|
void clearbuffers()
|
||||||
{
|
{
|
||||||
|
@ -35,14 +36,56 @@ void clearbuffers()
|
||||||
bufferchanged = true;
|
bufferchanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace Maxsi;
|
|
||||||
|
|
||||||
void cursorto(unsigned x, unsigned y)
|
void cursorto(unsigned x, unsigned y)
|
||||||
{
|
{
|
||||||
printf("\e[%u;%uH", y+1+1, x+1);
|
printf("\e[%u;%uH", y+1+1, x+1);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* readline(int fd)
|
||||||
|
{
|
||||||
|
unsigned oldtermmode;
|
||||||
|
if ( gettermmode(fd, &oldtermmode) ) { return NULL; }
|
||||||
|
|
||||||
|
unsigned termmode = TERMMODE_UNICODE
|
||||||
|
| TERMMODE_SIGNAL
|
||||||
|
| TERMMODE_UTF8
|
||||||
|
| TERMMODE_LINEBUFFER
|
||||||
|
| TERMMODE_ECHO;
|
||||||
|
if ( settermmode(fd, termmode) ) { return NULL; }
|
||||||
|
|
||||||
|
size_t lineused = 0;
|
||||||
|
size_t linelength = 32UL;
|
||||||
|
char* line = new char[linelength + 1];
|
||||||
|
line[0] = '\0';
|
||||||
|
|
||||||
|
while ( true )
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
ssize_t numbytes = read(fd, &c, sizeof(c));
|
||||||
|
if ( numbytes < 0 ) { delete[] line; line = NULL; break; }
|
||||||
|
if ( !numbytes ) { break; }
|
||||||
|
if ( c == '\n' ) { break; }
|
||||||
|
|
||||||
|
if ( lineused == linelength )
|
||||||
|
{
|
||||||
|
size_t newlinelength = 2 * linelength;
|
||||||
|
char* newline = new char[newlinelength];
|
||||||
|
if ( !newline ) { delete[] line; line = NULL; break; }
|
||||||
|
memcpy(newline, line, lineused * sizeof(*line));
|
||||||
|
delete[] line;
|
||||||
|
line = newline;
|
||||||
|
linelength = newlinelength;
|
||||||
|
}
|
||||||
|
|
||||||
|
line[lineused++] = c;
|
||||||
|
line[lineused] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( settermmode(fd, oldtermmode) ) { delete[] line; line = NULL; }
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
void drawtextmode()
|
void drawtextmode()
|
||||||
{
|
{
|
||||||
const char* printfilename = ( strlen(filename) > 0 ) ? filename : "New Buffer";
|
const char* printfilename = ( strlen(filename) > 0 ) ? filename : "New Buffer";
|
||||||
|
@ -64,6 +107,7 @@ unsigned textmode()
|
||||||
drawtextmode();
|
drawtextmode();
|
||||||
|
|
||||||
bool ctrl = false;
|
bool ctrl = false;
|
||||||
|
unsigned dectrlmode = 0;
|
||||||
|
|
||||||
int oldcursorx = -1;
|
int oldcursorx = -1;
|
||||||
int oldcursory = -1;
|
int oldcursory = -1;
|
||||||
|
@ -76,46 +120,63 @@ unsigned textmode()
|
||||||
oldcursory = cursory;
|
oldcursory = cursory;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned method = System::Keyboard::POLL;
|
unsigned termmode = TERMMODE_KBKEY | TERMMODE_UNICODE | TERMMODE_SIGNAL;
|
||||||
uint32_t codepoint = System::Keyboard::ReceiveKeystroke(method);
|
if ( settermmode(0, termmode) ) { error(1, errno, "settermmode"); }
|
||||||
|
|
||||||
if ( codepoint == 0 ) { continue; }
|
uint32_t codepoint = 0;
|
||||||
if ( codepoint & Keyboard::DEPRESSED )
|
ssize_t numbytes = read(0, &codepoint, sizeof(codepoint));
|
||||||
|
if ( !numbytes ) { break; }
|
||||||
|
if ( numbytes < 0 ) { error(1, errno, "read stdin"); }
|
||||||
|
if ( numbytes < sizeof(codepoint) ) {
|
||||||
|
printf("unexpectedly got %zi bytes\n", numbytes);
|
||||||
|
printf("bytes: %x\n", codepoint);
|
||||||
|
|
||||||
|
|
||||||
|
fprintf(stderr, "bad stdin data\n"); exit(1); }
|
||||||
|
if ( !codepoint ) { continue; }
|
||||||
|
int kbkey = KBKEY_DECODE(codepoint);
|
||||||
|
if ( kbkey )
|
||||||
{
|
{
|
||||||
if ( codepoint == Keyboard::CTRL | Keyboard::DEPRESSED ) { ctrl = false; }
|
if ( kbkey == -KBKEY_LCTRL && dectrlmode ) { return dectrlmode; }
|
||||||
|
int abskbkey = (kbkey < 0) ? -kbkey : kbkey;
|
||||||
|
if ( abskbkey == KBKEY_LCTRL ) { ctrl = (0 < kbkey); continue; }
|
||||||
|
switch ( kbkey )
|
||||||
|
{
|
||||||
|
case -KBKEY_ESC:
|
||||||
|
return MODE_CONFIRM_QUIT;
|
||||||
|
break;
|
||||||
|
case KBKEY_UP:
|
||||||
|
if ( cursory ) { cursory--; }
|
||||||
|
break;
|
||||||
|
case KBKEY_DOWN:
|
||||||
|
if ( cursory < numlines-1 ) { cursory++; }
|
||||||
|
break;
|
||||||
|
case KBKEY_LEFT:
|
||||||
|
if ( cursorx ) { cursorx--; }
|
||||||
|
break;
|
||||||
|
case KBKEY_RIGHT:
|
||||||
|
if ( cursorx < WIDTH-1 ) { cursorx++; }
|
||||||
|
break;
|
||||||
|
case KBKEY_O:
|
||||||
|
if ( ctrl ) { dectrlmode = MODE_SAVE; }
|
||||||
|
break;
|
||||||
|
case KBKEY_R:
|
||||||
|
if ( ctrl ) { dectrlmode = MODE_LOAD; }
|
||||||
|
break;
|
||||||
|
case KBKEY_X:
|
||||||
|
if ( ctrl ) { dectrlmode = MODE_CONFIRM_QUIT; }
|
||||||
|
break;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ctrl )
|
if ( ctrl ) { continue; }
|
||||||
{
|
|
||||||
if ( codepoint == 'o' || codepoint == 'O' ) { return MODE_SAVE; }
|
|
||||||
if ( codepoint == 'r' || codepoint == 'R' ) { return MODE_LOAD; }
|
|
||||||
if ( codepoint == 'x' || codepoint == 'X' ) { return MODE_CONFIRM_QUIT; }
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ( codepoint )
|
switch ( codepoint )
|
||||||
{
|
{
|
||||||
case Keyboard::ESC:
|
|
||||||
return MODE_CONFIRM_QUIT;
|
|
||||||
break;
|
|
||||||
case Keyboard::CTRL:
|
|
||||||
ctrl = true;
|
|
||||||
break;
|
|
||||||
case Keyboard::UP:
|
|
||||||
if ( cursory ) { cursory--; }
|
|
||||||
break;
|
|
||||||
case '\n':
|
case '\n':
|
||||||
cursorx = 0;
|
cursorx = 0;
|
||||||
if ( cursory < HEIGHT-1 ) { numlines++; }
|
if ( cursory < HEIGHT-1 ) { numlines++; cursory++; }
|
||||||
case Keyboard::DOWN:
|
|
||||||
if ( cursory < numlines-1 ) { cursory++; }
|
|
||||||
break;
|
|
||||||
case Keyboard::LEFT:
|
|
||||||
if ( cursorx ) { cursorx--; }
|
|
||||||
break;
|
|
||||||
case Keyboard::RIGHT:
|
|
||||||
if ( cursorx < WIDTH-1 ) { cursorx++; }
|
|
||||||
break;
|
break;
|
||||||
case '\b':
|
case '\b':
|
||||||
if ( cursorx )
|
if ( cursorx )
|
||||||
|
@ -179,24 +240,32 @@ unsigned confirmquit()
|
||||||
printf("\e37m\e40m\e[2J\e[H");
|
printf("\e37m\e40m\e[2J\e[H");
|
||||||
printf("There are unsaved changes: Are you sure you want to quit? (Y/N)\n");
|
printf("There are unsaved changes: Are you sure you want to quit? (Y/N)\n");
|
||||||
|
|
||||||
|
if ( settermmode(0, TERMMODE_KBKEY | TERMMODE_SIGNAL | TERMMODE_ECHO) )
|
||||||
|
{
|
||||||
|
error(1, errno, "settermmode");
|
||||||
|
}
|
||||||
|
|
||||||
while ( true )
|
while ( true )
|
||||||
{
|
{
|
||||||
unsigned method = System::Keyboard::POLL;
|
uint32_t codepoint;
|
||||||
uint32_t codepoint = System::Keyboard::ReceiveKeystroke(method);
|
ssize_t numbytes = read(0, &codepoint, sizeof(codepoint));
|
||||||
|
if ( !numbytes ) { exit(0); }
|
||||||
|
if ( numbytes < 0 ) { error(1, errno, "read stdin"); }
|
||||||
|
if ( numbytes < sizeof(codepoint) ) { fprintf(stderr, "bad stdin data\n"); exit(1); }
|
||||||
|
if ( !codepoint ) { continue; }
|
||||||
|
|
||||||
if ( codepoint == 0 ) { continue; }
|
int kbkey = KBKEY_DECODE(codepoint);
|
||||||
if ( codepoint & Keyboard::DEPRESSED ) { continue; }
|
if ( !kbkey ) { continue; }
|
||||||
|
if ( 0 < kbkey ) { continue; }
|
||||||
|
|
||||||
switch ( codepoint )
|
switch ( kbkey )
|
||||||
{
|
{
|
||||||
case Keyboard::ESC:
|
case -KBKEY_ESC:
|
||||||
return MODE_QUIT;
|
return MODE_QUIT;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case -KBKEY_N:
|
||||||
case 'N':
|
|
||||||
return MODE_TEXT;
|
return MODE_TEXT;
|
||||||
case 'y':
|
case -KBKEY_Y:
|
||||||
case 'Y':
|
|
||||||
return MODE_QUIT;
|
return MODE_QUIT;
|
||||||
default:
|
default:
|
||||||
printf("Would you like to quit? N for No, Y for Yes\n");
|
printf("Would you like to quit? N for No, Y for Yes\n");
|
||||||
|
@ -219,6 +288,7 @@ bool savetofile(const char* path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( close(fd) ) { error(0, errno, "close: %s", path); return false; }
|
if ( close(fd) ) { error(0, errno, "close: %s", path); return false; }
|
||||||
|
strcpy(filename, path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,54 +296,21 @@ int savemode()
|
||||||
{
|
{
|
||||||
printf("\e37m\e40m\e[2J\e[H");
|
printf("\e37m\e40m\e[2J\e[H");
|
||||||
printf("Please enter the filename you wish to save the text to and press "
|
printf("Please enter the filename you wish to save the text to and press "
|
||||||
"enter. Type an empty filename or press ESC to abort.\n\n");
|
"enter. Type an empty filename to abort.\n\n");
|
||||||
|
|
||||||
char writefilename[256];
|
char* storage = NULL;
|
||||||
strcpy(writefilename, filename);
|
|
||||||
|
|
||||||
retry:
|
do
|
||||||
size_t len = strlen(writefilename);
|
|
||||||
printf("File Name to Write: %s", writefilename);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
bool readytosave = false;
|
|
||||||
|
|
||||||
while ( !readytosave )
|
|
||||||
{
|
{
|
||||||
unsigned method = System::Keyboard::POLL;
|
delete[] storage;
|
||||||
uint32_t codepoint = System::Keyboard::ReceiveKeystroke(method);
|
printf("File to Write: ");
|
||||||
|
fflush(stdout);
|
||||||
|
storage = readline(0);
|
||||||
|
if ( !storage ) { error(1, errno, "readline"); }
|
||||||
|
if ( !storage[0] ) { delete[] storage; return MODE_TEXT; }
|
||||||
|
} while ( !savetofile(storage) );
|
||||||
|
delete[] storage;
|
||||||
|
|
||||||
if ( codepoint == 0 ) { continue; }
|
|
||||||
if ( codepoint & Keyboard::DEPRESSED ) { continue; }
|
|
||||||
|
|
||||||
switch ( codepoint )
|
|
||||||
{
|
|
||||||
case Keyboard::ESC:
|
|
||||||
return MODE_TEXT;
|
|
||||||
break;
|
|
||||||
case '\b':
|
|
||||||
if ( 0 < len ) { printf("\b"); fflush(stdout); writefilename[--len] = 0; }
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
if ( len == 0 ) { return MODE_TEXT; }
|
|
||||||
readytosave = true;
|
|
||||||
printf("\n");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if ( 0x80 <= codepoint ) { continue; }
|
|
||||||
writefilename[len++] = codepoint;
|
|
||||||
writefilename[len+1] = 0;
|
|
||||||
char msg[2];
|
|
||||||
msg[0] = codepoint;
|
|
||||||
msg[1] = 0;
|
|
||||||
printf("%s", msg);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !savetofile(writefilename) ) { goto retry; }
|
|
||||||
|
|
||||||
strcpy(filename, writefilename);
|
|
||||||
bufferchanged = false;
|
bufferchanged = false;
|
||||||
|
|
||||||
printf("Succesfully saved\n");
|
printf("Succesfully saved\n");
|
||||||
|
@ -318,6 +355,8 @@ bool loadfromfile(const char* path)
|
||||||
cursorx = 0;
|
cursorx = 0;
|
||||||
cursory = 0;
|
cursory = 0;
|
||||||
|
|
||||||
|
strcpy(filename, path);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,60 +364,21 @@ int loadmode()
|
||||||
{
|
{
|
||||||
printf("\e37m\e40m\e[2J\e[H");
|
printf("\e37m\e40m\e[2J\e[H");
|
||||||
printf("Please enter the filename you wish to load text from and press "
|
printf("Please enter the filename you wish to load text from and press "
|
||||||
"enter. Type an empty filename or press ESC to abort.\n\n");
|
"enter. Type an empty filename to abort.\n\n");
|
||||||
|
|
||||||
char loadfilename[256];
|
char* storage = NULL;
|
||||||
loadfilename[0] = 0;
|
|
||||||
|
|
||||||
retry:
|
do
|
||||||
size_t len = strlen(loadfilename);
|
|
||||||
printf("File Name to Load: %s", loadfilename);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
bool readytoload = false;
|
|
||||||
|
|
||||||
while ( !readytoload )
|
|
||||||
{
|
{
|
||||||
unsigned method = System::Keyboard::POLL;
|
delete[] storage;
|
||||||
uint32_t codepoint = System::Keyboard::ReceiveKeystroke(method);
|
printf("File to Load: ");
|
||||||
|
fflush(stdout);
|
||||||
|
storage = readline(0);
|
||||||
|
if ( !storage ) { error(1, errno, "readline"); }
|
||||||
|
if ( !storage[0] ) { delete[] storage; return MODE_TEXT; }
|
||||||
|
} while ( !loadfromfile(storage) );
|
||||||
|
delete[] storage;
|
||||||
|
|
||||||
if ( codepoint == 0 ) { continue; }
|
|
||||||
if ( codepoint & Keyboard::DEPRESSED ) { continue; }
|
|
||||||
|
|
||||||
switch ( codepoint )
|
|
||||||
{
|
|
||||||
case Keyboard::ESC:
|
|
||||||
return MODE_TEXT;
|
|
||||||
break;
|
|
||||||
case '\b':
|
|
||||||
if ( 0 < len ) { printf("\b"); fflush(stdout); loadfilename[--len] = 0; }
|
|
||||||
break;
|
|
||||||
case '\n':
|
|
||||||
if ( len == 0 ) { return MODE_TEXT; }
|
|
||||||
readytoload = true;
|
|
||||||
printf("\n");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if ( 0x80 <= codepoint ) { continue; }
|
|
||||||
loadfilename[len++] = codepoint;
|
|
||||||
loadfilename[len+1] = 0;
|
|
||||||
char msg[2];
|
|
||||||
msg[0] = codepoint;
|
|
||||||
msg[1] = 0;
|
|
||||||
printf("%s", msg);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !loadfromfile(loadfilename) )
|
|
||||||
{
|
|
||||||
clearbuffers();
|
|
||||||
cursorx = 0;
|
|
||||||
cursory = 0;
|
|
||||||
goto retry;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(filename, loadfilename);
|
|
||||||
bufferchanged = false;
|
bufferchanged = false;
|
||||||
|
|
||||||
return MODE_TEXT;
|
return MODE_TEXT;
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <error.h>
|
#include <error.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <libmaxsi/platform.h>
|
#include <libmaxsi/platform.h>
|
||||||
#include <libmaxsi/process.h>
|
#include <libmaxsi/process.h>
|
||||||
#include <libmaxsi/thread.h>
|
|
||||||
|
|
||||||
using namespace Maxsi;
|
using namespace Maxsi;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ int main(int argc, char* argv[])
|
||||||
printf("\r\e[m\e[J");
|
printf("\r\e[m\e[J");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
pid_t childpid = Process::Fork();
|
pid_t childpid = fork();
|
||||||
if ( childpid < 0 ) { perror("fork"); return 2; }
|
if ( childpid < 0 ) { perror("fork"); return 2; }
|
||||||
|
|
||||||
return ( childpid == 0 ) ? child() : parent(childpid);
|
return ( childpid == 0 ) ? child() : parent(childpid);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/termmode.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -8,8 +9,6 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <libmaxsi/platform.h>
|
#include <libmaxsi/platform.h>
|
||||||
#include <libmaxsi/process.h>
|
#include <libmaxsi/process.h>
|
||||||
#include <libmaxsi/sortix-keyboard.h>
|
|
||||||
#include <libmaxsi/string.h>
|
|
||||||
|
|
||||||
using namespace Maxsi;
|
using namespace Maxsi;
|
||||||
|
|
||||||
|
@ -17,6 +16,13 @@ int status = 0;
|
||||||
|
|
||||||
void command()
|
void command()
|
||||||
{
|
{
|
||||||
|
unsigned termmode = TERMMODE_UNICODE
|
||||||
|
| TERMMODE_SIGNAL
|
||||||
|
| TERMMODE_UTF8
|
||||||
|
| TERMMODE_LINEBUFFER
|
||||||
|
| TERMMODE_ECHO;
|
||||||
|
settermmode(0, termmode);
|
||||||
|
|
||||||
const size_t CWD_SIZE = 512;
|
const size_t CWD_SIZE = 512;
|
||||||
char cwd[CWD_SIZE];
|
char cwd[CWD_SIZE];
|
||||||
const char* wd = getcwd(cwd, CWD_SIZE);
|
const char* wd = getcwd(cwd, CWD_SIZE);
|
||||||
|
@ -31,35 +37,23 @@ void command()
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
unsigned method = System::Keyboard::POLL;
|
char c;
|
||||||
uint32_t codepoint = System::Keyboard::ReceiveKeystroke(method);
|
ssize_t bytesread = read(1, &c, sizeof(c));
|
||||||
|
if ( bytesread < 0 ) { error(64, errno, "read stdin"); }
|
||||||
if ( codepoint == 0 ) { continue; }
|
if ( !bytesread ) { break; }
|
||||||
if ( codepoint & Maxsi::Keyboard::DEPRESSED ) { continue; }
|
if ( !c ) { continue; }
|
||||||
if ( codepoint >= 0x80 ) { continue; }
|
if ( c == '\n' ) { break; }
|
||||||
|
if ( commandsize <= commandused ) { continue; }
|
||||||
if ( codepoint == '\b' )
|
command[commandused++] = c;
|
||||||
{
|
|
||||||
if ( 0 < commandused ) { printf("\b"); fflush(stdout); commandused--; }
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( commandsize <= commandused && codepoint != '\n' ) { continue; }
|
|
||||||
|
|
||||||
char msg[2]; msg[0] = codepoint; msg[1] = '\0';
|
|
||||||
printf("%s", msg);
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
if ( codepoint == '\n' ) { command[commandused] = '\0'; break; }
|
|
||||||
|
|
||||||
command[commandused++] = codepoint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command[commandused] = '\0';
|
||||||
|
|
||||||
if ( command[0] == '\0' ) { return; }
|
if ( command[0] == '\0' ) { return; }
|
||||||
|
|
||||||
if ( String::Compare(command, "$?") == 0 ) { printf("%u\n", status); status = 0; return; }
|
if ( strcmp(command, "$?") == 0 ) { printf("%u\n", status); status = 0; return; }
|
||||||
if ( String::Compare(command, "$$") == 0 ) { printf("%u\n", Process::GetPID()); status = 0; return; }
|
if ( strcmp(command, "$$") == 0 ) { printf("%u\n", Process::GetPID()); status = 0; return; }
|
||||||
if ( String::Compare(command, "$PPID") == 0 ) { printf("%u\n", Process::GetParentPID()); status = 0; return; }
|
if ( strcmp(command, "$PPID") == 0 ) { printf("%u\n", Process::GetParentPID()); status = 0; return; }
|
||||||
|
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
const char* argv[256];
|
const char* argv[256];
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include <sys/keycodes.h>
|
||||||
|
#include <sys/termmode.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -5,10 +7,6 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <error.h>
|
#include <error.h>
|
||||||
#include <libmaxsi/platform.h>
|
|
||||||
#include <libmaxsi/sortix-keyboard.h>
|
|
||||||
|
|
||||||
using namespace Maxsi;
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
@ -45,17 +43,21 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
printf("\n--pager--");
|
printf("\n--pager--");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
uint32_t codepoint;
|
settermmode(0, TERMMODE_KBKEY | TERMMODE_SIGNAL);
|
||||||
bool doexit = false;
|
bool doexit = false;
|
||||||
|
int kbkey;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
unsigned method = System::Keyboard::POLL;
|
uint32_t codepoint;
|
||||||
codepoint = System::Keyboard::ReceiveKeystroke(method);
|
ssize_t numbytes = read(0, &codepoint, sizeof(codepoint));
|
||||||
if ( codepoint == Keyboard::DOWN ) { break; }
|
if ( !numbytes ) { exit(0); }
|
||||||
if ( codepoint == Keyboard::PGDOWN ) { linesleft = HEIGHT-1; break; }
|
if ( numbytes < 0 ) { error(1, errno, "read(stdin)"); }
|
||||||
if ( codepoint == 'q' ) { doexit = true; break; }
|
if ( numbytes < sizeof(codepoint) ) { error(1, errno, "bad stdin"); }
|
||||||
}
|
if ( !(kbkey = KBKEY_DECODE(codepoint)) ) { continue; }
|
||||||
while ( codepoint != '\n' );
|
if ( kbkey == KBKEY_DOWN ) { break; }
|
||||||
|
if ( kbkey == KBKEY_PGDOWN ) { linesleft = HEIGHT-1; break; }
|
||||||
|
if ( kbkey == -KBKEY_Q ) { doexit = true; break; }
|
||||||
|
} while ( kbkey != KBKEY_ENTER );
|
||||||
printf("\r\e[J");
|
printf("\r\e[J");
|
||||||
if ( doexit ) { exit(result); }
|
if ( doexit ) { exit(result); }
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue