(SOLVED) getwchar (garbage in the terminal)

Linux specific questions.
Post Reply
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

(SOLVED) getwchar (garbage in the terminal)

Post by VANYA »

Hi all!

simple program:

Code: Select all

#include "crt.bi"
Dim As Long ws = getwchar
? ws
output result:

100
^[[1;1R^[[1;1Ruser@user:~/test$ RR

If you use getchar , then everything works fine. However, I need a function that returns multibyte characters.

Does anyone know why this is happening?
Last edited by VANYA on Apr 16, 2022 15:45, edited 1 time in total.
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: getwchar (garbage in the terminal)

Post by VANYA »

I understand everything. Do not mix FB console commands output and CRT input functions!

This is how it works well:

Code: Select all

#include "crt.bi"
Dim As Long ws = getwchar
printf( !"%d" , ws)
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: (SOLVED) getwchar (garbage in the terminal)

Post by coderJeff »

The fb run time system communicates with the terminal using escape sequences. The garbage seen are unhandled escape sequences - looks like cursor position information. The escape sequences allow features like mouse position, window size, etc to be communicated to fb rtlib from the terminal.

Either getwchar() interrupts / disables the escape sequence handle and/or fb rtlib doesn't know to recover from it.

I think If you read all the bytes from INKEY, you should get the sequence of UTF-8 characters. But then would need to buffer the bytes and convert the UTF8 bytes to a UTF32 for wstrings.

If you don't need fb's colour, locate, width, etc, statements:
Magic fb code to disable escape sequences:

Code: Select all

extern as long __fb_enable_vt100_escapes alias _
	"__fb_enable_vt100_escapes"
dim shared as long __fb_enable_vt100_escapes = 0
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: (SOLVED) getwchar (garbage in the terminal)

Post by VANYA »

coderJeff wrote: Apr 17, 2022 11:46 The fb run time system communicates with the terminal using escape sequences. The garbage seen are unhandled escape sequences - looks like cursor position information. The escape sequences allow features like mouse position, window size, etc to be communicated to fb rtlib from the terminal.

Either getwchar() interrupts / disables the escape sequence handle and/or fb rtlib doesn't know to recover from it.

I think If you read all the bytes from INKEY, you should get the sequence of UTF-8 characters. But then would need to buffer the bytes and convert the UTF8 bytes to a UTF32 for wstrings.

If you don't need fb's colour, locate, width, etc, statements:
Magic fb code to disable escape sequences:

Code: Select all

extern as long __fb_enable_vt100_escapes alias _
	"__fb_enable_vt100_escapes"
dim shared as long __fb_enable_vt100_escapes = 0
yes, so far the only way I see is to use printf directly with escape sequences, without FB's built-in console functions. On Linux, printf prints unicode characters and can work in tandem with getwchar. Thank you for your interest in this topic!
Post Reply