summaryrefslogtreecommitdiff
path: root/docker-widget
diff options
context:
space:
mode:
Diffstat (limited to 'docker-widget')
-rw-r--r--docker-widget/docker.lua53
1 files changed, 30 insertions, 23 deletions
diff --git a/docker-widget/docker.lua b/docker-widget/docker.lua
index 5bd5746..6ea0179 100644
--- a/docker-widget/docker.lua
+++ b/docker-widget/docker.lua
@@ -19,7 +19,8 @@ local HOME_DIR = os.getenv("HOME")
local WIDGET_DIR = HOME_DIR .. '/.config/awesome/awesome-wm-widgets/docker-widget'
local ICONS_DIR = WIDGET_DIR .. '/icons/'
-local LIST_CONTAINERS_CMD = [[bash -c "docker container ls -a -s -n %s --format '{{.Names}}::{{.ID}}::{{.Image}}::{{.Status}}::{{.Size}}'"]]
+local LIST_CONTAINERS_CMD = [[bash -c "docker container ls -a -s -n %s]]
+ .. [[ --format '{{.Names}}::{{.ID}}::{{.Image}}::{{.Status}}::{{.Size}}'"]]
--- Utility function to show warning messages
local function show_warning(message)
@@ -83,9 +84,9 @@ local status_to_icon_name = {
Paused = ICONS_DIR .. 'pause.svg'
}
-local function worker(args)
+local function worker(user_args)
- local args = args or {}
+ local args = user_args or {}
local icon = args.icon or ICONS_DIR .. 'docker.svg'
local number_of_containers = args.number_of_containers or -1
@@ -97,15 +98,15 @@ local function worker(args)
layout = wibox.layout.fixed.vertical,
}
- local function rebuild_widget(stdout, stderr, _, _)
- if stderr ~= '' then
- show_warning(stderr)
+ local function rebuild_widget(containers, errors, _, _)
+ if errors ~= '' then
+ show_warning(errors)
return
end
for i = 0, #rows do rows[i]=nil end
- for line in stdout:gmatch("[^\r\n]+") do
+ for line in containers:gmatch("[^\r\n]+") do
local container = parse_container(line)
@@ -163,10 +164,12 @@ local function worker(args)
status_icon:set_opacity(0.2)
status_icon:emit_signal('widget::redraw_needed')
- spawn.easy_async('docker ' .. command .. ' ' .. container['name'], function(stdout, stderr)
- if stderr ~= '' then show_warning(stderr) end
- spawn.easy_async(string.format(LIST_CONTAINERS_CMD, number_of_containers), function(stdout, stderr)
- rebuild_widget(stdout, stderr) end)
+ spawn.easy_async('docker ' .. command .. ' ' .. container['name'], function()
+ if errors ~= '' then show_warning(errors) end
+ spawn.easy_async(string.format(LIST_CONTAINERS_CMD, number_of_containers),
+ function(stdout, stderr)
+ rebuild_widget(stdout, stderr)
+ end)
end)
end) ) )
else
@@ -220,10 +223,12 @@ local function worker(args)
status_icon:set_opacity(0.2)
status_icon:emit_signal('widget::redraw_needed')
- awful.spawn.easy_async('docker ' .. command .. ' ' .. container['name'], function(stdout, stderr)
+ awful.spawn.easy_async('docker ' .. command .. ' ' .. container['name'], function(_, stderr)
if stderr ~= '' then show_warning(stderr) end
- spawn.easy_async(string.format(LIST_CONTAINERS_CMD, number_of_containers), function(stdout, stderr)
- rebuild_widget(stdout, stderr) end)
+ spawn.easy_async(string.format(LIST_CONTAINERS_CMD, number_of_containers),
+ function(stdout, container_errors)
+ rebuild_widget(stdout, container_errors)
+ end)
end)
end) ) )
else
@@ -250,11 +255,12 @@ local function worker(args)
}
delete_button:buttons(
awful.util.table.join( awful.button({}, 1, function()
- awful.spawn.easy_async('docker rm ' .. container['name'], function(stdout, stderr)
- if stderr ~= '' then show_warning(stderr) end
- spawn.easy_async(string.format(LIST_CONTAINERS_CMD, number_of_containers), function(stdout, stderr)
- rebuild_widget(stdout, stderr) end)
- end)
+ awful.spawn.easy_async('docker rm ' .. container['name'], function(_, rm_stderr)
+ if rm_stderr ~= '' then show_warning(rm_stderr) end
+ spawn.easy_async(string.format(LIST_CONTAINERS_CMD, number_of_containers),
+ function(lc_stdout, lc_stderr)
+ rebuild_widget(lc_stdout, lc_stderr) end)
+ end)
end)))
local old_cursor, old_wibox
@@ -350,10 +356,11 @@ local function worker(args)
if popup.visible then
popup.visible = not popup.visible
else
- spawn.easy_async(string.format(LIST_CONTAINERS_CMD, number_of_containers), function(stdout, stderr)
- rebuild_widget(stdout, stderr)
- popup:move_next_to(mouse.current_widget_geometry)
- end)
+ spawn.easy_async(string.format(LIST_CONTAINERS_CMD, number_of_containers),
+ function(stdout, stderr)
+ rebuild_widget(stdout, stderr)
+ popup:move_next_to(mouse.current_widget_geometry)
+ end)
end
end)
)