Module: Doing::PromptSTD

Included in:
Prompt
Defined in:
lib/doing/prompt/std.rb

Overview

STDOUT and STDERR methods

Instance Method Summary collapse

Instance Method Details

#clear_screen(msg = nil) ⇒ Object

Clear the terminal screen



9
10
11
12
# File 'lib/doing/prompt/std.rb', line 9

def clear_screen(msg = nil)
  puts "\e[H\e[2J" if $stdout.tty?
  puts msg if msg.good?
end

#restore_stdObject

Restore silenced STDOUT and STDERR



27
28
29
30
# File 'lib/doing/prompt/std.rb', line 27

def restore_std
  $stdout = STDOUT
  $stderr = STDERR
end

#silence_std(file = '/dev/null') ⇒ Object

Redirect STDOUT and STDERR to /dev/null or file

Parameters:

  • file (String) (defaults to: '/dev/null')

    a file path to redirect to



19
20
21
22
# File 'lib/doing/prompt/std.rb', line 19

def silence_std(file = '/dev/null')
  $stdout = File.new(file, 'w')
  $stderr = File.new(file, 'w')
end