diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e149742..084b5f4 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 diff --git a/.rubocop.yml b/.rubocop.yml index 6da5969..3db15b9 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 diff --git a/Changelog.md b/Changelog.md index ec452ef..e61950f 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 diff --git a/Gemfile b/Gemfile index 15da695..2c9d8e4 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 diff --git a/lib/highline.rb b/lib/highline.rb index dc4e344..87615c0 100644 --- a/lib/highline.rb +++ b/lib/highline.rb @@ -555,21 +555,26 @@ 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" - chopped = line.chop! - output_erase_char if chopped && question.echo - elsif character == "\cU" + + 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 + 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 - line << character + else # Any other character + line += character say_last_char_or_echo_char(line, question) end diff --git a/lib/highline/menu.rb b/lib/highline/menu.rb index 2ae1ad3..36128cf 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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 32bfcb8..e70a1aa 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"