Class: Terminal

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/prompts/terminal.rb

Overview

Simple User Prompts

Instance Method Summary collapse

Constructor Details

#initializeTerminal

Returns a new instance of Terminal.



7
8
9
10
11
# 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

Instance Method Details

#amazing_update(_title = 'Connecting') ⇒ Object

rubocop:disable Lint/UselessAssignment



52
53
54
55
56
57
58
59
60
# 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') ⇒ Object

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

Example: Terminal.new.progress(‘Downloading’)



34
35
36
37
38
39
40
# 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') ⇒ Object

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…’)



20
21
22
23
24
25
26
# 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') ⇒ Object

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



43
44
45
46
47
48
49
# 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_factorObject

rubocop:disable Lint/AmbiguousRegexpLiteral



64
65
66
67
68
# 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