robhagemans / pcbasic

PC-BASIC - A free, cross-platform emulator for the GW-BASIC family of interpreters
http://www.pc-basic.org
Other
396 stars 48 forks source link

SET_CURSOR_SHAPE not supported on Linux Console #119

Closed ardentperf closed 3 years ago

ardentperf commented 4 years ago

https://github.com/robhagemans/pcbasic/blob/e3cb62be6b192f126a6e15b41f49de691e7010c2/pcbasic/compat/posix_console.py#L59

I installed pcbasic on a Debian 10 system and used it from the console. It seems to me that the ANSI escape sequence for SET_CURSOR_SHAPE is hardcoded in the file posix_console.py - and this escape sequence is not supported by the Linux console. When I first tried to use pcbasic at the console, the lowercase letter "q" was getting printed on the screen. When I commented out the two lines of code which use this escape sequence, the letter "q" was no longer printed on the screen and pcbasic worked as expected.

This page seems to have more information about escape sequences supported by the Linux console. https://man7.org/linux/man-pages/man4/console_codes.4.html

robhagemans commented 4 years ago

Thanks. This'll depend on what console or virtual console you use. Unfortunately there is a trade off between supporting as many features as possible, breadth of support, and code complexity - if I focus on the limitations Linux text mode console this will remove valuable features from common virtual consoles. The primary interface is the graphical one - the ansi escape interface is provided as an additional option but some level of glitches are to be expected.

ardentperf commented 4 years ago

I installed pcbasic on a computer without framebuffer or graphical support - so the text terminal ("linux") was the only option. The only issue I've run into so far is the cursor shape.

A little more digging around and I found these two articles which seem related. I haven't yet figured out whether they would work with linux running on a system which didn't support VGA.

I'll poke around some more if I have some free time someday. 🙂 If support for the linux console is as simple as an alternative escape code for just the cursor shape, maybe I could cook up and propose a patch which checked TERM and switched SET_CURSOR_SHAPE for linux.

Seeing that we're talking about a GW-BASIC emulator, supporting the ability to run on a text console doesn't seem totally crazy, does it?

robhagemans commented 4 years ago

It's not totally crazy, but it is also not a great use of time. I'm quite sympathetic to the use on Linux - it's my primary platform - but let's say 90% of PC-BASIC users are on Windows, and even of the remaining spread between Mac, Linux and other Unix, most use a graphical interface whose terminal emulators follow xterm standards one way or another. So in general my thinking is that showing a glitch on the framebuffer console in Linux that hardly anyone still uses is preferable to removing quite essential cursor shape functionality from the vast majority of users. Plus this piece of code has already grown well beyond my ability to maintain it, ANSI escape codes are a horrid mess and every special case or switch increases the testing load.

That said, if there is a simple way to do this that doesn't clog up the code, has been tested on other platforms and terminals/terminal emulators and doesn't break them, I'm happy to look at it.

I think this has the ANSI code supported by the framebuffer console: https://unix.stackexchange.com/questions/49485/escape-code-to-change-cursor-shape

Meanwhile, for your purposes, have you looked at alternatives such as --interface=curses, which uses curses to do all the TERM compatibility hacking, or --interface=cli which is line-based and uses only minimal ANSI?

robhagemans commented 4 years ago

Actually, come to think of it, the reason I didn't want a curses dependency in this interface was that originally it had to work on Windows using an ugly wrapper, and curses is not available on Windows at least in some versions of Python I need to support.

However since I bit the bullet on that one and reimplemented all Windows console functionality using ctypes, that argument no longer holds - this only needs to run on Unixes. So perhaps the right thing to do is to use curses.tigetflag to replace the hardcoded strings. Or just query infocmp... I'll add this to the list of improvements, but I fear that list is rather long at this stage...

robhagemans commented 3 years ago

This sort of works (and apologies fr the initial response which reads back as grumpy). I've made changes along these lines in the develop branch and it seems to work on the framebuffer terminal. I don't know when I'll be able to make another release though - I haven't been able to devote much time to this project lately and the dev branch has some serious unresolved regressions