make_menu 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/Gemfile.lock +5 -1
- data/lib/make_menu/menu.rb +23 -16
- data/lib/make_menu/version.rb +1 -1
- data/lib/make_menu.rb +11 -13
- data/make_menu.gemspec +1 -40
- metadata +3 -44
- 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: 032edeb7018b672422a335bdcda50129603efe7f9fd6fda7ec2411d12c029e4c
|
4
|
+
data.tar.gz: 0c2481bfc18b982e5d834d81ebb7c1a1388ef2e6086121044badcf01be38c4b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 870f6926e1c56c1731a3cf5de5814aeb8885aaeb82446359f9405522230c42395da5c9e61d11f5f776349b0e42453e6b4df7981e1c48d1284d0301292ef747bf
|
7
|
+
data.tar.gz: 52c3cb4ab593115ff1274cdb4996a3c7ab2ebfab89db344d4be7922a0cc3de6efb255d18695cac180037bee994e3668e766aafb5ccd99c708023260d700b73ff
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
make_menu (0.0
|
4
|
+
make_menu (0.1.0)
|
5
|
+
tty-screen (~> 0.8.2)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: http://rubygems.org/
|
8
9
|
specs:
|
10
|
+
bump (0.10.0)
|
11
|
+
tty-screen (0.8.2)
|
9
12
|
|
10
13
|
PLATFORMS
|
11
14
|
arm64-darwin-21
|
12
15
|
|
13
16
|
DEPENDENCIES
|
17
|
+
bump
|
14
18
|
make_menu!
|
15
19
|
|
16
20
|
BUNDLED WITH
|
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,14 +73,8 @@ 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
|
-
current_group = MenuItemGroup.new
|
77
|
+
current_group = MenuItemGroup.new('Commands'.color(group_title_color))
|
87
78
|
groups << current_group
|
88
79
|
end
|
89
80
|
|
@@ -94,7 +85,25 @@ module MakeMenu
|
|
94
85
|
option_number += 1
|
95
86
|
end
|
96
87
|
end
|
88
|
+
|
89
|
+
if option_number == 1
|
90
|
+
puts
|
91
|
+
puts 'No annotated targets found!'.red.bold
|
92
|
+
puts
|
93
|
+
puts 'Expecting something like this....'
|
94
|
+
puts " #{'my_target:'.cyan} #{'## Do some things'.yellow}"
|
95
|
+
puts
|
96
|
+
exit 1
|
97
|
+
end
|
97
98
|
end
|
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
|
98
107
|
end
|
99
108
|
|
100
109
|
# rubocop:enable Metrics/MethodLength
|
@@ -144,21 +153,19 @@ module MakeMenu
|
|
144
153
|
|
145
154
|
# Get the menu logo from the LOGO constant
|
146
155
|
def logo
|
147
|
-
return "\n#{
|
156
|
+
return "\n#{" #{Dir.pwd.split('/').last} ".light_yellow_bg.black.bold}\n \n" unless Object.const_defined?("#{self.class.name}::LOGO")
|
148
157
|
|
149
158
|
Object.const_get("#{self.class.name}::LOGO")
|
150
159
|
end
|
151
160
|
|
152
161
|
protected
|
153
162
|
|
154
|
-
#
|
155
|
-
|
156
|
-
# @return [Symbol] Color for group title
|
163
|
+
# @return [Symbol,Array[Symbol]] Color for group title
|
157
164
|
def group_title_color
|
158
|
-
|
165
|
+
%i[yellow bold]
|
159
166
|
end
|
160
167
|
|
161
|
-
#
|
168
|
+
# Clear screen before and after each command
|
162
169
|
def clear_screen?
|
163
170
|
true
|
164
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
|
22
|
-
rescue LoadError => _e
|
23
|
-
puts "ERROR! Expected file ./#{menu_name.downcase}_menu.rb to define class #{menu_name.capitalize}Menu < MakeMenu::Menu"
|
24
|
-
end
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
puts "
|
22
|
+
rescue LoadError, NameError => _e
|
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
|
35
33
|
end
|
36
34
|
end
|
data/make_menu.gemspec
CHANGED
@@ -16,44 +16,5 @@ Gem::Specification.new do |s|
|
|
16
16
|
"https://rubygems.org/gems/make_menu"
|
17
17
|
s.license = "MIT"
|
18
18
|
s.add_dependency 'tty-screen', '~> 0.8.2'
|
19
|
-
s.description =
|
20
|
-
Creates a number-selection menu from a Makefile. The menu will attempt to fill the width of the terminal window.
|
21
|
-
|
22
|
-
- Any targets in the Makefile with a double-hash comment will be displayed, e.g.:
|
23
|
-
serve: ## Start Rails server in background
|
24
|
-
This will display a line such as '1. Start Rails server in background' which runs the command `make serve`.
|
25
|
-
|
26
|
-
- A line that starts with a triple-hash will create a new menu group, e.g.:
|
27
|
-
### Docker Commands
|
28
|
-
This will begin a new group with the header 'Docker Commands'
|
29
|
-
|
30
|
-
- The environment variable MENU can be used to specify a custom menu class, e.g.:
|
31
|
-
export MENU=Accounts
|
32
|
-
This assumes that a class `AccountsMenu` is defined in the file `accounts_menu.rb`
|
33
|
-
|
34
|
-
You can define two constants in your custom class:
|
35
|
-
LOGO (String) text or ASCII art to display above the menu
|
36
|
-
HIGHLIGHTS (Hash{String=>[Symbol,Array<Symbol>]}) Add coloring to specific words or phrases
|
37
|
-
|
38
|
-
- The environment variable MAKEFILE can specify a Makefile. The default is './Makefile'.
|
39
|
-
|
40
|
-
The menu will not display any targets called 'menu' or 'status'. The latter, if present, is called each
|
41
|
-
time the menu displays.
|
42
|
-
|
43
|
-
-----------------------------
|
44
|
-
Docker Container Status Panel
|
45
|
-
-----------------------------
|
46
|
-
|
47
|
-
Displays a color-coded panel indicating whether or not a Docker container is running.
|
48
|
-
|
49
|
-
You must define a custom class inheriting from `MakeMenu::StatusPanel` and indicate this using
|
50
|
-
the environment variable MENU, e.g.:
|
51
|
-
export MENU=Accounts
|
52
|
-
This assumes that a class `AccountsStatusPanel` is defined in the file `accounts_status_panel.rb`
|
53
|
-
|
54
|
-
You can define a constant CONTAINERS {String=>String} in this custom class to map the displayed
|
55
|
-
label to the container name, e.g.:
|
56
|
-
CONTAINERS = { 'Backend' => 'myapp-backend-1' }
|
57
|
-
|
58
|
-
)
|
19
|
+
s.description = ""
|
59
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: make_menu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Barri Mason
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-screen
|
@@ -24,46 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.8.2
|
27
|
-
description:
|
28
|
-
|
29
|
-
Creates a number-selection menu from a Makefile. The menu will attempt to fill the width of the terminal window.
|
30
|
-
|
31
|
-
- Any targets in the Makefile with a double-hash comment will be displayed, e.g.:
|
32
|
-
serve: ## Start Rails server in background
|
33
|
-
This will display a line such as '1. Start Rails server in background' which runs the command `make serve`.
|
34
|
-
|
35
|
-
- A line that starts with a triple-hash will create a new menu group, e.g.:
|
36
|
-
### Docker Commands
|
37
|
-
This will begin a new group with the header 'Docker Commands'
|
38
|
-
|
39
|
-
- The environment variable MENU can be used to specify a custom menu class, e.g.:
|
40
|
-
export MENU=Accounts
|
41
|
-
This assumes that a class `AccountsMenu` is defined in the file `accounts_menu.rb`
|
42
|
-
|
43
|
-
You can define two constants in your custom class:
|
44
|
-
LOGO (String) text or ASCII art to display above the menu
|
45
|
-
HIGHLIGHTS (Hash{String=>[Symbol,Array<Symbol>]}) Add coloring to specific words or phrases
|
46
|
-
|
47
|
-
- The environment variable MAKEFILE can specify a Makefile. The default is './Makefile'.
|
48
|
-
|
49
|
-
The menu will not display any targets called 'menu' or 'status'. The latter, if present, is called each
|
50
|
-
time the menu displays.
|
51
|
-
|
52
|
-
-----------------------------
|
53
|
-
Docker Container Status Panel
|
54
|
-
-----------------------------
|
55
|
-
|
56
|
-
Displays a color-coded panel indicating whether or not a Docker container is running.
|
57
|
-
|
58
|
-
You must define a custom class inheriting from `MakeMenu::StatusPanel` and indicate this using
|
59
|
-
the environment variable MENU, e.g.:
|
60
|
-
export MENU=Accounts
|
61
|
-
This assumes that a class `AccountsStatusPanel` is defined in the file `accounts_status_panel.rb`
|
62
|
-
|
63
|
-
You can define a constant CONTAINERS {String=>String} in this custom class to map the displayed
|
64
|
-
label to the container name, e.g.:
|
65
|
-
CONTAINERS = { 'Backend' => 'myapp-backend-1' }
|
66
|
-
|
27
|
+
description: ''
|
67
28
|
email: loki@amarantha.net
|
68
29
|
executables: []
|
69
30
|
extensions: []
|
@@ -76,7 +37,6 @@ files:
|
|
76
37
|
- lib/make_menu/menu.rb
|
77
38
|
- lib/make_menu/menu_item.rb
|
78
39
|
- lib/make_menu/menu_item_group.rb
|
79
|
-
- lib/make_menu/status_panel.rb
|
80
40
|
- lib/make_menu/text_column.rb
|
81
41
|
- lib/make_menu/text_table.rb
|
82
42
|
- lib/make_menu/version.rb
|
@@ -105,4 +65,3 @@ signing_key:
|
|
105
65
|
specification_version: 4
|
106
66
|
summary: Generates an interactive menu from a Makefile
|
107
67
|
test_files: []
|
108
|
-
...
|
@@ -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
|