A tiny project to power kotlin projects with *nix console control
The purpose of this project is to enable kotlin console programs to:
- Detect single key press, e.g: key, direction keys
- Output colorful texts
- Control the position of console print.
The old solutions are:
- To include a native library (JNI) in java library, to control console input.
- To call native programs
- To create your own console GUI
The problems of those solutions are:
- Very complicated
- Have compatibility problems
This solution includes 2 parts:
- A shell script, responsible to read raw key press.
- A Kotlin program, implementing the main feature.
These 2 parts are connected by a pipe
+---------+ +--------------+ +------+ +-----------------+
| | ----> | Script | ---> | Pipe | ---> |(stdin) |
| | |(read raw key)| | | | |
| Console | +--------------+ +------+ | Kotlin Program |
| | | |
| | <---------------------------------------- |(stdout) |
+---------+ +-----------------+
- The loops to read one key press
- When user press anything, the script will send the key to pipe
- The Kotlin program reads the pipe
- Then the Kotlin program print output to console, with ANSI code.
- This library only support *nix shell environment (Linux, Mac OS X, Cygwin, MinGW, etc.). Windows cmd is not supported.
- Currently, only bash and zsh are supported. Other shells are not tested.
In project root, type following:
./script/demo.sh
In build.gradle:
sourceControl {
gitRepository("[email protected]:WuYuntaoTheGreat/ansipipe.git") {
producesModule("cn.wuyatang.ansipipe:ansipipe")
}
}
dependencies {
...
implementation 'cn.wuyatang.ansipipe:ansipipe:v0.1.1'
}