lib/make_menu/menu.rb in make_menu-1.0.0 vs lib/make_menu/menu.rb in make_menu-1.1.0

- old
+ new

@@ -1,8 +1,10 @@ # frozen_string_literal: true require_relative 'builder' +require_relative 'badge_set' +require_relative 'field_set' require_relative 'menu_item_group' require_relative 'text/table' require_relative 'console/prompter' module MakeMenu @@ -19,11 +21,14 @@ group_title_color: :underline, clear_screen: true, pause_on_success: false } @highlights = {} + @header = nil + @field_set = nil + @badge_set = nil end attr_reader :makefile, :groups, :items, :options, :highlights def run @@ -33,10 +38,12 @@ loop do system 'clear' if clear_screen? display_header + display_badges + display_fields puts colorize(MakeMenu::Text::Table.new(groups).to_s) puts puts 'Press ESC to quit'.align(:center).bold puts @@ -71,30 +78,54 @@ gets end end end + def header(&block) + @header = block + end + def display_header if @header @header.call else logo = " #{Dir.pwd.split('/').last.upcase} ".invert.bold.to_s puts "\n#{logo.align(:center)}\n \n" end end + def add_field(field, &block) + fields.add field, &block + end + + def fields + @field_set ||= FieldSet.new + end + + def display_fields + @field_set.display if @field_set + end + + def add_badge(label = '', on: ' ON '.green_bg.bold, off: ' OFF '.red_bg.dark, &block) + badges.add label, on: on, off: off, &block + end + + def badges + @badge_set ||= BadgeSet.new + end + + def display_badges + @badge_set.display if @badge_set + end + def options @options.merge!(yield) if block_given? @options end def highlights @highlights.merge!(yield) if block_given? @highlights - end - - def header(&block) - @header = block end def add_group(group) groups << group group