summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichał Cichoń <michcic@gmail.com>2015-08-25 18:39:36 +0200
committerMichał Cichoń <michcic@gmail.com>2015-08-25 18:39:36 +0200
commitd5876d68f2676072834c83509f1ee79fb3c48f65 (patch)
treef21aa1ad30b9f99071c148917aa74e0f7fb98816 /src
parent103d71ac2fb3ead96da16d25097f1f559c953fcd (diff)
downloadpianobar-windows-d5876d68f2676072834c83509f1ee79fb3c48f65.tar.gz
pianobar-windows-d5876d68f2676072834c83509f1ee79fb3c48f65.tar.bz2
pianobar-windows-d5876d68f2676072834c83509f1ee79fb3c48f65.zip
Add format_title settings to control Pianobar window title appearance.
Since I'm not aware of any standard method to set title with escape codes explicit mechanism to control window title was introduced.
Diffstat (limited to 'src')
-rw-r--r--src/config.h2
-rw-r--r--src/main.c4
-rw-r--r--src/settings.c5
-rw-r--r--src/settings.h1
-rw-r--r--src/ui.c36
5 files changed, 48 insertions, 0 deletions
diff --git a/src/config.h b/src/config.h
index 2d335a9..2de1cfc 100644
--- a/src/config.h
+++ b/src/config.h
@@ -6,6 +6,8 @@
#define VERSION "2014.09.28-dev"
+#define TITLE "Pianobar"
+
/* Visual C++ name restrict differently */
#ifdef _WIN32
#define restrict __restrict
diff --git a/src/main.c b/src/main.c
index 4569de8..7c6ac08 100644
--- a/src/main.c
+++ b/src/main.c
@@ -247,6 +247,8 @@ static void BarMainPlayerCleanup (BarApp_t *app) {
BarPlayer2Finish(app->player);
+ BarConsoleSetTitle (TITLE);
+
//if (threadRet == (void *) PLAYER_RET_OK) {
// app->playerErrors = 0;
//} else if (threadRet == (void *) PLAYER_RET_SOFTFAIL) {
@@ -340,6 +342,8 @@ int main (int argc, char **argv) {
BarConsoleInit ();
+ BarConsoleSetTitle (TITLE);
+
/* init some things */
BarPlayer2Init (&app.player);
diff --git a/src/settings.c b/src/settings.c
index 297cfbc..6ce55c9 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -128,6 +128,7 @@ void BarSettingsDestroy (BarSettings_t *settings) {
free (settings->npSongFormat);
free (settings->npStationFormat);
free (settings->listSongFormat);
+ free (settings->titleFormat);
free (settings->fifo);
free (settings->rpcHost);
free (settings->rpcTlsPort);
@@ -173,6 +174,7 @@ void BarSettingsRead (BarSettings_t *settings) {
settings->npSongFormat = strdup ("\"%t\" by \"%a\" on \"%l\"%r%@%s");
settings->npStationFormat = strdup ("Station \"%n\" (%i)");
settings->listSongFormat = strdup ("%i) %a - %t%r");
+ settings->titleFormat = strdup (TITLE " - \"%t\" by \"%a\" on \"%l\"%r%@%s");
settings->rpcHost = strdup (PIANO_RPC_HOST);
settings->rpcTlsPort = NULL;
settings->partnerUser = strdup ("android");
@@ -325,6 +327,9 @@ void BarSettingsRead (BarSettings_t *settings) {
} else if (streq ("format_list_song", key)) {
free (settings->listSongFormat);
settings->listSongFormat = strdup (val);
+ } else if (streq ("format_title", key)) {
+ free (settings->titleFormat);
+ settings->titleFormat = strdup (val);
} else if (streq ("fifo", key)) {
free (settings->fifo);
settings->fifo = BarSettingsExpandTilde (val, userhome);
diff --git a/src/settings.h b/src/settings.h
index d0fdbfa..8718b34 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -101,6 +101,7 @@ typedef struct {
char *npSongFormat;
char *npStationFormat;
char *listSongFormat;
+ char *titleFormat;
char *fifo;
char *rpcHost, *rpcTlsPort, *partnerUser, *partnerPassword, *device, *inkey, *outkey, *caBundle;
char keys[BAR_KS_COUNT];
diff --git a/src/ui.c b/src/ui.c
index 962f94c..023a849 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -27,6 +27,7 @@ THE SOFTWARE.
#include "ui.h"
#include "ui_readline.h"
+#include "console.h"
#include <assert.h>
typedef int (*BarSortFunc_t) (const void *, const void *);
@@ -73,6 +74,27 @@ static const char *BarStrCaseStr (const char *haystack, const char *needle) {
return NULL;
}
+char* BatStrFormat (const char* format, va_list args) {
+ static const size_t c_initial_buffer_size = 256;
+
+ char* buffer = malloc(c_initial_buffer_size);
+ size_t buffer_size = c_initial_buffer_size;
+
+ int chars_writen;
+ while ((chars_writen = _vsnprintf(buffer, buffer_size - 1, format, args)) < 0) {
+ size_t new_buffer_size = buffer_size * 3 / 2;
+ if (new_buffer_size < buffer_size) { /* handle overflow */
+ chars_writen = buffer_size;
+ break;
+ }
+
+ buffer = realloc(buffer, new_buffer_size);
+ buffer_size = new_buffer_size;
+ }
+
+ return buffer;
+}
+
/* output message and flush stdout
* @param message
*/
@@ -91,6 +113,7 @@ void BarUiMsg (const BarSettings_t *settings, const BarUiMsg_t type,
case MSG_ERR:
case MSG_QUESTION:
case MSG_LIST:
+ case MSG_DEBUG:
/* print ANSI clear line */
fputs ("\033[2K", stdout);
@@ -106,6 +129,15 @@ void BarUiMsg (const BarSettings_t *settings, const BarUiMsg_t type,
va_start (fmtargs, format);
vprintf (format, fmtargs);
+
+ if (type == MSG_DEBUG) {
+ char* msg = BatStrFormat (format, fmtargs);
+ if (msg != NULL) {
+ BarConsoleSetClipboard (msg);
+ free (msg);
+ }
+ }
+
va_end (fmtargs);
if (settings->msgFormat[type].postfix != NULL) {
@@ -696,6 +728,10 @@ void BarUiPrintSong (const BarSettings_t *settings,
"talr@su", vals);
BarUiAppendNewline (outstr, sizeof (outstr));
BarUiMsg (settings, MSG_PLAYING, "%s", outstr);
+
+ BarUiCustomFormat(outstr, sizeof(outstr), settings->titleFormat,
+ "talr@su", vals);
+ BarConsoleSetTitle(outstr);
}
/* Print list of songs