5b76cd117e
This commit marks a significant milestone in the NETRAVE project. The first major system has been successfully completed, laying a solid foundation for the subsequent development phases. Key changes include: 1. Completion of the Initial Setup Process: The initial setup process has been successfully implemented. This process gathers necessary information from the user and sets up the basic environment for the application to run. 2. Removal of Redundant Thread in Alert System: An unnecessary thread in the alert system was identified and removed. This change simplifies the alert system's architecture and reduces the potential for concurrency-related issues. 3. Program Efficiency Improvements: Several optimizations have been made to enhance the efficiency of the program. These include changes to the way alerts are handled and displayed, as well as improvements to the handling of the alert queue. These changes have been verified and tested to ensure they work as expected and contribute to the overall functionality and performance of the NETRAVE project.
50 lines
1.6 KiB
Ruby
50 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Class for creating and displaying alerts in the Curses TUI. This class also manages a little bit of concurrency
|
|
# We use mutex for sync so we don't break Curses, as Curses isn't thread safe
|
|
class Alert
|
|
attr_reader :message, :severity, :alert_window
|
|
|
|
def initialize(message, severity)
|
|
@message = message
|
|
@severity = severity
|
|
@curses_mutex = Mutex.new
|
|
end
|
|
|
|
def display # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
@curses_mutex.synchronize do
|
|
# Initialize color pairs
|
|
Curses.start_color
|
|
Curses.init_pair(1, Curses::COLOR_BLUE, Curses::COLOR_BLACK) # Info
|
|
Curses.init_pair(2, Curses::COLOR_RED, Curses::COLOR_BLACK) # Error
|
|
Curses.init_pair(3, Curses::COLOR_YELLOW, Curses::COLOR_BLACK) # Warning
|
|
|
|
# Create a new window for the alert at the bottom of the screen
|
|
@alert_window = Curses::Window.new(1, Curses.cols, Curses.lines - 1, 0)
|
|
|
|
# Set the color attribute based on the severity of the alert
|
|
case @severity
|
|
when :info
|
|
@alert_window.attron(Curses.color_pair(1) | Curses::A_NORMAL) # Blue color
|
|
when :warning
|
|
@alert_window.attron(Curses.color_pair(3) | Curses::A_NORMAL) # Yellow color
|
|
when :error
|
|
@alert_window.attron(Curses.color_pair(2) | Curses::A_NORMAL) # Red color
|
|
end
|
|
|
|
# Add the message to the window and refresh it to display the message
|
|
@alert_window.addstr(@message)
|
|
@alert_window.refresh
|
|
end
|
|
end
|
|
|
|
def clear
|
|
@curses_mutex.synchronize do
|
|
# Clear the alert
|
|
@alert_window.clear
|
|
@alert_window.refresh
|
|
@alert_window.close
|
|
end
|
|
end
|
|
end
|