make_menu 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65183bccb23144d7c413ce5d010e5226e368922de246e83397964025e6a5c063
4
- data.tar.gz: '0960af7c003da69e8e1ada2b18021ec50772a7661204939201a664c33cd67669'
3
+ metadata.gz: 032edeb7018b672422a335bdcda50129603efe7f9fd6fda7ec2411d12c029e4c
4
+ data.tar.gz: 0c2481bfc18b982e5d834d81ebb7c1a1388ef2e6086121044badcf01be38c4b8
5
5
  SHA512:
6
- metadata.gz: ad13806ee0806d253bcc8435aa23e1ea5b1942e865e871270991ec7ae56da9d3ae77b0785dbb4e053c270ceb668f8baaa26d10a5799d6dc6a849c4ffd21183a2
7
- data.tar.gz: 77478754c06435ddcf96e1dbf495c47260166606f0fbcf35f8f00403e37792e22ede5f37668b978951f205eb8b11ef5ea6a398d4d933909c2f3cdcb2ddbcb14f
6
+ metadata.gz: 870f6926e1c56c1731a3cf5de5814aeb8885aaeb82446359f9405522230c42395da5c9e61d11f5f776349b0e42453e6b4df7981e1c48d1284d0301292ef747bf
7
+ data.tar.gz: 52c3cb4ab593115ff1274cdb4996a3c7ab2ebfab89db344d4be7922a0cc3de6efb255d18695cac180037bee994e3668e766aafb5ccd99c708023260d700b73ff
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- make_menu (0.0.5)
4
+ make_menu (0.1.0)
5
5
  tty-screen (~> 0.8.2)
6
6
 
7
7
  GEM
@@ -12,12 +12,10 @@ module MakeMenu
12
12
  def initialize(makefile)
13
13
  @groups = []
14
14
  @items = []
15
- @status_present = false
16
15
  build makefile
17
16
  end
18
17
 
19
18
  attr_reader :groups, :items
20
- attr_accessor :status_present
21
19
 
22
20
  # Display menu and prompt for command
23
21
  # rubocop:disable Metrics/MethodLength
@@ -48,7 +46,6 @@ module MakeMenu
48
46
  # Display the company logo and the status bar (if set)
49
47
  def display_header
50
48
  puts formatted_logo if logo
51
- puts `make status` if status_present
52
49
  end
53
50
 
54
51
  private
@@ -76,12 +73,6 @@ module MakeMenu
76
73
  # Target 'menu' should not appear
77
74
  next if target == 'menu'
78
75
 
79
- # Target 'status' should not appear, but is run automatically when the menu is rendered
80
- if target == 'status'
81
- self.status_present = true
82
- next
83
- end
84
-
85
76
  unless current_group
86
77
  current_group = MenuItemGroup.new('Commands'.color(group_title_color))
87
78
  groups << current_group
@@ -106,6 +97,13 @@ module MakeMenu
106
97
  end
107
98
  end
108
99
 
100
+ rescue Errno::ENOENT => _e
101
+ puts
102
+ puts 'No Makefile!'.red.bold
103
+ puts
104
+ puts "File '#{makefile}' could not be found.".yellow
105
+ puts
106
+ exit 1
109
107
  end
110
108
 
111
109
  # rubocop:enable Metrics/MethodLength
@@ -162,14 +160,12 @@ module MakeMenu
162
160
 
163
161
  protected
164
162
 
165
- # Override the following methods to customise the menu display
166
-
167
163
  # @return [Symbol,Array[Symbol]] Color for group title
168
164
  def group_title_color
169
165
  %i[yellow bold]
170
166
  end
171
167
 
172
- # Clean screen before and after each command
168
+ # Clear screen before and after each command
173
169
  def clear_screen?
174
170
  true
175
171
  end
@@ -1,3 +1,3 @@
1
1
  module MakeMenu
2
- VERSION = '0.0.5'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/make_menu.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require_relative 'make_menu/color_string'
2
2
  require_relative 'make_menu/menu'
3
- require_relative 'make_menu/status_panel'
4
3
 
5
4
  require 'tty-screen'
6
5
 
@@ -19,18 +18,17 @@ module MakeMenu
19
18
  else
20
19
  MakeMenu::Menu.new(makefile).run
21
20
  end
21
+
22
22
  rescue LoadError, NameError => _e
23
- puts "ERROR! Expected file ./#{menu_name.downcase}_menu.rb to define class #{menu_name.capitalize}Menu < MakeMenu::Menu".red
23
+ puts
24
+ puts 'No customisation class found!'.red.bold
25
+ puts
26
+ puts 'Expected file:'
27
+ puts " ./#{menu_name.downcase}_menu.rb".cyan
28
+ puts
29
+ puts 'To define class:'
30
+ puts " #{menu_name.capitalize}Menu < MakeMenu::Menu".yellow
31
+ puts
32
+ exit 1
24
33
  end
25
-
26
- # def self.status
27
- # if (menu_name = ENV.fetch('MENU', nil))
28
- # require "./#{menu_name.downcase}_status_panel.rb"
29
- # Object.const_get("#{menu_name.capitalize}StatusPanel").new.display
30
- # else
31
- # MakeMenu::StatusPanel.new.display
32
- # end
33
- # rescue LoadError => _e
34
- # puts "ERROR! Expected file ./#{menu_name.downcase}_status_panel.rb to define class #{menu_name.capitalize}StatusPanel < MakeMenu::StatusPanel".red
35
- # end
36
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: make_menu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barri Mason
@@ -37,7 +37,6 @@ files:
37
37
  - lib/make_menu/menu.rb
38
38
  - lib/make_menu/menu_item.rb
39
39
  - lib/make_menu/menu_item_group.rb
40
- - lib/make_menu/status_panel.rb
41
40
  - lib/make_menu/text_column.rb
42
41
  - lib/make_menu/text_table.rb
43
42
  - lib/make_menu/version.rb
@@ -1,113 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'color_string'
4
- require 'readline'
5
-
6
- module MakeMenu
7
- # A panel above the menu displaying the status of Docker containers.
8
- # The mapping of TextLabel => ContainerName must be defined in a constant called CONTAINERS
9
- class StatusPanel
10
- String.include(ColorString)
11
-
12
- # Print panel
13
- def display
14
- return if containers.empty?
15
-
16
- puts "\n#{panel}"
17
- end
18
-
19
- protected
20
-
21
- # Return a hash mapping label to container name
22
- # This is assumed to be provided as a constant called CONTAINERS
23
- # @return [Hash{String=>String}]
24
- def containers
25
- Object.const_get "#{self.class.name}::CONTAINERS"
26
- rescue NameError
27
- {}
28
- end
29
-
30
- # Override this to change the colors for running / not running
31
- def colors_if_running
32
- {
33
- true => %i[green_bg bold white],
34
- false => %i[red_bg bold dark]
35
- }.freeze
36
- end
37
-
38
- # Override this to limit each row to a maximum number of labels
39
- def max_labels_per_line
40
- containers.size
41
- end
42
-
43
- private
44
-
45
- # @return [String] Text representation of the panel
46
- # rubocop:disable Metrics/MethodLength
47
- def panel
48
- return @panel if @panel
49
-
50
- return "- Docker offline -\n".grey.dark.align(:center) unless docker_online?
51
-
52
- @panel = ''
53
- labels_on_this_line = 0
54
- line_buffer = ''
55
-
56
- containers.each do |label, container|
57
- if (labels_on_this_line + 1) > labels_per_line
58
- @panel += "#{left_indent(labels_on_this_line)}#{line_buffer}\n\n"
59
- labels_on_this_line = 0
60
- line_buffer = ''
61
- end
62
-
63
- text = label.align(:center, width: max_label_width, pad_right: true)
64
- .color(colors_if_running[running?(container)])
65
-
66
- line_buffer += " #{text} "
67
-
68
- labels_on_this_line += 1
69
- end
70
-
71
- @panel += "#{left_indent(labels_on_this_line)}#{line_buffer}\n\n"
72
- end
73
- # rubocop:enable Metrics/MethodLength
74
-
75
- def docker_online?
76
- system 'docker', 'compose', 'ps', out: File::NULL, err: File::NULL
77
- end
78
-
79
- # @return [String] List of Docker containers and information
80
- def docker_ps
81
- @docker_ps ||= `docker compose ps`
82
- end
83
-
84
- # @return [Boolean] whether specified container is running
85
- def running?(container)
86
- docker_ps.include? container
87
- end
88
-
89
- # Return the left indent for this line of labels
90
- # @param [Integer] number_of_labels Number of labels on this line
91
- # @return [String]
92
- def left_indent(number_of_labels)
93
- spaces = (::TTY::Screen.cols - (number_of_labels * (max_label_width + 2))) / 2
94
- spaces = [spaces, 0].max
95
- ' ' * spaces
96
- end
97
-
98
- # @return [Integer] Maximum label width, with padding
99
- def max_label_width
100
- @max_label_width ||= containers.map do |label, _container|
101
- label.length
102
- end.max + 2
103
- end
104
-
105
- # @return [Integer] Number of labels that can fit on one line
106
- def labels_per_line
107
- @labels_per_line ||= [
108
- (::TTY::Screen.cols / max_label_width) - 1,
109
- max_labels_per_line
110
- ].min
111
- end
112
- end
113
- end