Module: Morale::IO
- Included in:
- Account, Commands::Account, Commands::Project, Commands::Ticket, CredentialsStore
- Defined in:
- lib/morale/io.rb
Instance Method Summary collapse
- #ask ⇒ Object
- #ask_for_secret ⇒ Object
- #ask_for_secret_on_windows ⇒ Object
- #echo_off ⇒ Object
- #echo_on ⇒ Object
- #say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)$/)) ⇒ Object
Instance Method Details
#ask ⇒ Object
17 18 19 20 |
# File 'lib/morale/io.rb', line 17 def ask input = $stdin.gets input.strip! unless input.nil? end |
#ask_for_secret ⇒ Object
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_windows ⇒ Object
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_off ⇒ Object
48 49 50 |
# File 'lib/morale/io.rb', line 48 def echo_off system "stty -echo" end |
#echo_on ⇒ Object
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(="", color=nil, force_new_line=(.to_s !~ /( |\t)$/)) = .to_s = set_color(, color) if color spaces = "" if force_new_line $stdout.puts(spaces + ) else $stdout.print(spaces + ) end $stdout.flush end |