Skip to content

Commit

Permalink
Styles: add style "input"
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 6, 2024
1 parent 2ef6c4d commit 223c317
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ncmpc 0.50 - not yet released
* build: require Meson 0.60
* require libfmt 9
* draw progress bar as Unicode double line
* add color style "text" for input text controls
* lyrics/musixmatch: add new lyrics extension
* lyrics/google: fix partial loading of lyrics

Expand Down
3 changes: 3 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ color used to display time the status window.
:command:`color alert = COLOR[,ATTRIBUTE]...` - Set the text color
used to display alerts in the status window.

:command:`color input = COLOR[,ATTRIBUTE]...` - Set the text color of
text input controls.

:command:`colordef COLOR = R, G, B` - Redefine any of the base
colors. The RGB values must be integer values between 0 and 1000.
*Note*: Only some terminals allow redefinitions of colors!
Expand Down
5 changes: 5 additions & 0 deletions src/Styles.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ static StyleData styles[size_t(Style::END)] = {
COLOR_RED, COLOR_INHERIT, A_INHERIT,
A_NORMAL,
},
{
"input", Style::BACKGROUND,
COLOR_NONE, COLOR_INHERIT, A_NORMAL,
A_NORMAL,
},
{
"background", Style::DEFAULT,
COLOR_NONE, COLOR_BLACK, A_NORMAL,
Expand Down
1 change: 1 addition & 0 deletions src/Styles.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum class Style : unsigned {
STATUS_ALERT,
DIRECTORY,
PLAYLIST,
INPUT,
BACKGROUND,
END
};
Expand Down
34 changes: 29 additions & 5 deletions src/screen_utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "i18n.h"
#include "Styles.hxx"
#include "wreadln.hxx"
#include "ui/Options.hxx"
#include "util/ScopeExit.hxx"
#include "config.h"

#ifndef _WIN32
Expand Down Expand Up @@ -34,9 +36,17 @@ screen_getch(ScreenManager &screen, const char *prompt) noexcept
{
const auto &window = screen.status_bar.GetWindow();

if (ui_options.enable_colors)
window.SetBackgroundStyle(Style::INPUT);

AtScopeExit(&window) {
if (ui_options.enable_colors)
window.SetBackgroundStyle(Style::STATUS);
};

SelectStyle(window, Style::STATUS_ALERT);
window.Erase();
window.String({0, 0}, prompt);
window.ClearToEol();

echo();
curs_set(1);
Expand Down Expand Up @@ -92,6 +102,14 @@ screen_readln(ScreenManager &screen, const char *prompt,
{
const auto &window = screen.status_bar.GetWindow();

if (ui_options.enable_colors)
window.SetBackgroundStyle(Style::INPUT);

AtScopeExit(&window) {
if (ui_options.enable_colors)
window.SetBackgroundStyle(Style::STATUS);
};

window.MoveCursor({0, 0});

if (prompt != nullptr) {
Expand All @@ -100,8 +118,7 @@ screen_readln(ScreenManager &screen, const char *prompt,
window.String(": "sv);
}

SelectStyle(window, Style::STATUS);
window.AttributeOn(A_REVERSE);
SelectStyle(window, Style::INPUT);

return wreadln(window, value, history, completion);
}
Expand All @@ -111,6 +128,14 @@ screen_read_password(ScreenManager &screen, const char *prompt) noexcept
{
const auto &window = screen.status_bar.GetWindow();

if (ui_options.enable_colors)
window.SetBackgroundStyle(Style::INPUT);

AtScopeExit(&window) {
if (ui_options.enable_colors)
window.SetBackgroundStyle(Style::STATUS);
};

window.MoveCursor({0, 0});
SelectStyle(window, Style::STATUS_ALERT);

Expand All @@ -120,8 +145,7 @@ screen_read_password(ScreenManager &screen, const char *prompt) noexcept
window.String(prompt);
window.String(": "sv);

SelectStyle(window, Style::STATUS);
window.AttributeOn(A_REVERSE);
SelectStyle(window, Style::INPUT);

return wreadln_masked(window, nullptr);
}
Expand Down

0 comments on commit 223c317

Please sign in to comment.