d968e17823
1. Added a method to ask for the default mode (TUI, GUI, or WebApp) during the first run setup. 2. Implemented a method to validate the input mode. 3. Improved the database connection test method to handle exceptions and return a boolean value. 4. Added a method to ask for database details (username, password, and database name). 5. Enhanced the user interface by adding Curses.clear before each question to make the interface cleaner. 6. Improved the password input process by disabling echo to hide the input from the screen. 7. Added validation for uplink and downlink speeds. 8. Added a method to ask for services the system should be aware of.
60 lines
1.6 KiB
Ruby
60 lines
1.6 KiB
Ruby
require 'curses'
|
|
|
|
def first_run_setup
|
|
color = ask_for_color
|
|
# TODO: Use the color for something
|
|
db_details = ask_for_db_details
|
|
while !test_db_connection(db_details)
|
|
Curses.setpos(4, 0)
|
|
Curses.addstr("Whoops! We couldn't connect to the database with the details you provided. Please try again!")
|
|
Curses.refresh
|
|
db_details = ask_for_db_details
|
|
end
|
|
uplink_speed = ask_for_uplink_speed
|
|
# TODO: Use the uplink speed for something
|
|
downlink_speed = ask_for_downlink_speed
|
|
# TODO: Use the downlink speed for something
|
|
total_bandwidth = calculate_total_bandwidth(uplink_speed, downlink_speed)
|
|
# TODO: Use the total bandwidth for something
|
|
services = ask_for_services
|
|
# TODO: Use the services for something
|
|
# ...
|
|
end
|
|
|
|
def ask_for_color
|
|
while true
|
|
Curses.clear
|
|
Curses.setpos(0, 0)
|
|
Curses.addstr("Please enter your preferred color (white, red, or black): ")
|
|
Curses.refresh
|
|
color = Curses.getstr.strip.downcase
|
|
if ['white', 'red', 'black'].include?(color)
|
|
return color
|
|
else
|
|
Curses.setpos(1, 0)
|
|
Curses.addstr("Whoops! That didn't appear to be a valid color. Please try again!")
|
|
Curses.refresh
|
|
end
|
|
end
|
|
end
|
|
|
|
def ask_for_default_mode
|
|
while true
|
|
Curses.setpos(8, 0)
|
|
Curses.addstr("Please enter the default mode (TUI, GUI, or WebApp): ")
|
|
Curses.refresh
|
|
mode = Curses.getstr.strip.downcase
|
|
if valid_mode?(mode)
|
|
return mode
|
|
else
|
|
Curses.setpos(9, 0)
|
|
Curses.addstr("Whoops! That didn't appear to be a valid mode. Please try again!")
|
|
Curses.refresh
|
|
end
|
|
end
|
|
end
|
|
|
|
def valid_mode?(mode)
|
|
['tui', 'gui', 'webapp'].include?(mode)
|
|
end
|