RemiCharms
RemiCharms is an interface to libcurses for Crystal. It provides both a raw, low-level interface to libcurses via C bindings, and a more higher-level interface.
It is intended to be a bit easier to use than straight-up ncurses bindings. It is based on cl-charms, a similar interface to ncurses for Common Lisp.
Currently, the low-level interface (the NCurses
module) is pretty close to
ncurses itself. The high-level interface can be used directly alongside the
low-level interface for those instances where the high level interface is
missing functionality.
API documentation can be found here.
Wanna support Remilia? Buy me a coffee on Ko-Fi, or support her through Liberapay.
How do I get set up?
You will need Fossil installed to clone this repo. You will also need Shards v0.17.1 or later. If you have an earlier version of Shards, you will need to to build the latest version manually.
Add this to your shard.yml
file:
dependencies:
remicharms:
fossil: https://chiselapp.com/user/MistressRemilia/repository/remicharms/
Usage
The examples
folder has more examples. API documentation can be found
here.
require "./src/remicharms"
RemiCharms.withCurses do |stdwin|
RemiCharms.echoing = false
RemiCharms.inputMode = RemiCharms::InputMode::CBreak
stdwin.nonBlocking = true
lastTime = Time.unix(0)
width = 0
height = 0
x = 0
y = 0
message = "Hello, world!"
loop do
c = stdwin.getChar!
break if c == 'q'
stdwin.refresh
width, height = stdwin.size
if (Time.local - lastTime).total_milliseconds >= 469
stdwin.clear
x = Random.rand(width - message.size)
y = Random.rand(height)
stdwin.write(message, x, y)
lastTime = Time.local
else
sleep 10.milliseconds
end
end
end
Important Note
The high level API swaps the X and Y arguments to any function that uses them. It also swaps the top/bottom and left/right arguments to the border drawing functions.
Style info
I use a somewhat non-standard style for my code.
- Keep lines 118 characters or shorter. Obviously sometimes you can't, but please try. Use 80 or 115 characters for Markdown files, though.
- Please use pascalCase for variable and method names. Use CamelCase for type names. Use UPPER_SNAKE_CASE for constants.
- ALWAYS put parentheses around method parameters, except for these methods:
puts
,pp
,p
,raise
,sleep
,spawn
,loop
, andexit
. - Always the full
do |foo|...end
syntax with blocks, except when it's all on one line, then always use { and }. - The type name for exceptions end with Error. For example,
ExternalProgramError
.
How do I contribute?
- Go to https://chiselapp.com/user/MistressRemilia/repository/remicharms/ and clone the Fossil repository.
- Create a new branch for your feature.
- Push locally to the new branch.
- Create a bundle with Fossil that contains your changes.
- Get in contact with me.
Contributors
- Remilia Scarlet - creator and maintainer
- Homepage: https://remilia.sdf.org/
- Mastodon: @MistressRemilia@social.sdf.org
- Email: zremiliaz@postzeoz.jpz My real address does not contain Z's
Links and Licenses
RemiCurses is under the GNU Affero General Public License version 3.