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>
|
-- @author Julien Danjou <julien@danjou.info>
|
||||||
-- @copyright 2008 Julien Danjou
|
-- @copyright 2008 Julien Danjou
|
||||||
|
@ -31,37 +54,35 @@ data.history = {}
|
||||||
|
|
||||||
local search_term = nil
|
local search_term = nil
|
||||||
local function itera (inc,a, i)
|
local function itera (inc,a, i)
|
||||||
i = i + inc
|
i = i + inc
|
||||||
local v = a[i]
|
local v = a[i]
|
||||||
if v then return i,v end
|
if v then return i,v end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Load history file in history table
|
--- Load history file in history table
|
||||||
-- @param id The data.history identifier which is the path to the filename.
|
-- @param id The data.history identifier which is the path to the filename.
|
||||||
-- @param[opt] max The maximum number of entries in file.
|
-- @param[opt] max The maximum number of entries in file.
|
||||||
local function history_check_load(id, max)
|
local function history_check_load(id, max)
|
||||||
if id and id ~= ""
|
if id and id ~= "" and not data.history[id] then
|
||||||
and not data.history[id] then
|
data.history[id] = { max = 50, table = {} }
|
||||||
data.history[id] = { max = 50, table = {} }
|
|
||||||
|
|
||||||
if max then
|
if max then
|
||||||
data.history[id].max = max
|
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
|
-- Read history file
|
||||||
if f then
|
for line in f:lines() do
|
||||||
for line in f:lines() do
|
if util.table.hasitem(data.history[id].table, line) == nil then
|
||||||
if util.table.hasitem(data.history[id].table, line) == nil then
|
table.insert(data.history[id].table, line)
|
||||||
table.insert(data.history[id].table, line)
|
if #data.history[id].table >= data.history[id].max then
|
||||||
if #data.history[id].table >= data.history[id].max then
|
break
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
f:close()
|
end
|
||||||
end
|
f:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -114,7 +135,7 @@ local function history_save(id)
|
||||||
util.mkdir(id:sub(1, i - 1))
|
util.mkdir(id:sub(1, i - 1))
|
||||||
f = assert(io.open(id, "w"))
|
f = assert(io.open(id, "w"))
|
||||||
end
|
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")
|
f:write(data.history[id].table[i] .. "\n")
|
||||||
end
|
end
|
||||||
f:close()
|
f:close()
|
||||||
|
@ -365,7 +386,7 @@ function prompt.run(args, textbox, exe_callback, completion_callback,
|
||||||
local cur_pos = (selectall and 1) or text:wlen() + 1
|
local cur_pos = (selectall and 1) or text:wlen() + 1
|
||||||
-- The completion element to use on completion request.
|
-- The completion element to use on completion request.
|
||||||
local ncomp = 1
|
local ncomp = 1
|
||||||
if not textbox or not (exe_callback or args.hooks) then
|
if not textbox then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -394,7 +415,7 @@ function prompt.run(args, textbox, exe_callback, completion_callback,
|
||||||
textbox:set_markup("")
|
textbox:set_markup("")
|
||||||
history_add(history_path, command_to_history)
|
history_add(history_path, command_to_history)
|
||||||
keygrabber.stop(grabber)
|
keygrabber.stop(grabber)
|
||||||
cb(command)
|
if cb then cb(command) end
|
||||||
if done_callback then done_callback() end
|
if done_callback then done_callback() end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -444,7 +444,6 @@ function menubar.show(scr)
|
||||||
awful.prompt.run(setmetatable({
|
awful.prompt.run(setmetatable({
|
||||||
prompt = "Run: ",
|
prompt = "Run: ",
|
||||||
textbox = instance.prompt.widget,
|
textbox = instance.prompt.widget,
|
||||||
exe_callback = function() end,
|
|
||||||
completion_callback = awful.completion.shell,
|
completion_callback = awful.completion.shell,
|
||||||
history_path = awful.util.get_cache_dir() .. "/history_menu",
|
history_path = awful.util.get_cache_dir() .. "/history_menu",
|
||||||
done_callback = menubar.hide,
|
done_callback = menubar.hide,
|
||||||
|
|
Loading…
Reference in New Issue