Skip to content

Commit

Permalink
Change to use double-quoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Jun 8, 2020
1 parent f6dd920 commit 47f25d1
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 55 deletions.
42 changes: 21 additions & 21 deletions lib/tty/reader.rb
@@ -1,15 +1,15 @@
# frozen_string_literal: true

require 'tty-cursor'
require 'tty-screen'
require 'wisper'
require "tty-cursor"
require "tty-screen"
require "wisper"

require_relative 'reader/history'
require_relative 'reader/line'
require_relative 'reader/key_event'
require_relative 'reader/console'
require_relative 'reader/win_console'
require_relative 'reader/version'
require_relative "reader/history"
require_relative "reader/line"
require_relative "reader/key_event"
require_relative "reader/console"
require_relative "reader/win_console"
require_relative "reader/version"

module TTY
# A class responsible for reading character input from STDIN
Expand All @@ -31,7 +31,7 @@ class Reader
#
# @api public
def self.windows?
::File::ALT_SEPARATOR == '\\'
::File::ALT_SEPARATOR == "\\"
end

attr_reader :input
Expand Down Expand Up @@ -74,7 +74,7 @@ def initialize(**options)

@track_history = options.fetch(:track_history) { true }
@history_cycle = options.fetch(:history_cycle) { false }
exclude_proc = ->(line) { line.strip == '' }
exclude_proc = ->(line) { line.strip == "" }
@history_exclude = options.fetch(:history_exclude) { exclude_proc }
@history_duplicates = options.fetch(:history_duplicates) { false }

Expand Down Expand Up @@ -131,7 +131,7 @@ def unsubscribe(listener)
#
# @api private
def select_console(input)
if self.class.windows? && !env['TTY_TEST']
if self.class.windows? && !env["TTY_TEST"]
WinConsole.new(input)
else
Console.new(input)
Expand Down Expand Up @@ -172,7 +172,7 @@ def unbufferred(&block)
def read_keypress(options = {})
opts = { echo: false, raw: true }.merge(options)
codes = unbufferred { get_codes(opts) }
char = codes ? codes.pack('U*') : nil
char = codes ? codes.pack("U*") : nil

trigger_key_event(char) if char
char
Expand Down Expand Up @@ -224,16 +224,16 @@ def get_codes(options = {}, codes = [])
# @return [String]
#
# @api public
def read_line(prompt = '', **options)
def read_line(prompt = "", **options)
opts = { echo: true, raw: true }.merge(options)
value = options.fetch(:value, '')
value = options.fetch(:value, "")
line = Line.new(value, prompt: prompt)
screen_width = TTY::Screen.width

output.print(line)

while (codes = get_codes(opts)) && (code = codes[0])
char = codes.pack('U*')
char = codes.pack("U*")

if [:ctrl_d, :ctrl_z].include?(console.keys[char])
trigger_key_event(char, line: line.to_s)
Expand All @@ -256,7 +256,7 @@ def read_line(prompt = '', **options)
elsif console.keys[char] == :up
line.replace(history_previous) if history_previous?
elsif console.keys[char] == :down
line.replace(history_next? ? history_next : '')
line.replace(history_next? ? history_next : "")
elsif console.keys[char] == :left
line.left
elsif console.keys[char] == :right
Expand All @@ -277,7 +277,7 @@ def read_line(prompt = '', **options)
if opts[:raw]
output.print("\e[1X") unless line.start?
else
output.print(?\s + (line.start? ? '' : ?\b))
output.print(?\s + (line.start? ? "" : ?\b))
end
end

Expand Down Expand Up @@ -362,7 +362,7 @@ def read_multiline(*args)
lines = []
loop do
line = read_line(*args)
break if !line || line == ''
break if !line || line == ""
next if line !~ /\S/ && !@stop
if block_given?
yield(line) unless line.to_s.empty?
Expand Down Expand Up @@ -431,7 +431,7 @@ def inspect
# @return [nil]
#
# @api private
def trigger_key_event(char, line: '')
def trigger_key_event(char, line: "")
event = KeyEvent.from(console.keys, char, line)
trigger(:"key#{event.key.name}", event) if event.trigger?
trigger(:keypress, event)
Expand All @@ -443,7 +443,7 @@ def trigger_key_event(char, line: '')
def handle_interrupt
case @interrupt
when :signal
Process.kill('SIGINT', Process.pid)
Process.kill("SIGINT", Process.pid)
when :exit
exit(130)
when Proc
Expand Down
6 changes: 3 additions & 3 deletions lib/tty/reader/console.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require 'io/wait'
require "io/wait"

require_relative 'keys'
require_relative 'mode'
require_relative "keys"
require_relative "mode"

module TTY
class Reader
Expand Down
4 changes: 2 additions & 2 deletions lib/tty/reader/history.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'forwardable'
require "forwardable"

module TTY
class Reader
Expand Down Expand Up @@ -121,7 +121,7 @@ def [](index)
end
line = @history[index]
if line.nil?
raise IndexError, 'invalid index'
raise IndexError, "invalid index"
end
line.dup
end
Expand Down
4 changes: 2 additions & 2 deletions lib/tty/reader/key_event.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative 'keys'
require_relative "keys"

module TTY
class Reader
Expand All @@ -26,7 +26,7 @@ class KeyEvent < Struct.new(:key, :value, :line)
# @return [KeyEvent]
#
# @api public
def self.from(keys, char, line = '')
def self.from(keys, char, line = "")
key = Key.new
key.name = (name = keys[char]) ? name : :ignore

Expand Down
30 changes: 15 additions & 15 deletions lib/tty/reader/keys.rb
Expand Up @@ -13,12 +13,12 @@ def ctrl_keys
?\C-e => :ctrl_e,
?\C-f => :ctrl_f,
?\C-g => :ctrl_g,
?\C-h => :ctrl_h, # identical to '\b'
?\C-i => :ctrl_i, # identical to '\t'
?\C-j => :ctrl_j, # identical to '\n'
?\C-h => :ctrl_h, # identical to "\b"
?\C-i => :ctrl_i, # identical to "\t"
?\C-j => :ctrl_j, # identical to "\n"
?\C-k => :ctrl_k,
?\C-l => :ctrl_l,
?\C-m => :ctrl_m, # identical to '\r'
?\C-m => :ctrl_m, # identical to "\r"
?\C-n => :ctrl_n,
?\C-o => :ctrl_o,
?\C-p => :ctrl_p,
Expand Down Expand Up @@ -133,18 +133,18 @@ def win_keys
"\e" => :escape,
" " => :space,
"\b" => :backspace,
[224, 71].pack('U*') => :home,
[224, 79].pack('U*') => :end,
[224, 82].pack('U*') => :insert,
[224, 83].pack('U*') => :delete,
[224, 73].pack('U*') => :page_up,
[224, 81].pack('U*') => :page_down,
[224, 71].pack("U*") => :home,
[224, 79].pack("U*") => :end,
[224, 82].pack("U*") => :insert,
[224, 83].pack("U*") => :delete,
[224, 73].pack("U*") => :page_up,
[224, 81].pack("U*") => :page_down,

[224, 72].pack('U*') => :up,
[224, 80].pack('U*') => :down,
[224, 77].pack('U*') => :right,
[224, 75].pack('U*') => :left,
[224, 83].pack('U*') => :clear,
[224, 72].pack("U*") => :up,
[224, 80].pack("U*") => :down,
[224, 77].pack("U*") => :right,
[224, 75].pack("U*") => :left,
[224, 83].pack("U*") => :clear,

"\x00;" => :f1,
"\x00<" => :f2,
Expand Down
14 changes: 7 additions & 7 deletions lib/tty/reader/line.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'forwardable'
require "forwardable"

module TTY
class Reader
Expand All @@ -15,7 +15,7 @@ class Line
#
# @api public
def self.sanitize(text)
text.dup.gsub(ANSI_MATCHER, '')
text.dup.gsub(ANSI_MATCHER, "")
end

# The editable text
Expand All @@ -37,7 +37,7 @@ def self.sanitize(text)
# Create a Line instance
#
# @api private
def initialize(text = '', prompt: '')
def initialize(text = "", prompt: "")
@prompt = prompt.dup
@text = text.dup
@cursor = [0, @text.length].max
Expand Down Expand Up @@ -138,9 +138,9 @@ def move_to_end
# the characters to insert
#
# @example
# text = 'aaa'
# line[5]= 'b'
# => 'aaa b'
# text = "aaa"
# line[5]= "b"
# => "aaa b"
#
# @api public
def []=(i, chars)
Expand All @@ -153,7 +153,7 @@ def []=(i, chars)
end

if i <= 0
before_text = ''
before_text = ""
after_text = @text.dup
elsif i > @text.length - 1 # insert outside of line input
before_text = @text.dup
Expand Down
2 changes: 1 addition & 1 deletion lib/tty/reader/mode.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'io/console'
require "io/console"

module TTY
class Reader
Expand Down
2 changes: 1 addition & 1 deletion lib/tty/reader/version.rb
Expand Up @@ -2,6 +2,6 @@

module TTY
class Reader
VERSION = '0.7.0'
VERSION = "0.7.0"
end # Reader
end # TTY
2 changes: 1 addition & 1 deletion lib/tty/reader/win_api.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'fiddle'
require "fiddle"

module TTY
class Reader
Expand Down
4 changes: 2 additions & 2 deletions lib/tty/reader/win_console.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative 'keys'
require_relative "keys"

module TTY
class Reader
Expand All @@ -24,7 +24,7 @@ class WinConsole
attr_reader :escape_codes

def initialize(input)
require_relative 'win_api'
require_relative "win_api"
@input = input
@keys = Keys.ctrl_keys.merge(Keys.win_keys)
@escape_codes = [[NUL_HEX.ord], [ESC.ord], EXT_HEX.bytes.to_a]
Expand Down

0 comments on commit 47f25d1

Please sign in to comment.