From 182bfc1d5fc639bb2367c7a1ad9a40480b2551f2 Mon Sep 17 00:00:00 2001 From: "Abinoam Praxedes Marques Jr." Date: Mon, 6 Jan 2025 00:11:23 -0300 Subject: [PATCH 1/8] Fix for frozen string literal on lib/highline/menu.rb --- lib/highline/menu.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb index 2ae1ad31..36128cff 100644 --- a/lib/highline/menu.rb +++ b/lib/highline/menu.rb @@ -374,12 +374,14 @@ def options end def map_items_by_index - if [:letter, :capital_letter].include?(@index) - # @ and ` are the previous ASCII characters to A and a respectively - prev_char = (@index == :capital_letter ? '@' : '`') - all_items.map { prev_char.succ!.dup } + size = all_items.size + case @index + when :letter + ("a".."z").first(size) + when :capital_letter + ("A".."Z").first(size) else - (1..all_items.size).map(&:to_s) + (1..size).map(&:to_s) end end From 7c42ad1c7ccd960817f21c8b0b248e4206d18ca9 Mon Sep 17 00:00:00 2001 From: "Abinoam Praxedes Marques Jr." Date: Mon, 6 Jan 2025 00:34:46 -0300 Subject: [PATCH 2/8] Fix for frozen string literal on lib/highline.rb --- lib/highline.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/highline.rb b/lib/highline.rb index dc4e344d..cb52ab61 100644 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -560,16 +560,18 @@ def get_line_raw_no_echo_mode(question) break if ["\n", "\r"].include? character # honor backspace and delete - if character == "\b" || character == "\u007F" - chopped = line.chop! - output_erase_char if chopped && question.echo + if (character == "\b" || character == "\u007F") + unless line.empty? + line = line.chop + output_erase_char if question.echo + end elsif character == "\cU" line.size.times { output_erase_char } if question.echo line = "" elsif character == "\e" ignore_arrow_key else - line << character + line += character say_last_char_or_echo_char(line, question) end From 79d60b1bf457d8ee1e5ed961455ca81fff62d8eb Mon Sep 17 00:00:00 2001 From: "Abinoam Praxedes Marques Jr." Date: Mon, 6 Jan 2025 00:39:38 -0300 Subject: [PATCH 3/8] Fix for frozen string literal on test/test_helper.rb --- test/test_helper.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 32bfcb86..e70a1aa3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,12 +11,14 @@ require "highline/io_console_compatible" require "highline" -debug_message = "Tests will be run under:\n" -debug_message << " - #{HighLine.new.terminal.class}\n" -debug_message << " - HighLine::VERSION #{HighLine::VERSION}\n" -debug_message << " - #{RUBY_DESCRIPTION}\n" if defined? RUBY_DESCRIPTION +debug_message = <<~DEBUG_MESSAGE + Tests will be run under: + - #{HighLine.new.terminal.class} + - HighLine::VERSION #{HighLine::VERSION} +DEBUG_MESSAGE +debug_message += " - #{RUBY_DESCRIPTION}\n" if defined? RUBY_DESCRIPTION puts debug_message require "minitest/autorun" From 452d81347e6b326f6524bfa09e85a1c47a48feef Mon Sep 17 00:00:00 2001 From: "Abinoam Praxedes Marques Jr." Date: Mon, 6 Jan 2025 00:48:03 -0300 Subject: [PATCH 4/8] Add Ruby 3.4 to GitHub Actions matrix --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e149742e..084b5f4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ jobs: os: [ubuntu-latest] ruby-version: - head + - '3.4' - '3.3' - '3.2' - '3.1' @@ -23,7 +24,7 @@ jobs: - os: windows-latest ruby-version: head - os: windows-latest - ruby-version: '3.3' + ruby-version: '3.4' - os: windows-latest ruby-version: mingw - os: windows-latest @@ -33,7 +34,7 @@ jobs: - os: macos-latest ruby-version: 'head' - os: macos-latest - ruby-version: '3.3' + ruby-version: '3.4' runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 From cc067cc944cf5acec3381b37627584fde4bef7cd Mon Sep 17 00:00:00 2001 From: "Abinoam Praxedes Marques Jr." Date: Mon, 6 Jan 2025 00:48:17 -0300 Subject: [PATCH 5/8] Update Rubocop Ruby version target --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6da59697..3db15b9d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ # https://github.com/bbatsov/rubocop/tree/master/config AllCops: - TargetRubyVersion: 3.3 + TargetRubyVersion: 3.4 NewCops: enable # General From dfab07cb03391b179a92273237ff7f80e335bf11 Mon Sep 17 00:00:00 2001 From: "Abinoam Praxedes Marques Jr." Date: Mon, 6 Jan 2025 00:53:19 -0300 Subject: [PATCH 6/8] Add base64 gem to Gemfile ... as it's not included by default in Ruby 3.4 --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 15da695f..2c9d8e4c 100644 --- a/Gemfile +++ b/Gemfile @@ -17,4 +17,5 @@ group :code_quality do # gem "pronto-poper", require: false, platform: :ruby gem "pronto-reek", require: false, platform: :ruby gem "pronto-rubocop", require: false, platform: :ruby + gem "base64", require: false end From a428bbbd6a1bdf51a3db42c606c781aa8b586e69 Mon Sep 17 00:00:00 2001 From: "Abinoam Praxedes Marques Jr." Date: Mon, 6 Jan 2025 01:03:58 -0300 Subject: [PATCH 7/8] Turn if-else to case-when (rubocop) --- lib/highline.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/highline.rb b/lib/highline.rb index cb52ab61..87615c07 100644 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -555,22 +555,25 @@ def get_line_raw_no_echo_mode(question) terminal.raw_no_echo_mode_exec do loop do character = terminal.get_character - raise Interrupt if character == "\u0003" - break unless character - break if ["\n", "\r"].include? character - # honor backspace and delete - if (character == "\b" || character == "\u007F") + case character + when "\u0003" # Ctrl+C (Interrupt) + raise Interrupt + when nil # No character received + break + when "\n", "\r" # Newline or carriage return + break + when "\b", "\u007F" # Backspace and delete unless line.empty? line = line.chop output_erase_char if question.echo end - elsif character == "\cU" + when "\cU" # Clear line line.size.times { output_erase_char } if question.echo line = "" - elsif character == "\e" + when "\e" # Escape key ignore_arrow_key - else + else # Any other character line += character say_last_char_or_echo_char(line, question) end From 296bc23e0892310bb2bf8fab4f8e3a8d5ad4ea41 Mon Sep 17 00:00:00 2001 From: "Abinoam Praxedes Marques Jr." Date: Mon, 6 Jan 2025 01:16:35 -0300 Subject: [PATCH 8/8] Update Changelog.md --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index ec452ef0..e61950fa 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ Below is a complete listing of changes for each revision of HighLine. ### 3.1.2 / 2025-01-05 +* PR #279 - Upgrades and adjustments for Ruby 3.4 release (@abinoam) * PR #278 - Prevent ArgumentError for #col_count_calculate when items exceed 80 chars (@davidjkling, @justintsteele) ### 3.1.1 / 2024-08-18