From 582282e52570ea77ecb1593a20fe44c46b1479fb Mon Sep 17 00:00:00 2001 From: Glenn Date: Mon, 20 Nov 2023 12:05:51 +0100 Subject: [PATCH] feat: add test file for terminal management with tput --- shard.lock | 24 ++++++++++++++++++++ shard.yml | 5 +++++ src/test.cr | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/test.cr diff --git a/shard.lock b/shard.lock index e13838b..b070778 100644 --- a/shard.lock +++ b/shard.lock @@ -4,10 +4,34 @@ shards: git: https://github.com/straight-shoota/crinja.git 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: git: https://github.com/sztheory/shellwords-crystal.git 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: git: https://github.com/hugopl/version_from_shard.git version: 1.2.5 diff --git a/shard.yml b/shard.yml index 91274e8..7fba66c 100644 --- a/shard.yml +++ b/shard.yml @@ -8,6 +8,8 @@ name: Minimalist FUSE Manager version: 0.1.11 targets: + test: + main: src/test.cr mfm: main: src/main.cr @@ -24,6 +26,9 @@ dependencies: github: szTheory/shellwords-crystal version_from_shard: github: hugopl/version_from_shard + tput: + github: crystallabs/tput.cr + version: ~> 1.0 # dependencies: # pg: diff --git a/src/test.cr b/src/test.cr new file mode 100644 index 0000000..b1356f7 --- /dev/null +++ b/src/test.cr @@ -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 +