chemaclass / phel-cli-gui
Phel functions to render in the terminal. It uses the Cursor from the Symfony Command module.
0.4.0
2024-12-02 10:18 UTC
Requires
- php: >=8.2
- ext-pcntl: *
- ext-readline: *
- phel-lang/phel-lang: ^0.16
- symfony/console: ^7.1
Requires (Dev)
- roave/security-advisories: dev-latest
- symfony/var-dumper: 7.2
README
This library provides you with some Phel functions to render in the terminal. It uses the Cursor from the Symfony Command module.
Functions
(read-input [length])
: reads the input stream and returns it in different formats;:raw
and:hex
.(clear-screen)
: clears the entire screen.(clear-output)
: clears all the output from the cursors' current position to the end of the screen.(clear-line [line])
: clears the output from the line.(render-board [{:width w :height h}])
: renders the borders of a board.(render [x y text & [style]])
: render any text to a concrete position (x,y) in the terminal.
Example
This example will read the input from the keyboard and display the char and its hexadecimal value on the terminal.
You can run it locally using: vendor/bin/phel run src/phel/test-keyboard.phel
Source:
(ns phel-cli-gui\test-keyboard
(:require phel-cli-gui\terminal-gui :refer [read-input render]))
(defn render-input [{:raw raw :hex hex}]
(if (> (php/strlen hex) 0)
(println (format "# Raw input: `%s`, hex: `%s`" raw hex))))
(defn main
"Display the key and its hexadecimal value on the fly"
[]
(println "Type something...")
(loop []
(php/usleep 1000)
(let [input (read-input 3)]
(render-input input)
(recur))))
(main)
Examples
You can see some real examples using this library: