commit
2ca95cd75c
|
@ -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
|
||||
|
@ -40,8 +63,7 @@ end
|
|||
-- @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
|
||||
if id and id ~= "" and not data.history[id] then
|
||||
data.history[id] = { max = 50, table = {} }
|
||||
|
||||
if max then
|
||||
|
@ -49,9 +71,9 @@ local function history_check_load(id, max)
|
|||
end
|
||||
|
||||
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)
|
||||
|
@ -62,7 +84,6 @@ local function history_check_load(id, max)
|
|||
end
|
||||
f:close()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function is_word_char(c)
|
||||
|
@ -365,7 +386,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 +415,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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue