Skip to content

Commit

Permalink
Turn if-else to case-when (rubocop)
Browse files Browse the repository at this point in the history
  • Loading branch information
abinoam committed Jan 6, 2025
1 parent dfab07c commit a428bbb
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/highline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a428bbb

Please sign in to comment.