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

- old
+ new

@@ -18,11 +18,12 @@ @items = [] @options = { group_title_color: :underline, clear_screen: true, - pause_on_success: false + pause_on_success: false, + badges_first: true } @highlights = {} @header = nil @field_set = nil @@ -38,13 +39,19 @@ loop do system 'clear' if clear_screen? display_header - display_badges - display_fields + if badges_first? + display_badges + display_fields + else + display_fields + display_badges + end + puts colorize(MakeMenu::Text::Table.new(groups).to_s) puts puts 'Press ESC to quit'.align(:center).bold puts @@ -91,24 +98,24 @@ 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 + def add_field(label = '', value_from_file: nil, color: :normal, none: '[none]'.dark, &block) + fields.add label, value_from_file: value_from_file, color: color, none: none, &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 + def add_badge(label = '', &block) + badges.add label, &block end def badges @badge_set ||= BadgeSet.new end @@ -145,9 +152,13 @@ options[:clear_screen] end def pause_on_success? options[:pause_on_success] + end + + def badges_first? + options[:badges_first] end def colorize(text) highlights.each do |word, color| case color