summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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