WIP: feat: add test file for terminal management with tput #25
3 changed files with 92 additions and 0 deletions
24
shard.lock
24
shard.lock
|
@ -4,10 +4,34 @@ shards:
|
||||||
git: https://github.com/straight-shoota/crinja.git
|
git: https://github.com/straight-shoota/crinja.git
|
||||||
version: 0.8.1
|
version: 0.8.1
|
||||||
|
|
||||||
|
crystallabs-helpers:
|
||||||
|
git: https://github.com/crystallabs/crystallabs-helpers.cr.git
|
||||||
|
version: 1.0.1
|
||||||
|
|
||||||
|
ioctl:
|
||||||
|
git: https://github.com/crystal-posix/ioctl.cr.git
|
||||||
|
version: 1.0.0
|
||||||
|
|
||||||
shellwords:
|
shellwords:
|
||||||
git: https://github.com/sztheory/shellwords-crystal.git
|
git: https://github.com/sztheory/shellwords-crystal.git
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
|
||||||
|
term-screen:
|
||||||
|
git: https://github.com/crystal-term/screen.git
|
||||||
|
version: 0.1.0+git.commit.ea51ee8d1f6c286573c41a7e784d31c80af7b9bb
|
||||||
|
|
||||||
|
tput:
|
||||||
|
git: https://github.com/crystallabs/tput.cr.git
|
||||||
|
version: 1.0.7
|
||||||
|
|
||||||
|
unibilium:
|
||||||
|
git: https://github.com/crystallabs/unibilium.cr.git
|
||||||
|
version: 1.0.1
|
||||||
|
|
||||||
|
unibilium-shim:
|
||||||
|
git: https://github.com/crystallabs/unibilium-shim.cr.git
|
||||||
|
version: 1.1.0
|
||||||
|
|
||||||
version_from_shard:
|
version_from_shard:
|
||||||
git: https://github.com/hugopl/version_from_shard.git
|
git: https://github.com/hugopl/version_from_shard.git
|
||||||
version: 1.2.5
|
version: 1.2.5
|
||||||
|
|
|
@ -8,6 +8,8 @@ name: Minimalist FUSE Manager
|
||||||
version: 0.1.11
|
version: 0.1.11
|
||||||
|
|
||||||
targets:
|
targets:
|
||||||
|
test:
|
||||||
|
main: src/test.cr
|
||||||
mfm:
|
mfm:
|
||||||
main: src/main.cr
|
main: src/main.cr
|
||||||
|
|
||||||
|
@ -24,6 +26,9 @@ dependencies:
|
||||||
github: szTheory/shellwords-crystal
|
github: szTheory/shellwords-crystal
|
||||||
version_from_shard:
|
version_from_shard:
|
||||||
github: hugopl/version_from_shard
|
github: hugopl/version_from_shard
|
||||||
|
tput:
|
||||||
|
github: crystallabs/tput.cr
|
||||||
|
version: ~> 1.0
|
||||||
|
|
||||||
# dependencies:
|
# dependencies:
|
||||||
# pg:
|
# pg:
|
||||||
|
|
63
src/test.cr
Normal file
63
src/test.cr
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
require "unibilium"
|
||||||
|
require "tput"
|
||||||
|
|
||||||
|
terminfo = Unibilium::Terminfo.from_env
|
||||||
|
tput = Tput.new terminfo
|
||||||
|
|
||||||
|
# Print detected features and environment
|
||||||
|
p tput.features.to_json
|
||||||
|
p tput.emulator.to_json
|
||||||
|
|
||||||
|
# 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", print some text
|
||||||
|
tput.alternate
|
||||||
|
tput.cursor_pos 10, 20
|
||||||
|
tput.echo "Text at position y=10, x=20"
|
||||||
|
tput.bell
|
||||||
|
tput.cr
|
||||||
|
tput.lf
|
||||||
|
|
||||||
|
tput.echo "Now displaying ACS chars:"
|
||||||
|
tput.cr
|
||||||
|
tput.lf
|
||||||
|
tput.smacs
|
||||||
|
tput.echo "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
|
||||||
|
tput.rmacs
|
||||||
|
|
||||||
|
tput.cr
|
||||||
|
tput.lf
|
||||||
|
tput.echo "Press any keys; q to exit."
|
||||||
|
|
||||||
|
# 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.normal_buffer
|
||||||
|
# tput.reset_cursor
|
||||||
|
# tput.exit_alt_charset_mode
|
||||||
|
# tput.attr("normal", 1)
|
||||||
|
# tput.soft_reset
|
||||||
|
system("stty echo")
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
tput.cr
|
||||||
|
tput.lf
|
||||||
|
tput.echo "Char=#{char.inspect}, Key=#{key.inspect}, Sequence=#{sequence.inspect}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue