From 37f0b7e3bf78fe43bc90e6de1105d48c86dd75ec Mon Sep 17 00:00:00 2001 From: SammysHP Date: Sun, 22 Jan 2017 19:13:50 +0100 Subject: [PATCH] prompt: Make awful.widget.prompt themeable Adds new optional properties to the theme: prompt_fg prompt_bg prompt_fg_cursor prompt_bg_cursor prompt_font --- lib/awful/prompt.lua | 21 +++++++++++++++--- lib/awful/widget/prompt.lua | 22 +++++++++++++++++-- .../wibox/awidget/defaults/prompt.lua | 20 +++++++++++++++++ themes/default/theme.lua | 1 + 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 tests/examples/wibox/awidget/defaults/prompt.lua diff --git a/lib/awful/prompt.lua b/lib/awful/prompt.lua index f4025218..7ba629bb 100644 --- a/lib/awful/prompt.lua +++ b/lib/awful/prompt.lua @@ -94,6 +94,21 @@ -- @module awful.prompt --------------------------------------------------------------------------- +--- The prompt cursor foreground color. +-- @beautiful beautiful.prompt_fg_cursor +-- @param color +-- @see gears.color + +--- The prompt cursor background color. +-- @beautiful beautiful.prompt_bg_cursor +-- @param color +-- @see gears.color + +--- The prompt text font. +-- @beautiful beautiful.prompt_font +-- @param string +-- @see string + -- Grab environment we need local assert = assert local io = io @@ -449,11 +464,11 @@ function prompt.run(args, textbox, exe_callback, completion_callback, local command_before_comp local cur_pos_before_comp local prettyprompt = args.prompt or "" - local inv_col = args.fg_cursor or theme.fg_focus or "black" - local cur_col = args.bg_cursor or theme.bg_focus or "white" + local inv_col = args.fg_cursor or theme.prompt_fg_cursor or theme.fg_focus or "black" + local cur_col = args.bg_cursor or theme.prompt_bg_cursor or theme.bg_focus or "white" local cur_ul = args.ul_cursor local text = args.text or "" - local font = args.font or theme.font + local font = args.font or theme.prompt_font or theme.font local selectall = args.selectall local highlighter = args.highlighter local hooks = {} diff --git a/lib/awful/widget/prompt.lua b/lib/awful/widget/prompt.lua index ff9d9045..7075d37d 100644 --- a/lib/awful/widget/prompt.lua +++ b/lib/awful/widget/prompt.lua @@ -1,17 +1,32 @@ --------------------------------------------------------------------------- +-- The widget version of `awful.prompt`. +-- +-- @DOC_wibox_awidget_defaults_prompt_EXAMPLE@ +-- -- @author Julien Danjou <julien@danjou.info> -- @copyright 2009 Julien Danjou -- @classmod awful.widget.prompt --------------------------------------------------------------------------- +--- The prompt foreground color. +-- @beautiful beautiful.prompt_fg +-- @param color +-- @see gears.color + +--- The prompt background color. +-- @beautiful beautiful.prompt_bg +-- @param color +-- @see gears.color + local setmetatable = setmetatable local completion = require("awful.completion") local util = require("awful.util") local spawn = require("awful.spawn") local prompt = require("awful.prompt") -local widget_base = require("wibox.widget.base") +local beautiful = require("beautiful") local textbox = require("wibox.widget.textbox") +local background = require("wibox.container.background") local type = type local widgetprompt = { mt = {} } @@ -42,16 +57,19 @@ end -- -- @param args Arguments table. "prompt" is the prompt to use. -- @return A launcher widget. +-- @name awful.widget.prompt function widgetprompt.new(args) args = args or {} local widget = textbox() - local promptbox = widget_base.make_widget(widget) + local promptbox = background() promptbox.widget = widget promptbox.widget:set_ellipsize("start") promptbox.run = run promptbox.spawn_and_handle_error = spawn_and_handle_error promptbox.prompt = args.prompt or "Run: " + promptbox.fg = beautiful.prompt_fg or beautiful.fg_normal + promptbox.bg = beautiful.prompt_bg or beautiful.bg_normal return promptbox end diff --git a/tests/examples/wibox/awidget/defaults/prompt.lua b/tests/examples/wibox/awidget/defaults/prompt.lua new file mode 100644 index 00000000..12b7f8ab --- /dev/null +++ b/tests/examples/wibox/awidget/defaults/prompt.lua @@ -0,0 +1,20 @@ +local parent = ... --DOC_NO_USAGE --DOC_HIDE +local awful = { widget = { --DOC_HIDE + prompt = require("awful.widget.prompt")}}--DOC_HIDE +local beautiful = require( "beautiful" ) --DOC_HIDE + +-- Fake a theme --DOC_HIDE +beautiful.prompt_fg = "#F6F2E8" --DOC_HIDE +beautiful.prompt_bg = "#404040" --DOC_HIDE +beautiful.prompt_fg_cursor = "#000000" --DOC_HIDE +beautiful.prompt_bg_cursor = "#898941" --DOC_HIDE +beautiful.prompt_font = "DejaVu Sans Mono 8" --DOC_HIDE + + + local myprompt = awful.widget.prompt { + prompt = "Execute: " + } + + myprompt:run() + +parent:add(myprompt) --DOC_HIDE diff --git a/themes/default/theme.lua b/themes/default/theme.lua index 83f7f51e..10981867 100644 --- a/themes/default/theme.lua +++ b/themes/default/theme.lua @@ -38,6 +38,7 @@ theme.border_marked = "#91231c" -- titlebar_[bg|fg]_[normal|focus] -- tooltip_[font|opacity|fg_color|bg_color|border_width|border_color] -- mouse_finder_[color|timeout|animate_timeout|radius|factor] +-- prompt_[fg|bg|fg_cursor|bg_cursor|font] -- Example: --theme.taglist_bg_focus = "#ff0000"