class Terminal

Simple User Prompts

Public Class Methods

new() click to toggle source
# File lib/utils/prompts/terminal.rb, line 7
def initialize
  form = "\e[0;34m%t: |%B|\e[0m"
  @pbar = ProgressBar.create(length: 80, smoothing: 0.3, format: form)
  @prompt = TTY::Prompt.new
end

Public Instance Methods

amazing_update(_title = 'Connecting') click to toggle source

rubocop:disable Lint/UselessAssignment

# File lib/utils/prompts/terminal.rb, line 52
def amazing_update(_title = 'Connecting')
  steps_message(10)
  steps_message(10, title = 'Contacting Software Sites')
  steps_message(20, title = 'Indexing jiras')
  steps_message(10, title = 'Validating Checksums')
  steps_message(30, title = 'Checking Type Safety')
  steps_message(10, title = 'Deleting Previous Work')
  steps_message(10, title = 'Installing')
end
progress(title = 'Connecting') click to toggle source

A progress bar with linear increments can be called with an overriding default title

Example: Terminal.new.progress('Downloading')

# File lib/utils/prompts/terminal.rb, line 34
def progress(title = 'Connecting')
  @pbar.title = title
  100.times do
    @pbar.increment
    sleep 0.01
  end
end
r_progress(duration, title = 'Connecting') click to toggle source

Creates a progress bar with random increments of time can be called with an overriding default title

Example: Terminal.new.r_progress(10, 'Downloading') Terminal.new.r_progress(200, 'Deleting…')

# File lib/utils/prompts/terminal.rb, line 20
def r_progress(duration, title = 'Connecting')
  @pbar.title = title
  100.times do
    @pbar.increment
    sleep 0.001 * rand(1..duration)
  end
end
steps_message(steps, title = 'Connecting') click to toggle source

Use this for the amazing_update to change titles every n number steps

# File lib/utils/prompts/terminal.rb, line 43
def steps_message(steps, title = 'Connecting')
  steps.times do
    @pbar.title = title
    @pbar.increment
    sleep 0.01 * rand(1..20)
  end
end
two_factor() click to toggle source

rubocop:disable Lint/AmbiguousRegexpLiteral

# File lib/utils/prompts/terminal.rb, line 64
def two_factor
  @prompt.mask('Please enter your VPNs 2FA PIN:') do |q|
    q.validate /^\d{6}$/, 'Must be a six digit PIN!'
  end
end