\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /proc/self/root/opt/chef/embedded/lib/ruby/gems/2.7.0/gems/tty-cursor-0.7.1/lib/tty/

Viewing File: cursor.rb

# frozen_string_literal: true

require_relative 'cursor/version'

module TTY
  # Terminal cursor movement ANSI codes
  module Cursor
    module_function

    ESC = "\e".freeze
    CSI = "\e[".freeze
    DEC_RST  = 'l'.freeze
    DEC_SET  = 'h'.freeze
    DEC_TCEM = '?25'.freeze

    # Make cursor visible
    # @api public
    def show
      CSI + DEC_TCEM + DEC_SET
    end

    # Hide cursor
    # @api public
    def hide
      CSI + DEC_TCEM + DEC_RST
    end

    # Switch off cursor for the block
    # @api public
    def invisible(stream = $stdout)
      stream.print(hide)
      yield
    ensure
      stream.print(show)
    end

    # Save current position
    # @api public
    def save
      Gem.win_platform? ? CSI + 's' : ESC + '7'
    end

    # Restore cursor position
    # @api public
    def restore
      Gem.win_platform? ? CSI + 'u' : ESC + '8'
    end

    # Query cursor current position
    # @api public
    def current
      CSI + '6n'
    end

    # Set the cursor absolute position
    # @param [Integer] row
    # @param [Integer] column
    # @api public
    def move_to(row = nil, column = nil)
      return CSI + 'H' if row.nil? && column.nil?
      CSI + "#{column + 1};#{row + 1}H"
    end

    # Move cursor relative to its current position
    #
    # @param [Integer] x
    # @param [Integer] y
    #
    # @api public
    def move(x, y)
      (x < 0 ? backward(-x) : (x > 0 ? forward(x) : '')) +
      (y < 0 ? down(-y) : (y > 0 ? up(y) : ''))
    end

    # Move cursor up by n
    # @param [Integer] n
    # @api public
    def up(n = nil)
      CSI + "#{(n || 1)}A"
    end
    alias cursor_up up

    # Move the cursor down by n
    # @param [Integer] n
    # @api public
    def down(n = nil)
      CSI + "#{(n || 1)}B"
    end
    alias cursor_down down

    # Move the cursor backward by n
    # @param [Integer] n
    # @api public
    def backward(n = nil)
      CSI + "#{n || 1}D"
    end
    alias cursor_backward backward

    # Move the cursor forward by n
    # @param [Integer] n
    # @api public
    def forward(n = nil)
      CSI + "#{n || 1}C"
    end
    alias cursor_forward forward

    # Cursor moves to nth position horizontally in the current line
    # @param [Integer] n
    #   the nth aboslute position in line
    # @api public
    def column(n = nil)
      CSI + "#{n || 1}G"
    end

    # Cursor moves to the nth position vertically in the current column
    # @param [Integer] n
    #   the nth absolute position in column
    # @api public
    def row(n = nil)
      CSI + "#{n || 1}d"
    end

    # Move cursor down to beginning of next line
    # @api public
    def next_line
      CSI + 'E' + column(1)
    end

    # Move cursor up to beginning of previous line
    # @api public
    def prev_line
      CSI + 'A' + column(1)
    end

    # Erase n characters from the current cursor position
    # @api public
    def clear_char(n = nil)
      CSI + "#{n}X"
    end

    # Erase the entire current line and return to beginning of the line
    # @api public
    def clear_line
      CSI + '2K' + column(1)
    end

    # Erase from the beginning of the line up to and including
    # the current cursor position.
    # @api public
    def clear_line_before
      CSI + '1K'
    end

    # Erase from the current position (inclusive) to
    # the end of the line
    # @api public
    def clear_line_after
      CSI + '0K'
    end

    # Clear a number of lines
    #
    # @param [Integer] n
    #   the number of lines to clear
    # @param [Symbol] :direction
    #   the direction to clear, default :up
    #
    # @api public
    def clear_lines(n, direction = :up)
      n.times.reduce([]) do |acc, i|
        dir = direction == :up ? up : down
        acc << clear_line + ((i == n - 1) ? '' : dir)
      end.join
    end
    alias clear_rows clear_lines

    # Clear screen down from current position
    # @api public
    def clear_screen_down
      CSI + 'J'
    end

    # Clear screen up from current position
    # @api public
    def clear_screen_up
      CSI + '1J'
    end

    # Clear the screen with the background colour and moves the cursor to home
    # @api public
    def clear_screen
      CSI + '2J'
    end

    # Scroll display up one line
    # @api public
    def scroll_up
      ESC + 'M'
    end

    # Scroll display down one line
    # @api public
    def scroll_down
      ESC + 'D'
    end
  end # Cursor
end # TTY