bin/u-menu in u-menu-0.6.0 vs bin/u-menu in u-menu-0.8.0
- old
+ new
@@ -2,51 +2,56 @@
require_relative '../lib/u-menu'
require 'tty-prompt'
-config = Micro::Menu.configurations.load
+command = ARGV.first
-colors = Micro::Menu.colors
-prompt = TTY::Prompt.new(prefix: colors.magenta("\uea85 \u00b5menu "), interrupt: :signal)
+if command == 'init'
+ puts "\n\nCreating a simple config file at ``"
+ Micro::Menu.configurations.init
+end
+config = Micro::Menu.configurations.load
+colors = Micro::Menu.colors
icons = Micro::Menu.icons.all
+messages = Micro::Menu.messages
-thanks = [
- colors.green('Great job! o/'),
- colors.green('See you later! =)'),
- colors.green('Baby bye bye bye...'),
- "Bring me #{colors.green('a cookie')} when you come back!?",
- "Have a nice #{colors.cyan('day')}! =)",
- "See you later #{colors.green('olligator')}! =)"
-]
-
trap('INT') do
+ thanks = messages.thanks
+
puts "\n\n#{thanks.sample}"
exit(0)
end
-action = nil
-title, options = config.values_at(:title, :options)
+title, options, use_icons =
+ config.values_at(:title, :options, :use_icons)
+use_icons ||= false
+
+prompt = TTY::Prompt.new(
+ prefix: colors.magenta("#{use_icons ? "\uea85" : ''} u-menu "),
+ interrupt: :signal
+)
+
+# create a default edit settings option
options << {
- name: '{{settings}} Edit Settings',
- type: 'edit',
- value: 'settings',
- execute: config[:_path]
+ name: '{{settings}} Edit Settings', type: 'edit', value: 'settings', execute: config[:_path]
}
+
options = options.sort { |a, b| a[:name] <=> b[:name] }
options.each do |option|
if option[:name].match(/\{\{(?<icon_name>.*)\}\}/)
icon_name = Regexp.last_match('icon_name')
- option[:name].sub!("{{#{icon_name}}}", icons[icon_name])
+ option[:name].sub!("{{#{icon_name}}} ", use_icons ? icons[icon_name] : '')
else
- option[:name] = "#{icons['terminal']} #{option[:name]}" if option[:type] == 'command'
- option[:name] = "#{icons['link']} #{option[:name]}" if option[:type] == 'link'
+ option[:name] = "#{use_icons ? icons['terminal'] : ''} #{option[:name]}" if option[:type] == 'command'
+ option[:name] = "#{use_icons ? icons['link'] : ''} #{option[:name]}" if option[:type] == 'link'
end
end
+action = nil
loop do
choice = prompt.select(title, options, filter: true)
action = config[:options].find { |item| item[:value] == choice }
case action[:type]