Sha256: ceca642f6d4ba0fad9234bbce09ad64706a9a221e43dc2c056e6f6d8aad79bad
Contents?: true
Size: 1.28 KB
Versions: 3
Compression:
Stored size: 1.28 KB
Contents
module MotionProvisioning module Utils module_function def log(what, msg) require 'thread' @print_mutex ||= Mutex.new # Because this method can be called concurrently, we don't want to mess any output. @print_mutex.synchronize do $stderr.puts(what(what) + ' ' + msg) end end def ask(what, question) what = "\e[1m" + what.rjust(10) + "\e[0m" # bold $stderr.print(what(what) + ' ' + question + ' ') $stderr.flush result = $stdin.gets result.chomp! if result result end def ask_password(what, question) require 'io/console' # needed for noecho # Save current buffering mode buffering = $stderr.sync # Turn off buffering $stderr.sync = true `stty -icanon` begin $stderr.print(what(what) + ' ' + question + ' ') $stderr.flush pw = "" $stderr.noecho do while ( char = $stdin.getc ) != "\n" # break after [Enter] putc "*" pw << char end end ensure print "\n" end # Restore original buffering mode $stderr.sync = buffering `stty -icanon` pw end def what(what) "\e[1m" + what.rjust(10) + "\e[0m" # bold end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
motion-provisioning-0.0.3 | lib/motion-provisioning/utils.rb |
motion-provisioning-0.0.2 | lib/motion-provisioning/utils.rb |
motion-provisioning-0.0.1 | lib/motion-provisioning/utils.rb |