# frozen_string_literal: true # ========================================================== # adn/tools/bkps/lib/menu.rb — Menú TUI interactivo # Migrado desde dtic-BKPs v6.0 → ADN::BKPs # ========================================================== module ADN module BKPs class Menu def initialize(config, dispatcher, log) @config = config @dispatcher = dispatcher @log = log end def ejecutar loop do system('clear') || system('cls') mostrar_encabezado opciones = construir_opciones opciones.each { |op| puts op[:linea] } puts "#{Color::CYAN}────────────────────────#{Color::RESET}" print "\n#{Color::YELLOW}Selecciona > #{Color::RESET}" $stdout.flush entrada = $stdin.gets&.chomp&.strip&.upcase next if entrada.nil? || entrada.empty? op = opciones.find { |o| o[:id] == entrada } unless op @log.error("Opción no válida: #{entrada}") sleep 1 next end case op[:tipo] when :tarea @dispatcher.ejecutar_tarea(op[:config]) when :comando @dispatcher.ejecutar_comando(op[:config]) when :salir puts "Saliendo..." return end unless op[:tipo] == :salir || @config.auto_avanzar print "\nPresiona Enter para continuar..." $stdin.gets end end end private def mostrar_encabezado puts "#{Color::BOLD}#{Color::CYAN}╔══════════════════════════════════════════╗#{Color::RESET}" puts "#{Color::BOLD}#{Color::CYAN}║ dtic-BKPs — ADN Backups Manager ║#{Color::RESET}" puts "#{Color::BOLD}#{Color::CYAN}╚══════════════════════════════════════════╝#{Color::RESET}" end def construir_opciones opciones = [] puts "\n#{Color::BOLD}Tareas Individuales:#{Color::RESET}" @config.tareas.each_with_index do |t, i| id = "T#{i + 1}" opciones << { id: id, tipo: :tarea, config: t, linea: " #{Color::YELLOW}#{id}.#{Color::RESET} #{t[:texto]}" } end puts "\n#{Color::BOLD}Comandos (Secuencias):#{Color::RESET}" @config.comandos.each_with_index do |c, i| id = "C#{i + 1}" opciones << { id: id, tipo: :comando, config: c, linea: " #{Color::YELLOW}#{id}.#{Color::RESET} #{c[:texto]}" } end puts "\n#{Color::CYAN}────────────────────────#{Color::RESET}" opciones << { id: 'S', tipo: :salir, linea: " #{Color::YELLOW}S.#{Color::RESET} Salir" } opciones.select { |op| op[:tipo] == :salir }.each { |op| puts op[:linea] } opciones end end end end