lib/tty/cursor.rb in tty-cursor-0.4.0 vs lib/tty/cursor.rb in tty-cursor-0.5.0
- old
+ new
@@ -1,6 +1,7 @@
# encoding: utf-8
+# frozen_string_literal: true
module TTY
# Terminal cursor movement ANSI codes
module Cursor
module_function
@@ -33,17 +34,17 @@
end
# Save current position
# @api public
def save
- CSI + 's'
+ Gem.win_platform? ? CSI + 's' : ESC + '7'
end
# Restore cursor position
# @api public
def restore
- CSI + 'u'
+ Gem.win_platform? ? CSI + 'u' : ESC + '8'
end
# Query cursor current position
# @api public
def current
@@ -163,13 +164,13 @@
# @param [Symbol] :direction
# the direction to clear, default :up
#
# @api public
def clear_lines(n, direction = :up)
- n.times.reduce('') do |acc, i|
+ n.times.reduce([]) do |acc, i|
dir = direction == :up ? up : down
acc << clear_line + ((i == n - 1) ? '' : dir)
- end
+ end.join
end
alias clear_rows clear_lines
# Clear screen down from current position
# @api public