From 0e1c19345093a44e6cfdf8860310d79d0eccd270 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 11 Dec 2016 14:19:25 -0500 Subject: [PATCH 1/3] prompt: Make exe_callback optional The menubar already bypass it using keypress listener. Having an empty callback is ugly. Fixes #1180 --- lib/awful/prompt.lua | 4 ++-- lib/menubar/init.lua | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/awful/prompt.lua b/lib/awful/prompt.lua index ead326aec..b1515aede 100644 --- a/lib/awful/prompt.lua +++ b/lib/awful/prompt.lua @@ -365,7 +365,7 @@ function prompt.run(args, textbox, exe_callback, completion_callback, local cur_pos = (selectall and 1) or text:wlen() + 1 -- The completion element to use on completion request. local ncomp = 1 - if not textbox or not (exe_callback or args.hooks) then + if not textbox then return end @@ -394,7 +394,7 @@ function prompt.run(args, textbox, exe_callback, completion_callback, textbox:set_markup("") history_add(history_path, command_to_history) keygrabber.stop(grabber) - cb(command) + if cb then cb(command) end if done_callback then done_callback() end end diff --git a/lib/menubar/init.lua b/lib/menubar/init.lua index e3e2dc60b..10ad65c2d 100644 --- a/lib/menubar/init.lua +++ b/lib/menubar/init.lua @@ -444,7 +444,6 @@ function menubar.show(scr) awful.prompt.run(setmetatable({ prompt = "Run: ", textbox = instance.prompt.widget, - exe_callback = function() end, completion_callback = awful.completion.shell, history_path = awful.util.get_cache_dir() .. "/history_menu", done_callback = menubar.hide, From 73afe0e954d49246bfefaf1597aca15418b8fa91 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 11 Dec 2016 14:35:20 -0500 Subject: [PATCH 2/3] doc: Add a prompt example. --- lib/awful/prompt.lua | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/awful/prompt.lua b/lib/awful/prompt.lua index b1515aede..b4487dc43 100644 --- a/lib/awful/prompt.lua +++ b/lib/awful/prompt.lua @@ -1,5 +1,28 @@ --------------------------------------------------------------------------- ---- Prompt module for awful +--- Prompt module for awful. +-- +-- By default, `rc.lua` will create one `awful.widget.prompt` per screen called +-- `mypromptbox`. It is used for both the command execution (`mod4+r`) and +-- Lua prompt (`mod4+x`). It can be re-used for random inputs using: +-- +-- -- Create a shortcut function +-- local function echo_test() +-- awful.prompt.run { +-- prompt = "Echo: ", +-- textbox = mouse.screen.mypromptbox.widget, +-- exe_callback = function(input) +-- if not input or #input == 0 then return end +-- naughty.notify{ text = "The input was: "..input } +-- end +-- } +-- end +-- +-- -- Then **IN THE globalkeys TABLE** add a new shortcut +-- awful.key({ modkey }, "e", echo_test, +-- {description = "Echo a string", group = "custom"}), +-- +-- Note that this assumes an `rc.lua` file based on the default one. The way +-- to access the screen prompt may vary. -- -- @author Julien Danjou <julien@danjou.info> -- @copyright 2008 Julien Danjou From 52fbf493097a41d71715b775afe309584942ed70 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 11 Dec 2016 14:39:05 -0500 Subject: [PATCH 3/3] prompt: Fix indentation There was tabs mixed with spaces --- lib/awful/prompt.lua | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/awful/prompt.lua b/lib/awful/prompt.lua index b4487dc43..9a86475fd 100644 --- a/lib/awful/prompt.lua +++ b/lib/awful/prompt.lua @@ -54,37 +54,35 @@ data.history = {} local search_term = nil local function itera (inc,a, i) - i = i + inc - local v = a[i] - if v then return i,v end + i = i + inc + local v = a[i] + if v then return i,v end end --- Load history file in history table -- @param id The data.history identifier which is the path to the filename. -- @param[opt] max The maximum number of entries in file. local function history_check_load(id, max) - if id and id ~= "" - and not data.history[id] then - data.history[id] = { max = 50, table = {} } + if id and id ~= "" and not data.history[id] then + data.history[id] = { max = 50, table = {} } - if max then + if max then data.history[id].max = max - end + end - local f = io.open(id, "r") + local f = io.open(id, "r") + if not f then return end - -- Read history file - if f then - for line in f:lines() do - if util.table.hasitem(data.history[id].table, line) == nil then - table.insert(data.history[id].table, line) - if #data.history[id].table >= data.history[id].max then - break - end + -- Read history file + for line in f:lines() do + if util.table.hasitem(data.history[id].table, line) == nil then + table.insert(data.history[id].table, line) + if #data.history[id].table >= data.history[id].max then + break end end - f:close() - end + end + f:close() end end @@ -137,7 +135,7 @@ local function history_save(id) util.mkdir(id:sub(1, i - 1)) f = assert(io.open(id, "w")) end - for i = 1, math.min(#data.history[id].table, data.history[id].max) do + for i = 1, math.min(#data.history[id].table, data.history[id].max) do f:write(data.history[id].table[i] .. "\n") end f:close()