mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Implemented /time preference
This commit is contained in:
parent
40dc8e2c49
commit
8c027a56f9
@ -80,14 +80,14 @@ buffer_free(ProfBuff buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
buffer_push(ProfBuff buffer, const char show_char, const char * const date_fmt,
|
buffer_push(ProfBuff buffer, const char show_char, GDateTime *time,
|
||||||
int flags, int attrs, const char * const from, const char * const message)
|
int flags, int attrs, const char * const from, const char * const message)
|
||||||
{
|
{
|
||||||
ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t));
|
ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t));
|
||||||
e->show_char = show_char;
|
e->show_char = show_char;
|
||||||
e->flags = flags;
|
e->flags = flags;
|
||||||
e->attrs = attrs;
|
e->attrs = attrs;
|
||||||
e->date_fmt = strdup(date_fmt);
|
e->time = time;
|
||||||
e->from = strdup(from);
|
e->from = strdup(from);
|
||||||
e->message = strdup(message);
|
e->message = strdup(message);
|
||||||
|
|
||||||
@ -111,7 +111,6 @@ _free_entry(ProfBuffEntry *entry)
|
|||||||
{
|
{
|
||||||
free(entry->message);
|
free(entry->message);
|
||||||
free(entry->from);
|
free(entry->from);
|
||||||
free(entry->date_fmt);
|
g_date_time_unref(entry->time);
|
||||||
free(entry);
|
free(entry);
|
||||||
}
|
}
|
||||||
|
|
@ -37,9 +37,11 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
typedef struct prof_buff_entry_t {
|
typedef struct prof_buff_entry_t {
|
||||||
char show_char;
|
char show_char;
|
||||||
char *date_fmt;
|
GDateTime *time;
|
||||||
int flags;
|
int flags;
|
||||||
int attrs;
|
int attrs;
|
||||||
char *from;
|
char *from;
|
||||||
@ -50,7 +52,7 @@ typedef struct prof_buff_t *ProfBuff;
|
|||||||
|
|
||||||
ProfBuff buffer_create();
|
ProfBuff buffer_create();
|
||||||
void buffer_free(ProfBuff buffer);
|
void buffer_free(ProfBuff buffer);
|
||||||
void buffer_push(ProfBuff buffer, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message);
|
void buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, int flags, int attrs, const char * const from, const char * const message);
|
||||||
int buffer_size(ProfBuff buffer);
|
int buffer_size(ProfBuff buffer);
|
||||||
ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry);
|
ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry);
|
||||||
#endif
|
#endif
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
#define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
|
#define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
|
||||||
|
|
||||||
static void _win_print(ProfWin *window, const char show_char, const char * const date_fmt,
|
static void _win_print(ProfWin *window, const char show_char, GDateTime *time,
|
||||||
int flags, int attrs, const char * const from, const char * const message);
|
int flags, int attrs, const char * const from, const char * const message);
|
||||||
static void _win_print_wrapped(WINDOW *win, const char * const message);
|
static void _win_print_wrapped(WINDOW *win, const char * const message);
|
||||||
|
|
||||||
@ -542,21 +542,16 @@ void
|
|||||||
win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp,
|
win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp,
|
||||||
int flags, int attrs, const char * const from, const char * const message)
|
int flags, int attrs, const char * const from, const char * const message)
|
||||||
{
|
{
|
||||||
gchar *date_fmt;
|
|
||||||
GDateTime *time;
|
GDateTime *time;
|
||||||
|
|
||||||
if (tstamp == NULL) {
|
if (tstamp == NULL) {
|
||||||
time = g_date_time_new_now_local();
|
time = g_date_time_new_now_local();
|
||||||
date_fmt = g_date_time_format(time, "%H:%M:%S");
|
|
||||||
} else {
|
} else {
|
||||||
time = g_date_time_new_from_timeval_utc(tstamp);
|
time = g_date_time_new_from_timeval_utc(tstamp);
|
||||||
date_fmt = g_date_time_format(time, "%H:%M:%S");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_date_time_unref(time);
|
buffer_push(window->buffer, show_char, time, flags, attrs, from, message);
|
||||||
buffer_push(window->buffer, show_char, date_fmt, flags, attrs, from, message);
|
_win_print(window, show_char, time, flags, attrs, from, message);
|
||||||
_win_print(window, show_char, date_fmt, flags, attrs, from, message);
|
|
||||||
g_free(date_fmt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -572,18 +567,28 @@ win_save_newline(ProfWin *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_win_print(ProfWin *window, const char show_char, const char * const date_fmt,
|
_win_print(ProfWin *window, const char show_char, GDateTime *time,
|
||||||
int flags, int attrs, const char * const from, const char * const message)
|
int flags, int attrs, const char * const from, const char * const message)
|
||||||
{
|
{
|
||||||
// flags : 1st bit = 0/1 - me/not me
|
// flags : 1st bit = 0/1 - me/not me
|
||||||
// 2nd bit = 0/1 - date/no date
|
// 2nd bit = 0/1 - date/no date
|
||||||
// 3rd bit = 0/1 - eol/no eol
|
// 3rd bit = 0/1 - eol/no eol
|
||||||
// 4th bit = 0/1 - color from/no color from
|
// 4th bit = 0/1 - color from/no color from
|
||||||
|
// 5th bit = 0/1 - color date/no date
|
||||||
int unattr_me = 0;
|
int unattr_me = 0;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int colour = COLOUR_ME;
|
int colour = COLOUR_ME;
|
||||||
|
|
||||||
if ((flags & NO_DATE) == 0) {
|
if ((flags & NO_DATE) == 0) {
|
||||||
|
gchar *date_fmt;
|
||||||
|
char *time_pref = prefs_get_string(PREF_TIME);
|
||||||
|
if (g_strcmp0(time_pref, "minutes") == 0) {
|
||||||
|
date_fmt = g_date_time_format(time, "%H:%M");
|
||||||
|
} else {
|
||||||
|
date_fmt = g_date_time_format(time, "%H:%M:%S");
|
||||||
|
}
|
||||||
|
free(time_pref);
|
||||||
|
|
||||||
if ((flags & NO_COLOUR_DATE) == 0) {
|
if ((flags & NO_COLOUR_DATE) == 0) {
|
||||||
wattron(window->win, COLOUR_TIME);
|
wattron(window->win, COLOUR_TIME);
|
||||||
}
|
}
|
||||||
@ -591,6 +596,7 @@ _win_print(ProfWin *window, const char show_char, const char * const date_fmt,
|
|||||||
if ((flags & NO_COLOUR_DATE) == 0) {
|
if ((flags & NO_COLOUR_DATE) == 0) {
|
||||||
wattroff(window->win, COLOUR_TIME);
|
wattroff(window->win, COLOUR_TIME);
|
||||||
}
|
}
|
||||||
|
g_free(date_fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(from) > 0) {
|
if (strlen(from) > 0) {
|
||||||
@ -635,16 +641,29 @@ _win_print(ProfWin *window, const char show_char, const char * const date_fmt,
|
|||||||
static void
|
static void
|
||||||
_win_print_wrapped(WINDOW *win, const char * const message)
|
_win_print_wrapped(WINDOW *win, const char * const message)
|
||||||
{
|
{
|
||||||
|
int i = 0;
|
||||||
int linei = 0;
|
int linei = 0;
|
||||||
int wordi = 0;
|
int wordi = 0;
|
||||||
char *word = malloc(strlen(message) + 1);
|
char *word = malloc(strlen(message) + 1);
|
||||||
|
|
||||||
|
char *time_pref = prefs_get_string(PREF_TIME);
|
||||||
|
int wrap_space = 0;
|
||||||
|
if (g_strcmp0(time_pref, "minutes") == 0) {
|
||||||
|
wrap_space = 8;
|
||||||
|
} else {
|
||||||
|
wrap_space = 11;
|
||||||
|
}
|
||||||
|
free(time_pref);
|
||||||
|
|
||||||
while (message[linei] != '\0') {
|
while (message[linei] != '\0') {
|
||||||
if (message[linei] == ' ') {
|
if (message[linei] == ' ') {
|
||||||
wprintw(win, " ");
|
wprintw(win, " ");
|
||||||
linei++;
|
linei++;
|
||||||
} else if (message[linei] == '\n') {
|
} else if (message[linei] == '\n') {
|
||||||
wprintw(win, "\n ");
|
waddch(win, '\n');
|
||||||
|
for (i = 0; i < wrap_space; i++) {
|
||||||
|
waddch(win, ' ');
|
||||||
|
}
|
||||||
linei++;
|
linei++;
|
||||||
} else {
|
} else {
|
||||||
wordi = 0;
|
wordi = 0;
|
||||||
@ -657,21 +676,28 @@ _win_print_wrapped(WINDOW *win, const char * const message)
|
|||||||
int maxx = getmaxx(win);
|
int maxx = getmaxx(win);
|
||||||
|
|
||||||
// word larger than line
|
// word larger than line
|
||||||
if (strlen(word) > (maxx - 11)) {
|
if (strlen(word) > (maxx - wrap_space)) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < wordi; i++) {
|
for (i = 0; i < wordi; i++) {
|
||||||
curx = getcurx(win);
|
curx = getcurx(win);
|
||||||
if (curx < 11) {
|
if (curx < wrap_space) {
|
||||||
wprintw(win, " ");
|
for (i = 0; i < wrap_space; i++) {
|
||||||
|
waddch(win, ' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
waddch(win, word[i]);
|
waddch(win, word[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (curx + strlen(word) > maxx) {
|
if (curx + strlen(word) > maxx) {
|
||||||
wprintw(win, "\n ");
|
waddch(win, '\n');
|
||||||
|
for (i = 0; i < wrap_space; i++) {
|
||||||
|
waddch(win, ' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (curx < 11) {
|
if (curx < wrap_space) {
|
||||||
wprintw(win, " ");
|
for (i = 0; i < wrap_space; i++) {
|
||||||
|
waddch(win, ' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
wprintw(win, "%s", word);
|
wprintw(win, "%s", word);
|
||||||
}
|
}
|
||||||
@ -690,7 +716,7 @@ win_redraw(ProfWin *window)
|
|||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
ProfBuffEntry *e = buffer_yield_entry(window->buffer, i);
|
ProfBuffEntry *e = buffer_yield_entry(window->buffer, i);
|
||||||
_win_print(window, e->show_char, e->date_fmt, e->flags, e->attrs, e->from, e->message);
|
_win_print(window, e->show_char, e->time, e->flags, e->attrs, e->from, e->message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user