add support for pdcurses
This commit is contained in:
@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
|
||||
std::streambuf *cerr_buffer = std::cerr.rdbuf();
|
||||
std::cerr.rdbuf(errorlog.rdbuf());
|
||||
|
||||
InitScreen(Config.colors_enabled);
|
||||
InitScreen("ncmpc++ ver. "VERSION, Config.colors_enabled);
|
||||
init_current_locale();
|
||||
|
||||
MainStartY = 2;
|
||||
@@ -325,6 +325,10 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (input == KEY_RESIZE)
|
||||
{
|
||||
# ifdef USE_PDCURSES
|
||||
resize_term(0, 0);
|
||||
# endif // USE_PDCURSES
|
||||
|
||||
RedrawHeader = 1;
|
||||
|
||||
if (COLS < 20 || LINES < 5)
|
||||
|
||||
@@ -51,10 +51,14 @@ namespace
|
||||
|
||||
void WindowTitle(const string &status)
|
||||
{
|
||||
# ifndef USE_PDCURSES
|
||||
static const string term_type = getenv("TERM") ? getenv("TERM") : "";
|
||||
|
||||
if (term_type != "linux" && Config.set_window_title)
|
||||
std::cout << "\033]0;" << status << "\7";
|
||||
# else
|
||||
(void)status;
|
||||
# endif // USE_PDCURSES
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,18 +28,33 @@ using namespace NCurses;
|
||||
using std::string;
|
||||
using std::wstring;
|
||||
|
||||
void NCurses::InitScreen(bool enable_colors)
|
||||
void NCurses::InitScreen(const char *window_title, bool enable_colors)
|
||||
{
|
||||
const int ColorsTable[] =
|
||||
{
|
||||
COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW,
|
||||
COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE
|
||||
};
|
||||
setlocale(LC_ALL, "");
|
||||
# if defined(USE_PDCURSES) && defined(XCURSES)
|
||||
Xinitscr(1, const_cast<char **>(&window_title));
|
||||
# else
|
||||
window_title = 0; // silence compiler
|
||||
initscr();
|
||||
# endif // USE_PDCURSES && XCURSES
|
||||
if (has_colors() && enable_colors)
|
||||
{
|
||||
start_color();
|
||||
use_default_colors();
|
||||
int num = 1;
|
||||
for (int i = -1; i < 8; i++)
|
||||
# ifdef USE_PDCURSES
|
||||
int i = 0;
|
||||
# else
|
||||
int i = -1;
|
||||
# endif // USE_PDCURSES
|
||||
for (; i < 8; i++)
|
||||
for (int j = 0; j < 8; j++)
|
||||
init_pair(num++, j, i);
|
||||
init_pair(num++, ColorsTable[j], i < 0 ? i : ColorsTable[i]);
|
||||
}
|
||||
noecho();
|
||||
cbreak();
|
||||
@@ -424,7 +439,12 @@ string Window::GetString(const string &base, size_t length, size_t width, bool e
|
||||
input = wgetch(itsWindow);
|
||||
|
||||
// these key codes are special and should be ignored
|
||||
if (input < 10 || (input > 10 && input < 32))
|
||||
if ((input < 10 || (input > 10 && input < 32))
|
||||
# ifdef USE_PDCURSES
|
||||
&& input != 8) // backspace key in pdcurses
|
||||
# else
|
||||
)
|
||||
# endif // USE_PDCURSES
|
||||
continue;
|
||||
|
||||
switch (input)
|
||||
@@ -445,6 +465,9 @@ string Window::GetString(const string &base, size_t length, size_t width, bool e
|
||||
break;
|
||||
}
|
||||
case KEY_BACKSPACE: case 127:
|
||||
# ifdef USE_PDCURSES
|
||||
case 8: // backspace key in pdcurses
|
||||
# endif // USE_PDCURSES
|
||||
{
|
||||
if (x <= minx && !beginning)
|
||||
break;
|
||||
@@ -458,7 +481,11 @@ string Window::GetString(const string &base, size_t length, size_t width, bool e
|
||||
}
|
||||
else if (beginning > 0)
|
||||
beginning--;
|
||||
if (input != KEY_BACKSPACE && input != 127)
|
||||
if (input != KEY_BACKSPACE && input != 127
|
||||
# ifdef USE_PDCURSES
|
||||
&& input != 8 // backspace key in pdcurses
|
||||
# endif // USE_PDCURSES
|
||||
)
|
||||
break; // backspace = left & delete.
|
||||
}
|
||||
case KEY_DC:
|
||||
|
||||
@@ -25,7 +25,11 @@
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "ncurses.h"
|
||||
#ifdef USE_PDCURSES
|
||||
# define XCURSES
|
||||
#endif
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
@@ -55,7 +59,7 @@ namespace NCurses
|
||||
|
||||
typedef void (*GetStringHelper)(const std::wstring &);
|
||||
|
||||
void InitScreen(bool);
|
||||
void InitScreen(const char *, bool);
|
||||
void DestroyScreen();
|
||||
|
||||
struct Colors
|
||||
|
||||
Reference in New Issue
Block a user