Sha256: d4623858a245bd60db02a0d575169d071989ff99eadb72b1508c8a711c13aca4

Contents?: true

Size: 646 Bytes

Versions: 41

Compression:

Stored size: 646 Bytes

Contents

# frozen_string_literal: true

module Doing
  # STDOUT and STDERR methods
  module PromptSTD
    ##
    ## Clear the terminal screen
    ##
    def clear_screen(msg = nil)
      puts "\e[H\e[2J" if $stdout.tty?
      puts msg if msg.good?
    end

    ##
    ## Redirect STDOUT and STDERR to /dev/null or file
    ##
    ## @param      file  [String] a file path to redirect to
    ##
    def silence_std(file = '/dev/null')
      $stdout = File.new(file, 'w')
      $stderr = File.new(file, 'w')
    end

    ##
    ## Restore silenced STDOUT and STDERR
    ##
    def restore_std
      $stdout = STDOUT
      $stderr = STDERR
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
doing-2.1.41 lib/doing/prompt/std.rb