Module: Morale::IO

Included in:
Account, Commands::Account, Commands::Project, Commands::Ticket, CredentialsStore
Defined in:
lib/morale/io.rb

Instance Method Summary collapse

Instance Method Details

#askObject



17
18
19
20
# File 'lib/morale/io.rb', line 17

def ask
  input = $stdin.gets
  input.strip! unless input.nil?
end

#ask_for_secretObject



40
41
42
43
44
45
46
# File 'lib/morale/io.rb', line 40

def ask_for_secret
  echo_off
  secret = ask
  puts
  echo_on
  return secret
end

#ask_for_secret_on_windowsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/morale/io.rb', line 22

def ask_for_secret_on_windows
  require "Win32API"
  char = nil
  secret = ''

  while char = Win32API.new("crtdll", "_getch", [ ], "L").Call do
    break if char == 10 || char == 13 # received carriage return or newline
    if char == 127 || char == 8 # backspace and delete
      secret.slice!(-1, 1)
    else
      # windows might throw a -1 at us so make sure to handle RangeError
      (secret << char.chr) rescue RangeError
    end
  end
  puts
  return secret
end

#echo_offObject



48
49
50
# File 'lib/morale/io.rb', line 48

def echo_off
  system "stty -echo"
end

#echo_onObject



52
53
54
# File 'lib/morale/io.rb', line 52

def echo_on
  system "stty echo"
end

#say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)$/)) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/morale/io.rb', line 3

def say(message="", color=nil, force_new_line=(message.to_s !~ /( |\t)$/))
  message = message.to_s
  message = set_color(message, color) if color

  spaces = ""

  if force_new_line
    $stdout.puts(spaces + message)
  else
    $stdout.print(spaces + message)
  end
  $stdout.flush
end