3 #include "pseudo_curses.h"
6 #include <acess/devices/pty.h>
10 bool ACurses_GetDims_Acess(void);
11 bool ACurses_GetDims_SerialTermHack(void);
14 int giTerminal_Width = 80;
15 int giTerminal_Height = 25;
18 void ACurses_Init(void)
20 if( ACurses_GetDims_Acess() ) {
22 else if( ACurses_GetDims_SerialTermHack() ) {
25 _SysDebug("note: assuming 80x25, can't get terminal dimensions");
26 giTerminal_Width = 80;
27 giTerminal_Height = 25;
31 bool ACurses_GetDims_Acess(void)
33 if( _SysIOCtl(1, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL )
37 if( _SysIOCtl(1, PTY_IOCTL_GETDIMS, &dims) == -1 )
39 giTerminal_Width = dims.W;
40 giTerminal_Height = dims.H;
44 bool ACurses_GetDims_SerialTermHack(void)
46 _SysDebug("ACurses_GetDims_SerialTermHack: Trying");
47 // Set cursor to 1000,1000 , request cursor position, reset cursor to 0,0
48 static const char req[] = "\033[1000;1000H\033[6n\033[H";
50 _SysWrite(1, req, sizeof(req));
51 int64_t timeout = 1000;
55 _SysSelect(1, &fds, NULL, NULL, &timeout, 0);
56 if( !FD_ISSET(0, &fds) )
59 if( fgetc(stdin) != '\x1b' )
61 if( fgetc(stdin) != '[' )
63 if( fscanf(stdin, "%i;%i", &giTerminal_Width, &giTerminal_Height) != 2 )
65 if( fgetc(stdin) != 'R' )
71 void SetCursorPos(int Row, int Col)
73 printf("\x1B[%i;%iH", Row, Col);