codingteam / euclid

UI library for terminal environments.
MIT License
3 stars 0 forks source link

Review the platform abstraction layer #6

Open ForNeVeR opened 6 years ago

ForNeVeR commented 6 years ago

(Probably linked with #5)

Currently, the platform abstraction layer is nearly-nonexistent. We need to make an isolated place for all of the platform-dependent things (e.g. key codes, Display implementation etc.), so that we have a definitive answer to the question "How do I add the new platform".

hagane commented 6 years ago
  1. We need something to abstract color representation because #D13B0B or LightGoldenRodYellow do not mean a thing for a terminal. Rot.js has some facility to map weird HTML stuff onto ANSI colors, but it's not available in the JVM world.
  2. Input, too. Looks like input handling is ignored and every app has to roll its own.
  3. Storage should be abstracted too. JS apps should use browser local storage, native applications will have to dump their stuff somewhere into user's home directory.
ForNeVeR commented 6 years ago

Regarding the color and input stuff: probably take a look at lanterna, that's a library offering some nice abstractions around terminals.

It somewhat lacked proper Windows support last time I looked, but I could hack it.

hagane commented 6 years ago

I've already dropped in lanterna while implementing terminal support and did some preliminary research on unborking windows terminals, so I'm way ahead on this. Guess I'll do something with colors while finishing #5.

(tldr on terminals in Windows is that they are messed up beyond belief because of historical reasons. lanterna does works ok in a cygwin terminal and has an AWT terminal emulation mode)

ForNeVeR commented 6 years ago

Well, starting from some stupid version of Windows 10 it should work much better. I think we should support that mode. To enable that shit, we should call SetConsoleMode with ENABLE_VIRTUAL_TERMINAL_PROCESSING. Here're docs. I think it should be worth to enable these shits in lanterna.

hagane commented 6 years ago

Not exactly, no. The thing is, lanterna does not have any Windows support to speak of. If it runs in a cygwin environment, it sort of works. If one tries to start it in a cmd window, it still tries to run like that and crashes trying to run stty.exe. I guess there's a possibility of dropping in our own implementation based on com.googlecode.lanterna.terminal.ansi.ANSITerminal. Lanterna does looks for com.googlecode.lanterna.terminal.WindowsTerminal in classpath and tries to use it before falling back to Cygwin. I'm not exactly jumping at the thought of calling WinAPI from inside JVM here though.

ForNeVeR commented 6 years ago

The thing is, lanterna does not have any Windows support to speak of.

Well, yeah, mainstream lanterna doesn't. But some time ago I was working on a branch where it is. If there is a necessity, then we'll be able to dust it out.

I'm not exactly jumping at the thought of calling WinAPI from inside JVM here though.

Heh, but I am!