-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
56 lines (49 loc) · 1019 Bytes
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
require 'tty-box'
require 'tty-prompt'
require_relative 'lib/toolbox/toolbox'
@exit_flag = false
def exit? # rubocop:disable Metrics/MethodLength
prompt = TTY::Prompt.new
options = [
{ name: 'Exit Program', value: lambda {
clear_terminal
@exit_flag = true
} },
{ name: 'Stay in program', value: -> { main } }
]
clear_terminal
puts TTY::Box.error('An error occured')
begin
prompt.select('Please select', options)
rescue TTY::Reader::InputInterrupt
exit?
rescue Interrupt
exit?
rescue StandardError
exit?
end
end
def clear_terminal
if RUBY_PLATFORM =~ /win32|win64|\.NET|windows|cygwin|mingw32/i
system('cls')
else
system('clear')
end
end
def main # rubocop:disable Metrics/MethodLength
loop do
begin
Toolbox.new
rescue TTY::Reader::InputInterrupt
exit?
rescue Interrupt
exit?
rescue StandardError
exit?
end
break if @exit_flag
end
clear_terminal
end
main