Skip to content

Commit

Permalink
Options: move generic UI options to struct UiOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 2, 2024
1 parent 13d0862 commit 8212cd2
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 66 deletions.
23 changes: 12 additions & 11 deletions src/ConfigParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "screen_list.hxx"
#include "PageMeta.hxx"
#include "Options.hxx"
#include "ui/Options.hxx"
#include "lib/fmt/RuntimeError.hxx"
#include "util/CharUtil.hxx"
#include "util/PrintException.hxx"
Expand Down Expand Up @@ -594,12 +595,12 @@ parse_line(char *line)
/* enable colors */
else if(StringIsEqualIgnoreCase(CONF_ENABLE_COLORS, name))
#ifdef ENABLE_COLORS
options.enable_colors = str2bool(value);
ui_options.enable_colors = str2bool(value);
#else
{}
#endif
else if (StringIsEqualIgnoreCase(CONF_SCROLL_OFFSET, name))
options.scroll_offset = atoi(value);
ui_options.scroll_offset = atoi(value);
/* auto center */
else if (StringIsEqualIgnoreCase(CONF_AUTO_CENTER, name))
options.auto_center = str2bool(value);
Expand All @@ -612,9 +613,9 @@ parse_line(char *line)
#endif
/* wide cursor */
else if (StringIsEqualIgnoreCase(CONF_WIDE_CURSOR, name))
options.wide_cursor = str2bool(value);
ui_options.wide_cursor = str2bool(value);
else if (StringIsEqualIgnoreCase(name, CONF_HARDWARE_CURSOR))
options.hardware_cursor = str2bool(value);
ui_options.hardware_cursor = str2bool(value);
/* welcome screen list */
else if (StringIsEqualIgnoreCase(CONF_WELCOME_SCREEN_LIST, name))
options.welcome_screen_list = str2bool(value);
Expand Down Expand Up @@ -649,17 +650,17 @@ parse_line(char *line)
} else if (StringIsEqualIgnoreCase(CONF_XTERM_TITLE_FORMAT, name)) {
options.xterm_title_format = GetStringValue(value);
} else if (StringIsEqualIgnoreCase(CONF_LIST_WRAP, name))
options.list_wrap = str2bool(value);
ui_options.list_wrap = str2bool(value);
else if (StringIsEqualIgnoreCase(CONF_FIND_WRAP, name))
options.find_wrap = str2bool(value);
ui_options.find_wrap = str2bool(value);
else if (StringIsEqualIgnoreCase(CONF_FIND_SHOW_LAST,name))
options.find_show_last_pattern = str2bool(value);
ui_options.find_show_last_pattern = str2bool(value);
else if (StringIsEqualIgnoreCase(CONF_AUDIBLE_BELL, name))
options.audible_bell = str2bool(value);
ui_options.audible_bell = str2bool(value);
else if (StringIsEqualIgnoreCase(CONF_VISIBLE_BELL, name))
options.visible_bell = str2bool(value);
ui_options.visible_bell = str2bool(value);
else if (StringIsEqualIgnoreCase(CONF_BELL_ON_WRAP, name))
options.bell_on_wrap = str2bool(value);
ui_options.bell_on_wrap = str2bool(value);
else if (StringIsEqualIgnoreCase(CONF_STATUS_MESSAGE_TIME, name))
options.status_message_time = std::chrono::seconds(atoi(value));
else if (StringIsEqualIgnoreCase(CONF_XTERM_TITLE, name))
Expand Down Expand Up @@ -710,7 +711,7 @@ parse_line(char *line)
#ifdef NCMPC_MINI
{}
#else
options.jump_prefix_only = str2bool(value);
ui_options.jump_prefix_only = str2bool(value);
#endif
else if (StringIsEqualIgnoreCase(CONF_LYRICS_AUTOSAVE, name))
#ifdef ENABLE_LYRICS_SCREEN
Expand Down
5 changes: 3 additions & 2 deletions src/Options.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "charset.hxx"
#include "ConfigFile.hxx"
#include "i18n.h"
#include "ui/Options.hxx"
#include "util/StringAPI.hxx"

#include <stdlib.h>
Expand Down Expand Up @@ -199,12 +200,12 @@ handle_option(int c, const char *arg)
exit(EXIT_SUCCESS);
case 'c': /* --colors */
#ifdef ENABLE_COLORS
options.enable_colors = true;
ui_options.enable_colors = true;
#endif
break;
case 'C': /* --no-colors */
#ifdef ENABLE_COLORS
options.enable_colors = false;
ui_options.enable_colors = false;
#endif
break;
case 'm': /* --mouse */
Expand Down
23 changes: 2 additions & 21 deletions src/Options.hxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project

#ifndef OPTIONS_HXX
#define OPTIONS_HXX
#pragma once

#include "config.h"
#include "defaults.hxx"
Expand Down Expand Up @@ -47,8 +46,6 @@ struct Options {
int search_mode;
int seek_time = 1;

unsigned scroll_offset = 0;

#ifdef ENABLE_CHAT_SCREEN
std::string chat_prefix;
#endif
Expand All @@ -61,32 +58,18 @@ struct Options {
bool text_editor_ask = false;
#endif

bool find_wrap = true;
bool find_show_last_pattern;
bool list_wrap;
bool auto_center;
bool wide_cursor = true;
bool hardware_cursor;

#ifdef ENABLE_COLORS
bool enable_colors = true;
#endif
bool audible_bell = true;
bool visible_bell;
bool bell_on_wrap = true;
#ifndef NCMPC_MINI
bool enable_xterm_title;
#endif
#ifdef HAVE_GETMOUSE
bool enable_mouse;
#endif
#ifdef NCMPC_MINI
static constexpr bool jump_prefix_only = true;
#else
#ifndef NCMPC_MINI
bool scroll = DEFAULT_SCROLL;
bool visible_bitrate;
bool welcome_screen_list = true;
bool jump_prefix_only = true;
bool second_column = true;
#endif

Expand All @@ -96,5 +79,3 @@ struct Options {
extern Options options;

void options_parse(int argc, const char **argv);

#endif
4 changes: 2 additions & 2 deletions src/ProgressBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "ProgressBar.hxx"
#include "Styles.hxx"
#include "Options.hxx"
#include "ui/Options.hxx"
#include "config.h"

#include <assert.h>
Expand All @@ -13,7 +13,7 @@ ProgressBar::ProgressBar(Point p, unsigned _width) noexcept
{
leaveok(window.w, true);
#ifdef ENABLE_COLORS
if (options.enable_colors)
if (ui_options.enable_colors)
window.SetBackgroundStyle(Style::PROGRESSBAR);
#endif
}
Expand Down
1 change: 1 addition & 0 deletions src/SongRowPaint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "strfsong.hxx"
#include "time_format.hxx"
#include "hscroll.hxx"
#include "Options.hxx"
#include "ui/Window.hxx"
#include "ui/paint.hxx"
#include "util/LocaleString.hxx"
Expand Down
3 changes: 2 additions & 1 deletion src/StatusBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "strfsong.hxx"
#include "DelayedSeek.hxx"
#include "time_format.hxx"
#include "ui/Options.hxx"
#include "lib/fmt/ToSpan.hxx"
#include "util/LocaleString.hxx"

Expand All @@ -29,7 +30,7 @@ StatusBar::StatusBar(EventLoop &event_loop,
keypad(window.w, true);

#ifdef ENABLE_COLORS
if (options.enable_colors)
if (ui_options.enable_colors)
window.SetBackgroundStyle(Style::STATUS);
#endif
}
Expand Down
10 changes: 5 additions & 5 deletions src/Styles.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "util/StringStrip.hxx"

#ifdef ENABLE_COLORS
#include "Options.hxx"
#include "ui/Options.hxx"
#endif

#include <assert.h>
Expand Down Expand Up @@ -329,15 +329,15 @@ ApplyStyles() noexcept
/* define any custom colors defined in the configuration file */
ApplyCustomColors();

if (options.enable_colors) {
if (ui_options.enable_colors) {
for (size_t i = 1; i < size_t(Style::END); ++i)
/* update the color pairs */
colors_update_pair(Style(i));
}
} else if (options.enable_colors) {
} else if (ui_options.enable_colors) {
fprintf(stderr, "%s\n",
_("Terminal lacks color capabilities"));
options.enable_colors = false;
ui_options.enable_colors = false;
}
}
#endif
Expand All @@ -348,7 +348,7 @@ SelectStyle(const Window window, Style style) noexcept
const auto &data = GetStyle(style);

#ifdef ENABLE_COLORS
if (options.enable_colors) {
if (ui_options.enable_colors) {
/* color mode */
wattr_set(window.w, data.attr, short(style), nullptr);
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/TitleBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Styles.hxx"
#include "Options.hxx"
#include "i18n.h"
#include "ui/Options.hxx"
#include "util/LocaleString.hxx"

#include "config.h"
Expand All @@ -21,7 +22,7 @@ TitleBar::TitleBar(Point p, unsigned width) noexcept
keypad(window.w, true);

#ifdef ENABLE_COLORS
if (options.enable_colors)
if (ui_options.enable_colors)
window.SetBackgroundStyle(Style::TITLE);
#endif
}
Expand Down
5 changes: 3 additions & 2 deletions src/screen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "player_command.hxx"
#include "SongPage.hxx"
#include "LyricsPage.hxx"
#include "ui/Options.hxx"
#include "util/StringAPI.hxx"

#include <mpd/client.h>
Expand Down Expand Up @@ -226,8 +227,8 @@ ScreenManager::OnCommand(struct mpdclient &c, DelayedSeek &seek, Command cmd)

switch(cmd) {
case Command::TOGGLE_FIND_WRAP:
options.find_wrap = !options.find_wrap;
screen_status_message(options.find_wrap ?
ui_options.find_wrap = !ui_options.find_wrap;
screen_status_message(ui_options.find_wrap ?
_("Find mode: Wrapped") :
_("Find mode: Normal"));
break;
Expand Down
4 changes: 2 additions & 2 deletions src/screen_find.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "AsyncUserInput.hxx"
#include "i18n.h"
#include "Command.hxx"
#include "Options.hxx"
#include "ui/Bell.hxx"
#include "ui/ListWindow.hxx"
#include "ui/Options.hxx"
#include "util/LocaleString.hxx"

#include <ctype.h>
Expand Down Expand Up @@ -42,7 +42,7 @@ screen_find(ScreenManager &screen, ListWindow &lw, Command findcmd,
case Command::LIST_FIND_NEXT:
case Command::LIST_RFIND_NEXT:
if (screen.findbuf.empty()) {
char *value = options.find_show_last_pattern
char *value = ui_options.find_show_last_pattern
? (char *) -1 : nullptr;
screen.findbuf=screen_readln(screen, prompt,
value,
Expand Down
6 changes: 3 additions & 3 deletions src/screen_init.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "Page.hxx"
#include "QueuePage.hxx"
#include "config.h"
#include "Options.hxx"
#include "Styles.hxx"
#include "ui/Options.hxx"

/* minimum window size */
static const unsigned SCREEN_MIN_COLS = 14;
Expand All @@ -26,13 +26,13 @@ ScreenManager::ScreenManager(EventLoop &event_loop) noexcept
buf_size = layout.size.width;
buf = new char[buf_size];

if (!options.hardware_cursor)
if (!ui_options.hardware_cursor)
leaveok(main_window.w, true);

keypad(main_window.w, true);

#ifdef ENABLE_COLORS
if (options.enable_colors) {
if (ui_options.enable_colors) {
/* set background attributes */
main_window.SetBackgroundStyle(Style::LIST);
}
Expand Down
4 changes: 2 additions & 2 deletions src/screen_paint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "screen.hxx"
#include "Page.hxx"
#include "Options.hxx"
#include "ui/Options.hxx"

void
ScreenManager::PaintTopWindow() noexcept
Expand Down Expand Up @@ -34,7 +34,7 @@ ScreenManager::Paint() noexcept

/* move the cursor to the origin */

if (!options.hardware_cursor)
if (!ui_options.hardware_cursor)
main_window.MoveCursor({0, 0});

main_window.RefreshNoOut();
Expand Down
4 changes: 2 additions & 2 deletions src/ui/Bell.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
void
Bell() noexcept
{
if (options.audible_bell)
if (ui_options.audible_bell)
beep();
if (options.visible_bell)
if (ui_options.visible_bell)
flash();
}
8 changes: 4 additions & 4 deletions src/ui/ListCursor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

ListCursor::ListCursor(unsigned _height) noexcept
:height(_height),
scroll_offset(ClampScrollOffset(options.scroll_offset, height))
scroll_offset(ClampScrollOffset(ui_options.scroll_offset, height))
{
}

Expand Down Expand Up @@ -44,7 +44,7 @@ void
ListCursor::SetHeight(unsigned _height) noexcept
{
height = _height;
scroll_offset = ClampScrollOffset(options.scroll_offset, height);
scroll_offset = ClampScrollOffset(ui_options.scroll_offset, height);

CheckOrigin();
}
Expand Down Expand Up @@ -161,7 +161,7 @@ ListCursor::MoveCursorNext() noexcept
{
if (selected + 1 < length)
MoveCursor(selected + 1);
else if (options.list_wrap)
else if (ui_options.list_wrap)
MoveCursor(0);
}

Expand All @@ -170,7 +170,7 @@ ListCursor::MoveCursorPrevious() noexcept
{
if (selected > 0)
MoveCursor(selected - 1);
else if (options.list_wrap)
else if (ui_options.list_wrap)
MoveCursor(length - 1);
}

Expand Down
Loading

0 comments on commit 8212cd2

Please sign in to comment.