Skip to content

Commit

Permalink
screen_utils: move screen_bell() to separate header
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 2, 2024
1 parent d64dedb commit 13d0862
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/FileBrowserPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "screen_client.hxx"
#include "Command.hxx"
#include "Options.hxx"
#include "ui/Bell.hxx"
#include "lib/fmt/ToSpan.hxx"
#include "util/UriUtil.hxx"

Expand Down Expand Up @@ -236,7 +237,7 @@ FileBrowserPage::HandleDelete(struct mpdclient &c) noexcept
for playlists; the user attempted to delete a song
or a directory or something else */
screen_status_message(_("Deleting this item is not possible"));
screen_bell();
Bell();
continue;
}

Expand Down
7 changes: 4 additions & 3 deletions src/KeyDefPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "GlobalBindings.hxx"
#include "screen_utils.hxx"
#include "Options.hxx"
#include "ui/Bell.hxx"
#include "ui/ListText.hxx"
#include "ui/TextListRenderer.hxx"
#include "util/SPrintf.hxx"
Expand Down Expand Up @@ -179,7 +180,7 @@ CommandKeysPage::OverwriteKey(int key_index)
screen_status_printf(_("Error: key %s is already used for %s"),
GetLocalizedKeyName(key),
get_key_command_name(cmd));
screen_bell();
Bell();
return;
}

Expand Down Expand Up @@ -382,7 +383,7 @@ CommandListPage::Save()
filename = MakeKeysPath();
if (filename.empty()) {
screen_status_message(_("Unable to write configuration"));
screen_bell();
Bell();
return;
}
} else
Expand All @@ -392,7 +393,7 @@ CommandListPage::Save()
if (f == nullptr) {
screen_status_printf("%s: %s - %s", _("Error"),
filename.c_str(), strerror(errno));
screen_bell();
Bell();
return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/callbacks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "screen_status.hxx"
#include "mpdclient.hxx"
#include "ncmpc.hxx"
#include "ui/Bell.hxx"

#include <curses.h>

Expand Down Expand Up @@ -37,14 +38,14 @@ void
mpdclient_error_callback(std::string_view message) noexcept
{
screen_status_message(message);
screen_bell();
Bell();
doupdate();
}

void
mpdclient_error_callback(std::exception_ptr e) noexcept
{
screen_status_error(std::move(e));
screen_bell();
Bell();
doupdate();
}
3 changes: 2 additions & 1 deletion src/screen_find.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "i18n.h"
#include "Command.hxx"
#include "Options.hxx"
#include "ui/Bell.hxx"
#include "ui/ListWindow.hxx"
#include "util/LocaleString.hxx"

Expand Down Expand Up @@ -58,7 +59,7 @@ screen_find(ScreenManager &screen, ListWindow &lw, Command findcmd,
if (!found) {
screen_status_printf(_("Unable to find \'%s\'"),
screen.findbuf.c_str());
screen_bell();
Bell();
}
return true;
default:
Expand Down
10 changes: 0 additions & 10 deletions src/screen_utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "screen.hxx"
#include "config.h"
#include "i18n.h"
#include "Options.hxx"
#include "Styles.hxx"
#include "wreadln.hxx"
#include "config.h"
Expand All @@ -19,15 +18,6 @@

using std::string_view_literals::operator""sv;

void
screen_bell() noexcept
{
if (options.audible_bell)
beep();
if (options.visible_bell)
flash();
}

static constexpr bool
ignore_key(int key) noexcept
{
Expand Down
4 changes: 0 additions & 4 deletions src/screen_utils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

class ScreenManager;

/* sound an audible and/or visible bell */
void
screen_bell() noexcept;

/* read a character from the status window */
int
screen_getch(ScreenManager &screen, const char *prompt) noexcept;
Expand Down
13 changes: 13 additions & 0 deletions src/ui/Bell.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Bell.hxx"
#include "Options.hxx"

#include <curses.h>

void
Bell() noexcept
{
if (options.audible_bell)
beep();
if (options.visible_bell)
flash();
}
5 changes: 5 additions & 0 deletions src/ui/Bell.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

/* sound an audible and/or visible bell */
void
Bell() noexcept;
6 changes: 3 additions & 3 deletions src/ui/ListWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#include "ListWindow.hxx"
#include "ListRenderer.hxx"
#include "ListText.hxx"
#include "Bell.hxx"
#include "config.h"
#include "Match.hxx"
#include "Options.hxx"
#include "Command.hxx"
#include "paint.hxx"
#include "screen_utils.hxx"

void
ListWindow::Paint(const ListRenderer &renderer) const noexcept
Expand Down Expand Up @@ -75,7 +75,7 @@ ListWindow::Find(const ListText &text,
return 1;
i=0; /* first item */
if (options.bell_on_wrap) {
screen_bell();
Bell();
}
}
} while (wrap);
Expand Down Expand Up @@ -115,7 +115,7 @@ ListWindow::ReverseFind(const ListText &text,
if (wrap) {
i = GetLength() - 1; /* last item */
if (options.bell_on_wrap) {
screen_bell();
Bell();
}
}
} while (wrap);
Expand Down
1 change: 1 addition & 0 deletions src/ui/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ui = static_library(
'ui',
'Bell.cxx',
'ListCursor.cxx',
'ListWindow.cxx',
'TextListRenderer.cxx',
Expand Down
7 changes: 4 additions & 3 deletions src/wreadln.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include "wreadln.hxx"
#include "Completion.hxx"
#include "screen_utils.hxx"
//#include "screen_utils.hxx"
#include "config.h"
#include "ui/Bell.hxx"
#include "ui/Point.hxx"
#include "ui/Window.hxx"
#include "util/LocaleString.hxx"
Expand Down Expand Up @@ -341,7 +342,7 @@ _wreadln(const Window window,
wr.value = std::move(r.new_prefix);
wr.MoveCursorToEnd();
} else
screen_bell();
Bell();

completion->Post(wr.value, r.range);
}
Expand All @@ -350,7 +351,7 @@ _wreadln(const Window window,

case KEY_CTRL_C:
case KEY_CTRL_G:
screen_bell();
Bell();
if (history) {
history->pop_back();
}
Expand Down

0 comments on commit 13d0862

Please sign in to comment.