Class: VMC::Cli::Command::FileWithPercentOutput

Inherits:
File
  • Object
show all
Defined in:
lib/cli/commands/apps.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.display_strObject

Returns the value of attribute display_str.



911
912
913
# File 'lib/cli/commands/apps.rb', line 911

def display_str
  @display_str
end

.upload_sizeObject

Returns the value of attribute upload_size.



911
912
913
# File 'lib/cli/commands/apps.rb', line 911

def upload_size
  @upload_size
end

Instance Method Details

#read(*args) ⇒ Object



925
926
927
928
929
930
931
932
933
934
935
936
937
# File 'lib/cli/commands/apps.rb', line 925

def read(*args)
  result  = super(*args)
  if result && result.size > 0
    update_display(result.size)
  else
    unless VMC::Cli::Config.output.nil? || !STDOUT.tty?
      clear(FileWithPercentOutput.display_str.size + 5)
      VMC::Cli::Config.output.print(FileWithPercentOutput.display_str)
      display('OK'.green)
    end
  end
  result
end

#update_display(rsize) ⇒ Object



914
915
916
917
918
919
920
921
922
923
# File 'lib/cli/commands/apps.rb', line 914

def update_display(rsize)
  @read ||= 0
  @read += rsize
  p = (@read * 100 / FileWithPercentOutput.upload_size).to_i
  unless VMC::Cli::Config.output.nil? || !STDOUT.tty?
    clear(FileWithPercentOutput.display_str.size + 5)
    VMC::Cli::Config.output.print("#{FileWithPercentOutput.display_str} #{p}%")
    VMC::Cli::Config.output.flush
  end
end