Subj : Detecting Terminals To : Dingo From : AKAcastor Date : Wed Mar 20 2024 02:51 pm d> I was the first to write a BBS that supports UTF-8 and d> cp437, but we required selecting it manually d> (x84/default/charset.py script). Supporting UTF-8 is a nice touch, certainly makes it easier for callers to use a variety of modern terminals. d> But I wanted to share d> with you a technique that I've been using lately that d> should allow your BBS Softwares to automatically detect d> the client, using the "Query Cursor Position" sequence, d> "\x1b[6n". You could also use this to automatically d> detect for "bots" or "scanners" rather than real users. d> At least, any bot would have to emulate a terminal to d> respond correctly. This same sequence can also be useful for testing for general ANSI support. Nice trick to use it to detect the unicode support level too! d> In any case, if the "bots" are not responding to this d> query, you can kick them off. You can detect if they d> support utf-8, and, whether they support emojis etc. d> CP437 terminals like SyncTerm will be "corrupted" by utf- d> 8 bytes or display characters incorrectly, and by d> measuring the delta of the starting and ending position d> of a character after displaying unicode string, we can d> determine whether they are utf-8 capable automatically. Great technique and thank you for sharing it. Since my BBS doesn't support UTF-8 (yet) I might use the detection to present a message to callers using UTF-8 terminals to let them know CP437 would be better. I think the idea of testing for terminal emulation to detect bots is interesting. It may run the risk of false positives, if you get callers using odd terminals - probably more concern for those running older systems like CBBS or other pure ASCII systems. I wonder how many (if any) bots support the ANSI terminal emulation - I have noticed that some of the scanners are doing telnet protocol negotiation (not just sending raw text for login attempts). Gonna have to run some tests on these bots! On a similar topic of detecting terminals - I have recently implemented sixel detection (and am curious if anyone has other/better techniques). Sixel detection isn't too difficult, but from my tests different terminals respond to different queries. "\x1b[4c" works with iTerm2 "\x1b[<0c" works with SyncTerm Read the response which should end with 'c'. If the response has ;4 in it then that indicates that sixel is supported. For sixel detection on my BBS, I send both strings ("\x1b[4c\x1b[<0c") and read until I receive a 'c' (or time out after a second or two). If I find ";4" in the response then I assume sixel support exists. I'm still working on understanding how to specify if a terminal should scale the image when displaying (SyncTerm seems to scale automatically, iTerm2 doesn't). Chris/akacastor --- Maximus 3.01 * Origin: Another Millennium - Canada - another.tel (21:1/162) .