sidekiq 8.1.6 → 8.1.8

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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +18 -0
  3. data/README.md +5 -3
  4. data/bin/sidekiqload +2 -0
  5. data/lib/active_job/queue_adapters/sidekiq_adapter.rb +1 -1
  6. data/lib/sidekiq/api.rb +16 -13
  7. data/lib/sidekiq/cli.rb +5 -2
  8. data/lib/sidekiq/client.rb +3 -3
  9. data/lib/sidekiq/config.rb +26 -1
  10. data/lib/sidekiq/embedded.rb +1 -1
  11. data/lib/sidekiq/job/iterable/active_record_enumerator.rb +1 -1
  12. data/lib/sidekiq/job/iterable.rb +1 -1
  13. data/lib/sidekiq/job.rb +55 -64
  14. data/lib/sidekiq/job_logger.rb +5 -0
  15. data/lib/sidekiq/job_retry.rb +6 -6
  16. data/lib/sidekiq/job_util.rb +7 -2
  17. data/lib/sidekiq/launcher.rb +1 -1
  18. data/lib/sidekiq/metrics/query.rb +6 -1
  19. data/lib/sidekiq/metrics/shared.rb +1 -1
  20. data/lib/sidekiq/paginator.rb +3 -0
  21. data/lib/sidekiq/processor.rb +7 -4
  22. data/lib/sidekiq/redis_client_adapter.rb +5 -3
  23. data/lib/sidekiq/redis_connection.rb +18 -9
  24. data/lib/sidekiq/tui/tabs/base_tab.rb +60 -15
  25. data/lib/sidekiq/tui/tabs/busy.rb +3 -17
  26. data/lib/sidekiq/tui/tabs/dead.rb +0 -5
  27. data/lib/sidekiq/tui/tabs/home.rb +12 -41
  28. data/lib/sidekiq/tui/tabs/metrics.rb +2 -19
  29. data/lib/sidekiq/tui/tabs/queues.rb +2 -14
  30. data/lib/sidekiq/tui/tabs/retries.rb +0 -5
  31. data/lib/sidekiq/tui/tabs/scheduled.rb +0 -5
  32. data/lib/sidekiq/tui/tabs/set_tab.rb +15 -20
  33. data/lib/sidekiq/tui.rb +59 -76
  34. data/lib/sidekiq/version.rb +1 -1
  35. data/lib/sidekiq/web/action.rb +2 -2
  36. data/lib/sidekiq/web/application.rb +5 -5
  37. data/lib/sidekiq/web/helpers.rb +24 -2
  38. data/lib/sidekiq/web.rb +2 -2
  39. data/sidekiq.gemspec +3 -2
  40. data/web/assets/javascripts/application.js +1 -0
  41. data/web/locales/da.yml +34 -0
  42. data/web/locales/de.yml +29 -1
  43. data/web/locales/en.yml +1 -0
  44. data/web/locales/es.yml +2 -0
  45. data/web/locales/fr.yml +11 -0
  46. data/web/locales/hi.yml +34 -0
  47. data/web/locales/it.yml +2 -0
  48. data/web/locales/ja.yml +19 -0
  49. data/web/locales/ko.yml +42 -0
  50. data/web/locales/nb.yml +32 -0
  51. data/web/locales/nl.yml +41 -0
  52. data/web/locales/pl.yml +50 -0
  53. data/web/locales/pt-BR.yml +13 -0
  54. data/web/locales/pt.yml +42 -0
  55. data/web/locales/ru.yml +26 -0
  56. data/web/locales/sv.yml +41 -0
  57. data/web/locales/ta.yml +81 -47
  58. data/web/locales/tr.yml +9 -0
  59. data/web/locales/uk.yml +9 -0
  60. data/web/locales/ur.yml +34 -4
  61. data/web/locales/zh-CN.yml +4 -0
  62. data/web/locales/zh-TW.yml +18 -0
  63. data/web/views/_footer.html.erb +1 -1
  64. data/web/views/_job_info.html.erb +7 -7
  65. data/web/views/_nav.html.erb +3 -9
  66. data/web/views/busy.html.erb +7 -6
  67. data/web/views/dead.html.erb +1 -1
  68. data/web/views/layout.html.erb +1 -1
  69. data/web/views/metrics.html.erb +1 -1
  70. data/web/views/metrics_for_job.html.erb +1 -1
  71. data/web/views/morgue.html.erb +3 -2
  72. data/web/views/profiles.html.erb +1 -1
  73. data/web/views/queues.html.erb +1 -0
  74. data/web/views/retries.html.erb +4 -3
  75. data/web/views/scheduled.html.erb +3 -2
  76. metadata +4 -3
@@ -33,7 +33,10 @@ module Sidekiq
33
33
  symbolized_options[:timeout] ||= 3
34
34
 
35
35
  redis_config = Sidekiq::RedisClientAdapter.new(symbolized_options)
36
- ConnectionPool.new(timeout: pool_timeout, size: size) do
36
+ # Only the main Ractor can fork, and connection_pool's fork registry
37
+ # is a non-shareable constant other Ractors can't touch.
38
+ main = Ractor.current == Ractor.main
39
+ ConnectionPool.new(timeout: pool_timeout, size: size, auto_reload_after_fork: main) do
37
40
  redis_config.new_client
38
41
  end
39
42
  end
@@ -70,18 +73,12 @@ module Sidekiq
70
73
  # unable to safely dump.
71
74
  keys = options.keys - [:logger, :ssl_params, :password, :sentinel_password]
72
75
  scrubbed_options = Marshal.load(Marshal.dump(options.slice(*keys)))
73
- if scrubbed_options[:url] && (uri = URI.parse(scrubbed_options[:url])) && uri.password
74
- uri.password = redacted
75
- scrubbed_options[:url] = uri.to_s
76
- end
76
+ scrubbed_options[:url] = redact_uri(scrubbed_options[:url], redacted) if scrubbed_options[:url]
77
77
  scrubbed_options[:password] = redacted if options.key?(:password)
78
78
  scrubbed_options[:sentinel_password] = redacted if options.key?(:sentinel_password)
79
79
  scrubbed_options[:sentinels]&.each do |sentinel|
80
80
  if sentinel.is_a?(String)
81
- if (uri = URI(sentinel)) && uri.password
82
- uri.password = redacted
83
- sentinel.replace(uri.to_s)
84
- end
81
+ sentinel.replace(redact_uri(sentinel, redacted))
85
82
  elsif sentinel[:password]
86
83
  sentinel[:password] = redacted
87
84
  end
@@ -89,6 +86,18 @@ module Sidekiq
89
86
  scrubbed_options
90
87
  end
91
88
 
89
+ # Replace the password in a Redis URL. A URL which can't be parsed may
90
+ # still hold a password, so it is redacted completely rather than letting
91
+ # URI::InvalidURIError (which quotes the URL) escape.
92
+ def redact_uri(url, redacted)
93
+ uri = URI.parse(url)
94
+ return url unless uri.password
95
+ uri.password = redacted
96
+ uri.to_s
97
+ rescue URI::InvalidURIError
98
+ redacted
99
+ end
100
+
92
101
  def determine_redis_provider
93
102
  # If you have this in your environment:
94
103
  # MY_REDIS_URL=redis://hostname.example.com:1238/4
@@ -16,6 +16,25 @@ module Sidekiq
16
16
  @parent.t(*)
17
17
  end
18
18
 
19
+ # Splits the described controls into rows which fit within +width+ columns.
20
+ def control_rows(width)
21
+ rows = []
22
+ row_width = 0
23
+ controls.each do |hash|
24
+ next unless hash[:description]
25
+
26
+ # rendered as "key: description "
27
+ control_width = (hash[:display] || hash[:code]).length + t(hash[:description]).length + 4
28
+ if rows.empty? || row_width + control_width > width
29
+ rows << []
30
+ row_width = 0
31
+ end
32
+ rows.last << hash
33
+ row_width += control_width
34
+ end
35
+ rows
36
+ end
37
+
19
38
  def reset_data
20
39
  @data = {selected: [], selected_row_index: 0}
21
40
  end
@@ -140,31 +159,57 @@ module Sidekiq
140
159
 
141
160
  def render_stats_section(tui, frame, area)
142
161
  stats = @data[:stats]
143
-
144
162
  keys = ["Processed", "Failed", "Busy", "Enqueued", "Retries", "Scheduled", "Dead"]
145
- values = [
146
- stats[:processed],
147
- stats[:failed],
148
- stats[:busy],
149
- stats[:enqueued],
150
- stats[:retries],
151
- stats[:scheduled],
152
- stats[:dead]
153
- ]
154
-
155
- # Format keys and values with spacing
156
- keys_line = keys.map { |k| t(k).to_s.ljust(12) }.join(" ")
157
- values_line = values.map { |v| number_with_delimiter(v).ljust(12) }.join(" ")
163
+ values = %i[processed failed busy enqueued retries scheduled dead].map { |k| number_with_delimiter(stats[k]) }
164
+ render_kv_section(tui, frame, area, title: "Statistics", keys:, values:)
165
+ end
166
+
167
+ # Render a bordered paragraph with a line of (translated) keys over
168
+ # a line of preformatted values, each column ljust'ed to +width+.
169
+ def render_kv_section(tui, frame, area, title:, keys:, values:, width: 12)
170
+ keys_line = keys.map { |k| t(k).to_s.ljust(width) }.join(" ")
171
+ values_line = values.map { |v| v.to_s.ljust(width) }.join(" ")
158
172
 
159
173
  frame.render_widget(
160
174
  tui.paragraph(
161
175
  text: [keys_line, values_line],
162
- block: tui.block(title: "Statistics", borders: [:all])
176
+ block: tui.block(title:, borders: [:all])
163
177
  ),
164
178
  area
165
179
  )
166
180
  end
167
181
 
182
+ # Split a tab's area into the standard stats header and a fill
183
+ # area for the tab's main content.
184
+ def stats_content_split(tui, area)
185
+ tui.layout_split(
186
+ area,
187
+ direction: :vertical,
188
+ constraints: [
189
+ tui.constraint_length(4), # Stats
190
+ tui.constraint_fill(1) # Content
191
+ ]
192
+ )
193
+ end
194
+
195
+ def striped_rows(tui, rows)
196
+ rows.map.with_index { |cells, idx|
197
+ tui.table_row(
198
+ cells:,
199
+ style: idx.even? ? nil : tui.style(bg: :dark_gray)
200
+ )
201
+ }
202
+ end
203
+
204
+ def chart_y_axis(tui, y_max, num_labels: 5)
205
+ labels = (0...num_labels).map { |i| ((y_max * i) / (num_labels - 1)).round.to_s }
206
+ tui.axis(
207
+ bounds: [0.0, y_max.to_f],
208
+ labels: labels,
209
+ style: tui.style(fg: :white)
210
+ )
211
+ end
212
+
168
213
  # [thousands_separator, decimal_separator] per locale.
169
214
  # Locales not listed here use the English default [",", "."].
170
215
  NUMERIC_SEPARATORS = {
@@ -59,7 +59,7 @@ module Sidekiq
59
59
  constraints: [
60
60
  tui.constraint_length(4), # Stats
61
61
  tui.constraint_length(4), # Status
62
- tui.constraint_fill(1) # Graph
62
+ tui.constraint_fill(1) # Graph
63
63
  ]
64
64
  )
65
65
 
@@ -77,12 +77,7 @@ module Sidekiq
77
77
  tui.constraint_length(6),
78
78
  tui.constraint_length(6)
79
79
  ],
80
- rows: @data[:busy].map.with_index { |cells, idx|
81
- tui.table_row(
82
- cells:,
83
- style: idx.even? ? nil : tui.style(bg: :dark_gray)
84
- )
85
- }
80
+ rows: striped_rows(tui, @data[:busy])
86
81
  }
87
82
  end
88
83
  end
@@ -101,16 +96,7 @@ module Sidekiq
101
96
  values << format_memory(processes.total_rss)
102
97
 
103
98
  keys = %w[Processes Threads Busy Utilization RSS]
104
- keys_line = keys.map { |k| t(k).to_s.ljust(12) }.join(" ")
105
- values_line = values.map { |v| v.to_s.ljust(12) }.join(" ")
106
-
107
- frame.render_widget(
108
- tui.paragraph(
109
- text: [keys_line, values_line],
110
- block: tui.block(title: t("Status"), borders: [:all])
111
- ),
112
- area
113
- )
99
+ render_kv_section(tui, frame, area, title: t("Status"), keys:, values:)
114
100
  end
115
101
  end
116
102
  end
@@ -8,11 +8,6 @@ module Sidekiq
8
8
  include SetTab
9
9
 
10
10
  def set_class = Sidekiq::DeadSet
11
-
12
- def refresh_data
13
- refresh_data_for_stats
14
- refresh_data_for_set
15
- end
16
11
  end
17
12
  end
18
13
  end
@@ -49,7 +49,7 @@ module Sidekiq
49
49
  direction: :vertical,
50
50
  constraints: [
51
51
  tui.constraint_length(4), # Stats
52
- tui.constraint_fill(1), # Graph
52
+ tui.constraint_fill(1), # Graph
53
53
  tui.constraint_length(4) # Redis
54
54
  ]
55
55
  )
@@ -63,31 +63,16 @@ module Sidekiq
63
63
  max_value = [@data[:chart][:deltas][:processed].max, @data[:chart][:deltas][:failed].max, 1].max
64
64
  y_max = [max_value, 5].max
65
65
 
66
- processed_data = @data[:chart][:deltas][:processed].each_with_index.map { |value, idx| [idx.to_f, value.to_f] }
67
- failed_data = @data[:chart][:deltas][:failed].each_with_index.map { |value, idx| [idx.to_f, value.to_f] }
68
-
69
- datasets = [
66
+ datasets = {processed: :green, failed: :red}.map { |key, color|
67
+ data = @data[:chart][:deltas][key].each_with_index.map { |value, idx| [idx.to_f, value.to_f] }
70
68
  tui.dataset(
71
69
  name: "",
72
- data: processed_data,
73
- style: tui.style(fg: :green),
74
- marker: :dot,
75
- graph_type: :line
76
- ),
77
- tui.dataset(
78
- name: "",
79
- data: failed_data,
80
- style: tui.style(fg: :red),
70
+ data: data,
71
+ style: tui.style(fg: color),
81
72
  marker: :dot,
82
73
  graph_type: :line
83
74
  )
84
- ]
85
-
86
- num_labels = 5
87
- y_labels = (0...num_labels).map do |i|
88
- value = ((y_max * i) / (num_labels - 1)).round
89
- value.to_s
90
- end
75
+ }
91
76
 
92
77
  beacon_pulse = (Time.now.to_i % 2 == 0) ? "●" : " "
93
78
 
@@ -98,11 +83,7 @@ module Sidekiq
98
83
  labels: [],
99
84
  style: tui.style(fg: :white)
100
85
  ),
101
- y_axis: tui.axis(
102
- bounds: [0.0, y_max.to_f],
103
- labels: y_labels,
104
- style: tui.style(fg: :white)
105
- ),
86
+ y_axis: chart_y_axis(tui, y_max),
106
87
  block: tui.block(
107
88
  title: "Dashboard #{beacon_pulse}",
108
89
  borders: [:all]
@@ -119,24 +100,14 @@ module Sidekiq
119
100
 
120
101
  keys = ["Version", "Uptime", "Connected Clients", "Memory Usage", "Peak Memory"]
121
102
  values = [
122
- redis_info[:version].to_s,
103
+ redis_info[:version],
123
104
  uptime_value,
124
- redis_info[:connected_clients].to_s,
125
- redis_info[:used_memory].to_s,
126
- redis_info[:peak_memory].to_s
105
+ redis_info[:connected_clients],
106
+ redis_info[:used_memory],
107
+ redis_info[:peak_memory]
127
108
  ]
128
109
 
129
- # Format keys and values with spacing
130
- keys_line = keys.map { |k| t(k).ljust(18) }.join(" ")
131
- values_line = values.map { |v| v.ljust(18) }.join(" ")
132
-
133
- frame.render_widget(
134
- tui.paragraph(
135
- text: [keys_line, values_line],
136
- block: tui.block(title: "Redis Information", borders: [:all])
137
- ),
138
- area
139
- )
110
+ render_kv_section(tui, frame, area, title: "Redis Information", keys:, values:, width: 18)
140
111
  end
141
112
  end
142
113
  end
@@ -33,15 +33,7 @@ module Sidekiq
33
33
  end
34
34
 
35
35
  def render(tui, frame, area)
36
- chunks = tui.layout_split(
37
- area,
38
- direction: :vertical,
39
- constraints: [
40
- tui.constraint_length(4), # Stats
41
- tui.constraint_fill(1) # Chart
42
- # TOOD Table
43
- ]
44
- )
36
+ chunks = stats_content_split(tui, area)
45
37
 
46
38
  render_stats_section(tui, frame, chunks[0])
47
39
  render_metrics_chart(tui, frame, chunks[1])
@@ -93,11 +85,6 @@ module Sidekiq
93
85
  graph_type: :line)
94
86
  end
95
87
 
96
- num_labels = 5
97
- y_labels = (0...num_labels).map do |i|
98
- value = ((y_max * i) / (num_labels - 1)).round
99
- value.to_s
100
- end
101
88
  xlabels = [
102
89
  q.starts_at.iso8601[11..15],
103
90
  q.ends_at.iso8601[11..15]
@@ -112,11 +99,7 @@ module Sidekiq
112
99
  labels: xlabels,
113
100
  style: tui.style(fg: :white)
114
101
  ),
115
- y_axis: tui.axis(
116
- bounds: [0.0, y_max.to_f],
117
- labels: y_labels,
118
- style: tui.style(fg: :white)
119
- ),
102
+ y_axis: chart_y_axis(tui, y_max),
120
103
  block: tui.block(
121
104
  title: t(name),
122
105
  borders: [:all]
@@ -63,14 +63,7 @@ module Sidekiq
63
63
  header = ["☑️", "Queue", "Size", "Latency"].map { |x| t(x) }
64
64
  header << "Paused?" if Sidekiq.pro?
65
65
 
66
- chunks = tui.layout_split(
67
- area,
68
- direction: :vertical,
69
- constraints: [
70
- tui.constraint_length(4), # Stats
71
- tui.constraint_fill(1) # Table
72
- ]
73
- )
66
+ chunks = stats_content_split(tui, area)
74
67
 
75
68
  render_stats_section(tui, frame, chunks[0])
76
69
  render_table(tui, frame, chunks[1]) do
@@ -80,12 +73,7 @@ module Sidekiq
80
73
  widths: header.map.with_index { |_, idx|
81
74
  tui.constraint_length((idx == 1) ? 60 : 10)
82
75
  },
83
- rows: @data[:queues].map.with_index { |cells, idx|
84
- tui.table_row(
85
- cells:,
86
- style: idx.even? ? nil : tui.style(bg: :dark_gray)
87
- )
88
- }
76
+ rows: striped_rows(tui, @data[:queues])
89
77
  }
90
78
  end
91
79
  end
@@ -8,11 +8,6 @@ module Sidekiq
8
8
  include SetTab
9
9
 
10
10
  def set_class = Sidekiq::RetrySet
11
-
12
- def refresh_data
13
- refresh_data_for_stats
14
- refresh_data_for_set
15
- end
16
11
  end
17
12
  end
18
13
  end
@@ -8,11 +8,6 @@ module Sidekiq
8
8
  include SetTab
9
9
 
10
10
  def set_class = Sidekiq::ScheduledSet
11
-
12
- def refresh_data
13
- refresh_data_for_stats
14
- refresh_data_for_set
15
- end
16
11
  end
17
12
  end
18
13
  end
@@ -30,6 +30,11 @@ module Sidekiq
30
30
  end
31
31
  end
32
32
 
33
+ def refresh_data
34
+ refresh_data_for_stats
35
+ refresh_data_for_set
36
+ end
37
+
33
38
  def refresh_data_for_set
34
39
  set = set_class.new
35
40
  f = current_filter
@@ -52,14 +57,7 @@ module Sidekiq
52
57
  end
53
58
 
54
59
  def render(tui, frame, area)
55
- chunks = tui.layout_split(
56
- area,
57
- direction: :vertical,
58
- constraints: [
59
- tui.constraint_length(4), # Stats
60
- tui.constraint_fill(1) # Table
61
- ]
62
- )
60
+ chunks = stats_content_split(tui, area)
63
61
 
64
62
  render_stats_section(tui, frame, chunks[0])
65
63
  render_table(tui, frame, chunks[1]) do
@@ -74,19 +72,16 @@ module Sidekiq
74
72
  tui.constraint_fill(1)
75
73
  ]
76
74
  }.tap do |h|
77
- rows = @data[:table][:rows].map.with_index { |entry, idx|
78
- tui.table_row(
79
- cells: [
80
- selected?(entry) ? "✅" : "",
81
- entry.at,
82
- entry.queue,
83
- entry.display_class,
84
- entry.display_args
85
- ],
86
- style: idx.even? ? nil : tui.style(bg: :dark_gray)
87
- )
75
+ cells = @data[:table][:rows].map { |entry|
76
+ [
77
+ selected?(entry) ? "✅" : "",
78
+ entry.at,
79
+ entry.queue,
80
+ entry.display_class,
81
+ entry.display_args
82
+ ]
88
83
  }
89
- h[:rows] = rows
84
+ h[:rows] = striped_rows(tui, cells)
90
85
  end
91
86
  end
92
87
  end
data/lib/sidekiq/tui.rb CHANGED
@@ -60,12 +60,14 @@ module Sidekiq
60
60
  track_fps do
61
61
  if @showing == :main
62
62
  @tui.draw do |frame|
63
+ # Borders take 2 columns, and 2 rows along with the footer line.
64
+ control_rows = current_tab.control_rows(frame.area.width - 4)
63
65
  main_area, controls_area = @tui.layout_split(
64
66
  frame.area,
65
67
  direction: :vertical,
66
68
  constraints: [
67
69
  @tui.constraint_fill(1),
68
- @tui.constraint_length(5)
70
+ @tui.constraint_length([control_rows.size, 2].max + 3)
69
71
  ]
70
72
  )
71
73
 
@@ -91,7 +93,7 @@ module Sidekiq
91
93
  frame.render_widget(tabs, tabs_area)
92
94
 
93
95
  render_content_area(frame, content_area)
94
- render_controls(frame, controls_area)
96
+ render_controls(frame, controls_area, control_rows)
95
97
  end
96
98
  end
97
99
 
@@ -105,63 +107,46 @@ module Sidekiq
105
107
  @tui.constraint_length(4)
106
108
  ]
107
109
  )
108
- content = @tui.block(
109
- title: " #{Sidekiq::NAME} ",
110
- borders: [:all],
111
- title_style: @tui.style(fg: :light_red, modifiers: [:bold]),
112
- children: [
113
- # TODO convert to table
114
- @tui.paragraph(
115
- text: [
116
- @tui.text_line(spans: ["Welcome to the Sidekiq Terminal UI"], alignment: :center),
117
- @tui.text_line(spans: [
118
- @tui.text_span(content: "Global hotkeys")
119
- ]),
120
- @tui.text_line(spans: []),
121
- @tui.text_line(spans: [
122
- @tui.text_span(content: "Esc", style: @hotkey_style),
123
- @tui.text_span(content: ": Close this window")
124
- ]),
125
- @tui.text_line(spans: [
126
- @tui.text_span(content: "←/→", style: @hotkey_style),
127
- @tui.text_span(content: ": Move between tabs")
128
- ]),
129
- @tui.text_line(spans: [
130
- @tui.text_span(content: "h/l", style: @hotkey_style),
131
- @tui.text_span(content: ": Move to prev/next page of data")
132
- ]),
133
- @tui.text_line(spans: [
134
- @tui.text_span(content: "j/k", style: @hotkey_style),
135
- @tui.text_span(content: ": Move to prev/next row in current page")
136
- ]),
137
- @tui.text_line(spans: [
138
- @tui.text_span(content: "x", style: @hotkey_style),
139
- @tui.text_span(content: ": Select/deselect current row")
140
- ]),
141
- @tui.text_line(spans: [
142
- @tui.text_span(content: "A", style: @hotkey_style),
143
- @tui.text_span(content: ": Select/deselect All rows in current page")
144
- ]),
145
- @tui.text_line(spans: [
146
- @tui.text_span(content: "q", style: @hotkey_style),
147
- @tui.text_span(content: ": Quit")
148
- ])
149
- ]
150
- )
151
- ]
110
+
111
+ help_data = [
112
+ ["Esc", "Close this window"],
113
+ ["←/→", "Move between tabs"],
114
+ ["h/l", "Move to prev/next page of data"],
115
+ ["j/k", "Move to prev/next row in current page"],
116
+ ["x", "Select/deselect current row"],
117
+ ["A", "Select/deselect All rows in current page"],
118
+ ["q", "Quit"]
119
+ ]
120
+
121
+ # striped styling like other tables in the app
122
+ help_rows = help_data.map.with_index { |cells, idx|
123
+ @tui.table_row(
124
+ cells: cells,
125
+ style: idx.even? ? nil : @tui.style(bg: :dark_gray)
126
+ )
127
+ }
128
+
129
+ table = @tui.table(
130
+ block: @tui.block(
131
+ title: " #{Sidekiq::NAME} - Welcome to the Sidekiq Terminal UI ",
132
+ borders: [:all],
133
+ title_style: @tui.style(fg: :light_red, modifiers: [:bold])
134
+ ),
135
+ header: ["Key", "Action"],
136
+ rows: help_rows,
137
+ widths: [
138
+ @tui.constraint_length(15),
139
+ @tui.constraint_fill(1)
140
+ ],
141
+ column_spacing: 1
152
142
  )
153
- frame.render_widget(content, main_area)
143
+ frame.render_widget(table, main_area)
154
144
  controls = @tui.block(
155
145
  title: t("Controls"),
156
146
  borders: [:all],
157
147
  children: [
158
148
  @tui.paragraph(
159
- text: [
160
- @tui.text_line(spans: [
161
- @tui.text_span(content: "Esc", style: @hotkey_style),
162
- @tui.text_span(content: ": Close ")
163
- ])
164
- ]
149
+ text: [hotkey_line("Esc", "Close ")]
165
150
  )
166
151
  ]
167
152
  )
@@ -177,30 +162,12 @@ module Sidekiq
177
162
  current_tab.render(@tui, frame, content_area)
178
163
  end
179
164
 
180
- def render_controls(frame, area)
181
- active_keys = current_tab.controls.filter { |hash| hash[:description] }
165
+ def render_controls(frame, area, control_rows)
166
+ lines = control_rows.map { |keys| controls_line(keys) }
182
167
 
183
- # Split controls into two lines, 8 is arbitrary
184
- # TODO Dynamically split based on term width?
185
- first = active_keys[...8]
186
- lines = []
187
- lines << @tui.text_line(spans: first.map { |hash|
188
- [
189
- @tui.text_span(content: hash[:display] || hash[:code], style: @hotkey_style),
190
- @tui.text_span(content: ": #{t(hash[:description])} ")
191
- ]
192
- }.flatten)
193
-
194
- last = active_keys[8...]
195
- lines << if last && last.size > 0
196
- @tui.text_line(spans: last.map { |hash|
197
- [
198
- @tui.text_span(content: hash[:display] || hash[:code], style: @hotkey_style),
199
- @tui.text_span(content: ": #{t(hash[:description])} ")
200
- ]
201
- }.flatten)
202
- else
203
- @tui.text_line(spans: [])
168
+ # Ensure we have at least 2 lines for layout consistency
169
+ while lines.length < 2
170
+ lines << @tui.text_line(spans: [])
204
171
  end
205
172
 
206
173
  footer = [
@@ -225,6 +192,22 @@ module Sidekiq
225
192
  frame.render_widget(controls, area)
226
193
  end
227
194
 
195
+ def hotkey_line(key, description)
196
+ @tui.text_line(spans: [
197
+ @tui.text_span(content: key, style: @hotkey_style),
198
+ @tui.text_span(content: ": #{description}")
199
+ ])
200
+ end
201
+
202
+ def controls_line(keys)
203
+ @tui.text_line(spans: keys.map { |hash|
204
+ [
205
+ @tui.text_span(content: hash[:display] || hash[:code], style: @hotkey_style),
206
+ @tui.text_span(content: ": #{t(hash[:description])} ")
207
+ ]
208
+ }.flatten)
209
+ end
210
+
228
211
  def handle_input
229
212
  # We shouldn't need more than 10 FPS for a data-oriented app.
230
213
  # This throttles down our CPU usage. Default is 60 FPS.
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sidekiq
4
- VERSION = "8.1.6"
4
+ VERSION = "8.1.8"
5
5
  MAJOR = 8
6
6
 
7
7
  def self.gem_version
@@ -118,7 +118,7 @@ module Sidekiq
118
118
  unless respond_to?(:"_erb_#{content}")
119
119
  views = options[:views] || Web.views
120
120
  filename = "#{views}/#{content}.html.erb"
121
- src = ERB.new(File.read(filename)).src
121
+ src = ERB.new(File.read(filename, encoding: "UTF-8")).src
122
122
 
123
123
  # Need to use lineno less by 1 because erb generates a
124
124
  # comment before the source code.
@@ -170,7 +170,7 @@ module Sidekiq
170
170
 
171
171
  class_eval <<-RUBY, ::Sidekiq::Web::LAYOUT, -1 # standard:disable Style/EvalWithLocation
172
172
  def _render
173
- #{ERB.new(File.read(::Sidekiq::Web::LAYOUT)).src}
173
+ #{ERB.new(File.read(::Sidekiq::Web::LAYOUT, encoding: "UTF-8")).src}
174
174
  end
175
175
  RUBY
176
176
  end