mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Implemented the buffer for windows resizing
This commit is contained in:
parent
dada879347
commit
945d655910
@ -23,6 +23,15 @@ buffer_create() {
|
|||||||
return new_buff;
|
return new_buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int buffer_size(ProfBuff* buffer) {
|
||||||
|
if(buffer->wrap == 1) {
|
||||||
|
return BUFF_SIZE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return buffer->current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
buffer_free(ProfBuff* buffer) {
|
buffer_free(ProfBuff* buffer) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -33,29 +42,32 @@ buffer_free(ProfBuff* buffer) {
|
|||||||
for(i = 0; i < imax; i++) {
|
for(i = 0; i < imax; i++) {
|
||||||
free(buffer->entry[i].message);
|
free(buffer->entry[i].message);
|
||||||
free(buffer->entry[i].from);
|
free(buffer->entry[i].from);
|
||||||
|
free(buffer->entry[i].date_fmt);
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
buffer_push(ProfBuff* buffer, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message) {
|
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) {
|
||||||
int *current = &(buffer->current);
|
int *current = &(buffer->current);
|
||||||
ProfBuffEntry e = buffer->entry[*current];
|
ProfBuffEntry* e = &(buffer->entry[buffer->current]);
|
||||||
|
|
||||||
if(buffer->wrap == 1) {
|
if(buffer->wrap == 1) {
|
||||||
free(e.message);
|
free(e->message);
|
||||||
free(e.from);
|
free(e->from);
|
||||||
}
|
}
|
||||||
e.show_char = show_char;
|
e->show_char = show_char;
|
||||||
e.tstamp = *tstamp;
|
e->flags = flags;
|
||||||
e.flags = flags;
|
e->attrs = attrs;
|
||||||
e.attrs = attrs;
|
|
||||||
|
|
||||||
e.from = malloc(strlen(from)+1);
|
e->date_fmt = malloc(strlen(date_fmt)+1);
|
||||||
strcpy(e.from, from);
|
strcpy(e->date_fmt, date_fmt);
|
||||||
|
|
||||||
e.message = malloc(strlen(message)+1);
|
e->from = malloc(strlen(from)+1);
|
||||||
strcpy(e.message, message);
|
strcpy(e->from, from);
|
||||||
|
|
||||||
|
e->message = malloc(strlen(message)+1);
|
||||||
|
strcpy(e->message, message);
|
||||||
|
|
||||||
*current += 1;
|
*current += 1;
|
||||||
if(*current >= BUFF_SIZE) {
|
if(*current >= BUFF_SIZE) {
|
||||||
@ -64,11 +76,22 @@ buffer_push(ProfBuff* buffer, const char show_char, GTimeVal *tstamp, int flags,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProfBuffEntry
|
||||||
|
buffer_yield_entry(ProfBuff* buffer, int entry) {
|
||||||
|
return (buffer->entry)[entry];
|
||||||
|
if(buffer->wrap == 1) {
|
||||||
|
return buffer->entry[(buffer->current + entry) % BUFF_SIZE];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return buffer->entry[entry % (buffer->current)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list) {
|
buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list) {
|
||||||
//Returns the (line+1)-th last line
|
//Returns the size of the (line+1)-th last line, and list contains the line
|
||||||
//e.g. if line == 0, returns the last line
|
//e.g. if line == 0, returns the last line
|
||||||
//To correct for splitted lines...
|
//bug if the wrap happens in the middle of a line
|
||||||
int current = buffer->current;
|
int current = buffer->current;
|
||||||
int imax = current;
|
int imax = current;
|
||||||
if(buffer->wrap == 1) {
|
if(buffer->wrap == 1) {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
typedef struct prof_buff_entry_t {
|
typedef struct prof_buff_entry_t {
|
||||||
char show_char;
|
char show_char;
|
||||||
GTimeVal tstamp;
|
char *date_fmt;
|
||||||
int flags;
|
int flags;
|
||||||
int attrs;
|
int attrs;
|
||||||
char *from;
|
char *from;
|
||||||
@ -24,6 +24,8 @@ typedef struct prof_buff_t {
|
|||||||
|
|
||||||
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, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message);
|
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);
|
||||||
|
int buffer_size(ProfBuff* buffer);
|
||||||
int buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list);
|
int buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list);
|
||||||
|
ProfBuffEntry buffer_yield_entry(ProfBuff* buffer, int entry);
|
||||||
#endif
|
#endif
|
||||||
|
@ -340,14 +340,8 @@ void win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, in
|
|||||||
win_save_print(window, show_char, tstamp, flags, attrs, from, fmt_msg->str);
|
win_save_print(window, show_char, tstamp, flags, attrs, from, fmt_msg->str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message) {
|
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message) {
|
||||||
// flags : 1st bit = 0/1 - me/not me
|
|
||||||
// 2nd bit = 0/1 - date/no date
|
|
||||||
// 3rd bit = 0/1 - eol/no eol
|
|
||||||
// 4th bit = 0/1 - color from/no color from
|
|
||||||
int unattr_me = 0;
|
|
||||||
int offset = 0;
|
|
||||||
int colour = COLOUR_ME;
|
|
||||||
gchar *date_fmt;
|
gchar *date_fmt;
|
||||||
GDateTime *time;
|
GDateTime *time;
|
||||||
if(tstamp == NULL) {
|
if(tstamp == NULL) {
|
||||||
@ -359,13 +353,25 @@ void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int
|
|||||||
date_fmt = g_date_time_format(time, "%H:%M:%S");
|
date_fmt = g_date_time_format(time, "%H:%M:%S");
|
||||||
}
|
}
|
||||||
g_date_time_unref(time);
|
g_date_time_unref(time);
|
||||||
buffer_push(window->buffer, show_char, tstamp, flags, attrs, from, message);
|
buffer_push(window->buffer, show_char, date_fmt, flags, attrs, from, message);
|
||||||
|
win_print(window, show_char, date_fmt, flags, attrs, from, message);
|
||||||
|
g_free(date_fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void win_print(ProfWin *window, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message) {
|
||||||
|
// flags : 1st bit = 0/1 - me/not me
|
||||||
|
// 2nd bit = 0/1 - date/no date
|
||||||
|
// 3rd bit = 0/1 - eol/no eol
|
||||||
|
// 4th bit = 0/1 - color from/no color from
|
||||||
|
int unattr_me = 0;
|
||||||
|
int offset = 0;
|
||||||
|
int colour = COLOUR_ME;
|
||||||
if((flags & 2) == 0) {
|
if((flags & 2) == 0) {
|
||||||
wattron(window->win, COLOUR_TIME);
|
wattron(window->win, COLOUR_TIME);
|
||||||
wprintw(window->win, "%s %c ", date_fmt, show_char);
|
wprintw(window->win, "%s %c ", date_fmt, show_char);
|
||||||
wattroff(window->win, COLOUR_TIME);
|
wattroff(window->win, COLOUR_TIME);
|
||||||
}
|
}
|
||||||
g_free(date_fmt);
|
|
||||||
|
|
||||||
if(strlen(from) > 0) {
|
if(strlen(from) > 0) {
|
||||||
if((flags & 1) != 0) {
|
if((flags & 1) != 0) {
|
||||||
@ -396,3 +402,13 @@ void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int
|
|||||||
wattroff(window->win, colour);
|
wattroff(window->win, colour);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void win_redraw(ProfWin *window) {
|
||||||
|
int i, size;
|
||||||
|
werase(window->win);
|
||||||
|
size = buffer_size(window->buffer);
|
||||||
|
for(i = 0; i < size; 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -80,5 +80,7 @@ void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
|
|||||||
void win_show_info(ProfWin *window, PContact contact);
|
void win_show_info(ProfWin *window, PContact contact);
|
||||||
void win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message, ...);
|
void win_save_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message, ...);
|
||||||
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message);
|
void win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, int attrs, const char * const from, const char * const message);
|
||||||
|
void win_print(ProfWin *window, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message);
|
||||||
|
void win_redraw(ProfWin *window);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -272,20 +272,15 @@ wins_resize_all(void)
|
|||||||
int rows, cols;
|
int rows, cols;
|
||||||
getmaxyx(stdscr, rows, cols);
|
getmaxyx(stdscr, rows, cols);
|
||||||
|
|
||||||
// only make the pads bigger, to avoid data loss on cropping
|
|
||||||
if (cols > max_cols) {
|
|
||||||
max_cols = cols;
|
|
||||||
|
|
||||||
GList *values = g_hash_table_get_values(windows);
|
GList *values = g_hash_table_get_values(windows);
|
||||||
GList *curr = values;
|
GList *curr = values;
|
||||||
|
|
||||||
while (curr != NULL) {
|
while (curr != NULL) {
|
||||||
ProfWin *window = curr->data;
|
ProfWin *window = curr->data;
|
||||||
wresize(window->win, PAD_SIZE, cols);
|
wresize(window->win, PAD_SIZE, cols);
|
||||||
|
win_redraw(window);
|
||||||
curr = g_list_next(curr);
|
curr = g_list_next(curr);
|
||||||
}
|
}
|
||||||
g_list_free(values);
|
g_list_free(values);
|
||||||
}
|
|
||||||
|
|
||||||
ProfWin *current_win = wins_get_current();
|
ProfWin *current_win = wins_get_current();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user