tput
Version, currently 0.3.116 versions
- 1.0.8latestFeb 1, 2024
- 1.0.7not indexedJul 28, 2026
- 1.0.6not indexedJul 28, 2026
- 1.0.5not indexedJul 28, 2026
- 1.0.4not indexedJul 28, 2026
- 1.0.3not indexedJul 28, 2026
- 1.0.2not indexedJul 28, 2026
- 1.0.1not indexedJul 28, 2026
- 0.6.0not indexedJul 28, 2026
- 0.4.2not indexedJul 28, 2026
- 0.4.1not indexedJul 28, 2026
- 0.4.0not indexedJul 28, 2026
- 0.3.1not indexedJul 28, 2026
- 0.3.0not indexedJul 28, 2026
- 0.2.0not indexedJul 28, 2026
- 0.1.0not indexedJul 28, 2026
github.com/crystallabs/tput.cr
Low-level component for building term/console applications in Crystal
30 stars
0 dependents
License: AGPLv3
Nothing has been indexed for 0.3.1 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
tput:
github: crystallabs/tput.cr
version: ~> 0.3.1Then run:
shards installshard.yml
No shard.yml has been indexed for 0.3.1. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
# Tput.cr
Tput (akin to `tput(1)`) is a complete term/console output library for Crystal.
In general, when writing console apps, 4 layers can be identified:
1. Low-level (terminal emulator & terminfo)
1. Mid-level (console interface, memory state, cursor position, etc.)
1. High-level (a framework or toolkit)
1. End-user apps
Tput implements levels (1) and (2).
Is it any good? Yes, there are many, many functions supported. Check the API
docs for a list.
It is a Crystal-native implementation (except for binding to a C Terminfo library
called `unibilium`). Not even ncurses bindings are used; Tput is a standalone
library that implements all the needed functions itself and provides a much nicer
API.
Why no ncurses? Ncurses is an implementation sort-of specific to C. When not working
in C, many of the ncurses methods make no sense. Also in general, the ncurses API is arcane.
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
tput:
github: crystallabs/tput.cr
version: ~> 1.0
```
2. Run `shards install`
## Overview
If/when initialized with term name, terminfo data will be looked up. If no terminfo
data is found (or one wishes not to use terminfo), Tput's built-in, generic sequences
will be used.
As part of initialization, Tput will also detect terminal features and the
terminal emulator program in use.
There is zero configuration or considerations to have in mind when using
this library. Everything shoud be set up automatically.
For example:
```cr
require "unibilium"
require "tput"
terminfo = Unibilium::Terminfo.from_env
tput = Tput.new terminfo
# Set terminal emulator's title, if possible
tput.title = "Test 123"
# Set cursor to red block
tput.cursor_shape Tput::CursorShape::Block, blink: false
tput.cursor_color Tput::Color::Red
# Switch to "alternate buffer"
tput.alternate
tput.clear
# Print detected features and environment
puts "Term type and features:"
puts tput.emulator.to_json
puts tput.features.to_json
# Print some more text
tput.cursor_pos 15, 20
tput.echo "Text at position y=15, x=20"
tput.bell
tput.cr
tput.lf
# Enter ACS mode, print some ACS chars, and exit ACS mode
tput.echo "Now displaying ACS chars:"
tput.cr
tput.lf
tput.smacs
tput.echo "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
tput.rmacs
tput.cr
tput.lf
tput.echo "Press keys to see their inspected value; press q to exit."
tput.cr
tput.lf
# Listen for keypresses
tput.listen do |char, key, sequence|
# `char` is a single typed character, or the first character
# of a sequence which led to a particular key.
# `key` is a keyboard key, if any. Ordinary characters like
# 'a' or '1' don't have a representation as Key. Special
# keys like Enter, F1, Esc etc. do.
# Sequence is the complete sequence of characters which
# were consumed as part of identifying the key that was
# pressed.
if char == 'q'
tput.cursor_reset
break
else
tput.cr
tput.lf
tput.echo "Char=#{char.inspect}, Key=#{key.inspect}, Sequence=#{sequence.inspect}"
end
end
tput.clear
```
## API documentation
Run `crystal docs` as usual, then open file `docs/index.html`.
## Testing
Run `crystal spec` as usual.
## Thanks
* All the fine folks on Libera.Chat IRC channel #crystal-lang and on Crystal's Gitter channel https://gitter.im/crystal-lang/crystal
* Blacksmoke16, Asterite, HertzDevil, Raz, Oprypin, Straight-shoota, Watzon, Naqvis, and others!
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.3.1- Tagged
- Jul 28, 2026
- Commit
b6cc0cc7dbea- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/crystallabs/tput.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 16