Set up Terminal to Use BaCon
Mar 28, 2020 11:06:47 GMT 1
Post by alexfish on Mar 28, 2020 11:06:47 GMT 1
Hi Rikky & All
@ Rickky
here is the demo , sooner than i thought
Here Setting
Clear terminal
RESET_TERM
Get terminal size
GETXY
Set up read ch
getch()
there is a GETCHAR function relating to Rick post but could not get this to work;
in main is a while loop
record & decode the results
when running press Enter/Return
BR
Alex
the code
Then change the Main to this Note there is no -32 Print (int)c-32 << "|" return keys will still exit an all all special key will be shown
Can also test the mouse
Next POST will have a fall though loop to catch special keys
@ Rickky
here is the demo , sooner than i thought
Here Setting
Clear terminal
RESET_TERM
Get terminal size
GETXY
Set up read ch
getch()
there is a GETCHAR function relating to Rick post but could not get this to work;
in main is a while loop
record & decode the results
when running press Enter/Return
BR
Alex
the code
PROTO ioctl , printf, tcgetattr, read , perror
FUNCTION getch() TYPE int
LOCAL buf TYPE int
USEC
struct termios old = {0};
END USEC
IF (tcgetattr(0, &old) < 0) THEN
perror("tcsetattr()")
END IF
old.c_lflag &= ~ICANON
old.c_lflag &= ~ECHO
old.c_cc[VMIN] = 1
old.c_cc[VTIME] = 0
IF (tcsetattr(0, TCSANOW, &old) < 0) THEN
perror("tcsetattr ICANON")
END IF
IF (read(0, &buf, 1) < 0) THEN
perror ("read()")
END IF
old.c_lflag |= ICANON;
old.c_lflag |= ECHO;
IF (tcsetattr(0, TCSADRAIN, &old) < 0) THEN
perror ("tcsetattr ~ICANON")
END IF
RETURN (buf)
END FUNCTION
SUB GETXY( int * row, int * col)
USEC
struct winsize term;
END USEC
ioctl(STDOUT_FILENO, TIOCGWINSZ, &term)
* col = term.ws_col
* row = term.ws_row
END SUB
SUB RESET_TERM()
printf("\x1b[0m");
printf ("\033\143");
END SUB
FUNCTION GETCHAR() TYPE int
LOCAL ch TYPE int
stndin = (STDIN_FILENO)
ch = stndin
RETURN ch
END FUNCTION
' MAIN =========================================================================
'if want term for edit or apps // and or mouse , also totally clear term
' then only your results will be seen
RESET_TERM
LOCAL Tcols, Trows TYPE int
GETXY(&Trows,&Tcols)
PRINT "Rows : " , Trows , " Cols : " , Tcols
LOCAL ch TYPE int
WHILE 1 DO
ch =getch()
PRINT CHR$(ch-32) , "|" ;
IF CHR$(ch)="A" THEN
PRINT "UP"
END IF
IF CHR$(ch)="B" THEN
PRINT "DOWN"
END IF
IF CHR$(ch)="D" THEN
PRINT "LEFT"
END IF
IF CHR$(ch)="e" THEN
PRINT "RIGHT"
END IF
IF CHR$(ch)="\n" THEN
BREAK
END IF
PRINT
WEND
'if want term for edit or apps : clear your rubbish
RESET_TERM
Then change the Main to this Note there is no -32 Print (int)c-32 << "|" return keys will still exit an all all special key will be shown
Can also test the mouse
RESET_TERM
LOCAL Tcols, Trows TYPE int
GETXY(&Trows,&Tcols)
PRINT "Rows : " , Trows , " Cols : " , Tcols
LOCAL ch TYPE int
WHILE 1 DO
ch =getch()
PRINT ch , "|" ;
IF ch= ASC("A") THEN
PRINT "UP"
END IF
IF ch= ASC("B") THEN
PRINT "DOWN"
END IF
IF ch= ASC("D") THEN
PRINT "LEFT"
END IF
IF ch= ASC("E") THEN
PRINT "RIGHT"
END IF
IF CHR$(ch)="\n" THEN
BREAK
END IF
PRINT
WEND
'if want term for edit or apps : clear your rubbish
RESET_TERM
Next POST will have a fall though loop to catch special keys