phantomics / april

The APL programming language (a subset thereof) compiling to Common Lisp.
Apache License 2.0
602 stars 31 forks source link

Suggestions and comments for the croatoan ncurses wrapper #255

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hello phantomics,

by pure chance I recently stumbled upon your april paper [1] and noticed that you not only used but actually referenced the croatoan ncurses library in the paper. Thank you!

Altough I have no idea how to even start to comprehend the APL code, I got the the terminal demo [2] to run and it seems quite nice and appealing and I have made a commit [3] not meant as a PR, with a few suggestions and comments how to improve the terminal handling.

To summarize:

  1. Use the TERM=xterm-256color environment variable to make xterm support 265 colors, instead of the default 8.
  2. Use the ncurses:colors variable to get the number of colors supported by a terminal instead of manually parsing tput colors, which also just asks ncurses for the same information.
  3. I merged main and initialize-screen to make the demo work without slime and the screen global variable, but that is just my personal preference.
  4. You dont have to pass (win event) to every key binding and then ignore them, the length of the lambda list is checked by the event dispatcher.
  5. If you do not actually have code that runs between key presses (during the "nil" event), set input-blocking to t. The blocking timeout (or frame rate) is only useful if you need ticks during your main loop, for example in a game.
  6. Instead of add-wide-char, you can use any lisp stream output function like format, princ or terpri because windows (and thus the main screen) is a stream by the way of gray streams. You need add-wide-char (or just "add") only to pass colors, attributes or the position in one go.

If you have any questions or suggestions for future improvement, you can drop by on the croatoan GH [4] or the ML.

Cheers, McParen

[1] https://zenodo.org/record/6349747/files/april-paper.pdf [2] https://i.imgur.com/BCMpnPK.png [3] https://github.com/McParen/april/commits/master [4] https://github.com/McParen/croatoan

phantomics commented 2 years ago

Hi McParen, thanks for your improvements to the ncurses demo. I was looking for a way to count the number of supported colors from within croatoan but somehow didn't find it. Your other changes also contribute to a more elegant implementation. Look for more croatoan-based April apps in the future.