make_menu 0.0.5 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/make_menu/menu.rb +8 -12
- data/lib/make_menu/version.rb +1 -1
- data/lib/make_menu.rb +11 -13
- data/make_menu.gemspec +1 -1
- metadata +2 -3
- data/lib/make_menu/status_panel.rb +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1e6fc0d7ef57702a6b3921de109c4107cbfd91ae82ad2c3b6c4bb4d965336ce
|
4
|
+
data.tar.gz: ac58b2cbc0b2b6e01451598194494a924e707ee8c0e29b6462961f8f1a51b3eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a41d2f31a4f67d4dae2b62252fa4a4ac81b60561d72f780f5b2718fa1ba98ba6c3b716323e4e3e25ed7e2ad93b755f3f4403fa86265b0c9c849bf93f52f1fe1
|
7
|
+
data.tar.gz: 1a0cabf2eefb7b9d9c8f03dc11c6dc730a4db17ade1e4e20c2e0937c91139b6e37846bec0058f994b6b1053047d22ecbf7ef466859daf674330cc074e5912f7f
|
data/Gemfile.lock
CHANGED
data/lib/make_menu/menu.rb
CHANGED
@@ -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
|
-
#
|
168
|
+
# Clear screen before and after each command
|
173
169
|
def clear_screen?
|
174
170
|
true
|
175
171
|
end
|
data/lib/make_menu/version.rb
CHANGED
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
|
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
|
data/make_menu.gemspec
CHANGED
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Barri Mason
|
@@ -37,12 +37,11 @@ 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
|
44
43
|
- make_menu.gemspec
|
45
|
-
homepage: https://
|
44
|
+
homepage: https://github.com/MisterGrimalkin/make_menu
|
46
45
|
licenses:
|
47
46
|
- MIT
|
48
47
|
metadata: {}
|
@@ -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
|