From 582282e52570ea77ecb1593a20fe44c46b1479fb Mon Sep 17 00:00:00 2001 From: Glenn Date: Mon, 20 Nov 2023 12:05:51 +0100 Subject: [PATCH 1/4] 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 + -- 2.45.2 From 96f552128609dfe017e36c750fcfcc7e3dda6a19 Mon Sep 17 00:00:00 2001 From: Glenn Date: Mon, 20 Nov 2023 12:28:06 +0100 Subject: [PATCH 2/4] fix: add workaround preserving terminal integrity --- src/test.cr | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/test.cr b/src/test.cr index b1356f7..6b9e3f0 100644 --- a/src/test.cr +++ b/src/test.cr @@ -47,13 +47,13 @@ tput.listen do |char, key, sequence| # were consumed as part of identifying the key that was # pressed. if char == 'q' - tput.normal_buffer + # tput.normal_buffer # tput.reset_cursor # tput.exit_alt_charset_mode # tput.attr("normal", 1) # tput.soft_reset - system("stty echo") - exit + # system("stty echo") + break else tput.cr tput.lf @@ -61,3 +61,5 @@ tput.listen do |char, key, sequence| end end +tput.normal_buffer +# tput.clear -- 2.45.2 From c66534d889fae2c95eaaf75fd53d754c8776f899 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 21 Nov 2023 10:14:55 +0100 Subject: [PATCH 3/4] ci: add missing build dependency --- .drone.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.yml b/.drone.yml index 8999d06..259b38c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -19,6 +19,7 @@ steps: # cmake g++ \ # libevent-dev libpcre3-dev \ # libyaml-dev liblzma-dev + - apk --update add unibilium - shards install - shards build --production --static - strip bin/mfm -- 2.45.2 From 0fce436ceefe6744a8adb7d9d1fb757c52191b60 Mon Sep 17 00:00:00 2001 From: Glenn Date: Tue, 21 Nov 2023 10:16:41 +0100 Subject: [PATCH 4/4] ci: fix unibilium dev package name --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 259b38c..d821330 100644 --- a/.drone.yml +++ b/.drone.yml @@ -19,7 +19,7 @@ steps: # cmake g++ \ # libevent-dev libpcre3-dev \ # libyaml-dev liblzma-dev - - apk --update add unibilium + - apk --update add unibilium-dev - shards install - shards build --production --static - strip bin/mfm -- 2.45.2