prompt: Unit test the example

This commit is contained in:
Emmanuel Lepage Vallee 2016-12-30 00:45:49 -05:00
parent 856244723c
commit 53d32d362a
2 changed files with 37 additions and 14 deletions

View File

@ -1,25 +1,17 @@
---------------------------------------------------------------------------
--- Prompt module for awful.
--
-- **Basic usage**:
--
-- 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
-- @DOC_wibox_awidget_prompt_simple_EXAMPLE@
--
-- -- Then **IN THE globalkeys TABLE** add a new shortcut
-- awful.key({ modkey }, "e", echo_test,
-- {description = "Echo a string", group = "custom"}),
-- -- 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.

View File

@ -0,0 +1,31 @@
local parent = ... --DOC_NO_USAGE --DOC_HIDE
local wibox = require( "wibox" ) --DOC_HIDE
local awful = { prompt = require("awful.prompt") }--DOC_HIDE
local beautiful = require( "beautiful" ) --DOC_HIDE
local naughty = {} --DOC_HIDE
local atextbox = wibox.widget.textbox()
-- Create a shortcut function
local function echo_test()
awful.prompt.run {
prompt = "<b>Echo: </b>",
text = "default command",
bg_cursor = "#ff0000",
-- To use the default `rc.lua` prompt:
--textbox = mouse.screen.mypromptbox.widget,
textbox = atextbox,
exe_callback = function(input)
if not input or #input == 0 then return end
naughty.notify{ text = "The input was: "..input }
end
}
end
echo_test() --DOC_HIDE
parent:add( wibox.widget { --DOC_HIDE
atextbox, --DOC_HIDE
bg = beautiful.bg_normal, --DOC_HIDE
widget = wibox.container.background --DOC_HIDE
}) --DOC_HIDE