torch2424 / wasm-matrix

A Matrix effect in your terminal using AssemblyScript 🚀 and WASI 🧩 . Deployed to WAPM 📦 .
Apache License 2.0
70 stars 5 forks source link

Automatically find the terminal size #1

Open torch2424 opened 5 years ago

torch2424 commented 5 years ago

For a full screen matrix effect.

Attempted solutions

First I tried getting the $LINES and $COLUMNS, but I guess that is not supported in programs.

Doing some more researc, seems C programs seem to use ioctl or termios to do this: https://stackoverflow.com/questions/1022957/getting-terminal-width-in-c . However, in WASI we don't have this.

Then, I realized I can do a hack, and use an ANSI code to move the cursor alllll the way to the bottom right, then use another ANSI code, that replies with the current cursor position. this works!

However, I can't read the stdin where the response goes, without pressing enter. And to read without pressing enter, requires going into "non-canonical" mode (A.K.A raw mode). Which, doesn't seem to be able to be done, without ioctl or termios :(

See my fustration at: https://github.com/torch2424/wasm-matrix/commit/eb51dab3413e0f81aee21cf9e4abfbb053681506

Which has nice links to the POSIX behind the scenes on how this could be implemented.

This problem mostly steams from me not being able to find docs on how to implement an ioctl or termios API.