2014-03-24 12:18:58 +01:00
|
|
|
/* line_info.c
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Toxic All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Toxic.
|
|
|
|
*
|
|
|
|
* Toxic is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Toxic is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
2014-07-25 04:43:32 +02:00
|
|
|
#include <stdarg.h>
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-12 00:06:55 +02:00
|
|
|
#include "toxic.h"
|
|
|
|
#include "windows.h"
|
2014-03-24 12:18:58 +01:00
|
|
|
#include "line_info.h"
|
2014-03-26 02:43:49 +01:00
|
|
|
#include "groupchat.h"
|
2014-05-26 01:54:34 +02:00
|
|
|
#include "settings.h"
|
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
extern struct user_settings *user_settings_;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
|
|
|
void line_info_init(struct history *hst)
|
|
|
|
{
|
2014-07-06 07:46:07 +02:00
|
|
|
hst->line_root = calloc(1, sizeof(struct line_info));
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-18 21:54:05 +02:00
|
|
|
if (hst->line_root == NULL)
|
|
|
|
exit_toxic_err("failed in line_info_init", FATALERR_MEMORY);
|
2014-03-24 12:18:58 +01:00
|
|
|
|
|
|
|
hst->line_start = hst->line_root;
|
|
|
|
hst->line_end = hst->line_start;
|
2014-06-14 07:43:59 +02:00
|
|
|
hst->queue_sz = 0;
|
2014-03-24 12:18:58 +01:00
|
|
|
}
|
|
|
|
|
2014-07-06 07:46:07 +02:00
|
|
|
/* resets line_start (page end) */
|
2014-06-13 21:37:04 +02:00
|
|
|
static void line_info_reset_start(ToxWindow *self, struct history *hst)
|
2014-03-24 12:18:58 +01:00
|
|
|
{
|
2014-07-06 07:46:07 +02:00
|
|
|
struct line_info *line = hst->line_end;
|
|
|
|
|
|
|
|
if (line->prev == NULL)
|
|
|
|
return;
|
|
|
|
|
2014-06-13 21:37:04 +02:00
|
|
|
int y2, x2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-13 23:37:11 +02:00
|
|
|
int side_offst = self->is_groupchat ? SIDEBAR_WIDTH : 0;
|
2014-07-06 07:46:07 +02:00
|
|
|
int top_offst = self->is_chat || self->is_prompt ? 2 : 0;
|
2014-06-13 23:37:11 +02:00
|
|
|
int max_y = (y2 - CHATBOX_HEIGHT - top_offst);
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-07-06 07:46:07 +02:00
|
|
|
int curlines = 0;
|
|
|
|
int nxtlines = line->newlines + (line->len / (x2 - side_offst));
|
|
|
|
|
|
|
|
do {
|
|
|
|
curlines += 1 + nxtlines;
|
2014-03-24 12:18:58 +01:00
|
|
|
line = line->prev;
|
2014-07-06 07:46:07 +02:00
|
|
|
nxtlines = line->newlines + (line->len / (x2 - side_offst));
|
|
|
|
} while (line->prev && curlines + nxtlines < max_y);
|
2014-06-13 21:37:04 +02:00
|
|
|
|
|
|
|
hst->line_start = line;
|
2014-03-24 12:18:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void line_info_cleanup(struct history *hst)
|
|
|
|
{
|
|
|
|
struct line_info *tmp1 = hst->line_root;
|
|
|
|
|
|
|
|
while (tmp1) {
|
|
|
|
struct line_info *tmp2 = tmp1->next;
|
|
|
|
free(tmp1);
|
|
|
|
tmp1 = tmp2;
|
|
|
|
}
|
2014-07-09 01:24:44 +02:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < hst->queue_sz; ++i) {
|
|
|
|
if (hst->queue[i])
|
|
|
|
free(hst->queue[i]);
|
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
}
|
|
|
|
|
2014-04-01 03:26:09 +02:00
|
|
|
/* moves root forward and frees previous root */
|
|
|
|
static void line_info_root_fwd(struct history *hst)
|
|
|
|
{
|
|
|
|
struct line_info *tmp = hst->line_root->next;
|
|
|
|
tmp->prev = NULL;
|
|
|
|
|
|
|
|
if (hst->line_start->prev == NULL) { /* if line_start is root move it forward as well */
|
|
|
|
hst->line_start = hst->line_start->next;
|
|
|
|
hst->line_start->prev = NULL;
|
|
|
|
++hst->start_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(hst->line_root);
|
|
|
|
hst->line_root = tmp;
|
|
|
|
}
|
|
|
|
|
2014-06-14 07:43:59 +02:00
|
|
|
/* adds a line_info line to queue */
|
|
|
|
static void line_info_add_queue(struct history *hst, struct line_info *line)
|
|
|
|
{
|
|
|
|
if (hst->queue_sz >= MAX_QUEUE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hst->queue[hst->queue_sz++] = line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns ptr to queue item 0 and removes it from queue */
|
|
|
|
static struct line_info *line_info_ret_queue(struct history *hst)
|
|
|
|
{
|
|
|
|
if (hst->queue_sz <= 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
struct line_info *ret = hst->queue[0];
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < hst->queue_sz; ++i)
|
|
|
|
hst->queue[i] = hst->queue[i + 1];
|
|
|
|
|
|
|
|
--hst->queue_sz;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-14 20:09:20 +02:00
|
|
|
/* creates new line_info line and puts it in the queue */
|
2014-07-25 04:43:32 +02:00
|
|
|
void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, uint8_t type, uint8_t bold,
|
|
|
|
uint8_t colour, const char *msg, ...)
|
2014-03-24 12:18:58 +01:00
|
|
|
{
|
|
|
|
struct history *hst = self->chatwin->hst;
|
2014-07-06 07:46:07 +02:00
|
|
|
struct line_info *new_line = calloc(1, sizeof(struct line_info));
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-18 21:54:05 +02:00
|
|
|
if (new_line == NULL)
|
|
|
|
exit_toxic_err("failed in line_info_add", FATALERR_MEMORY);
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-07-25 04:43:32 +02:00
|
|
|
char frmt_msg[MAX_STR_SIZE] = {0};
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, msg);
|
|
|
|
vsnprintf(frmt_msg, sizeof(frmt_msg), msg, args);
|
|
|
|
va_end(args);
|
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
int len = 1; /* there will always be a newline */
|
|
|
|
|
|
|
|
/* for type-specific formatting in print function */
|
2014-03-25 13:21:50 +01:00
|
|
|
switch (type) {
|
2014-04-19 23:58:13 +02:00
|
|
|
case ACTION:
|
2014-06-14 20:09:20 +02:00
|
|
|
case CONNECTION:
|
2014-04-19 23:58:13 +02:00
|
|
|
len += 3;
|
|
|
|
break;
|
|
|
|
|
2014-06-14 20:09:20 +02:00
|
|
|
case SYS_MSG:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROMPT:
|
|
|
|
++len;
|
|
|
|
break;
|
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
default:
|
|
|
|
len += 2;
|
|
|
|
break;
|
2014-03-24 12:18:58 +01:00
|
|
|
}
|
|
|
|
|
2014-07-25 04:43:32 +02:00
|
|
|
if (frmt_msg[0]) {
|
|
|
|
snprintf(new_line->msg, sizeof(new_line->msg), "%s", frmt_msg);
|
2014-06-01 18:54:45 +02:00
|
|
|
len += strlen(new_line->msg);
|
2014-06-14 08:54:58 +02:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2014-07-25 04:43:32 +02:00
|
|
|
for (i = 0; frmt_msg[i]; ++i) {
|
|
|
|
if (frmt_msg[i] == '\n')
|
2014-06-14 08:54:58 +02:00
|
|
|
++new_line->newlines;
|
|
|
|
}
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tmstmp) {
|
2014-06-01 18:54:45 +02:00
|
|
|
snprintf(new_line->timestamp, sizeof(new_line->timestamp), "%s", tmstmp);
|
|
|
|
len += strlen(new_line->timestamp);
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name1) {
|
2014-06-01 18:54:45 +02:00
|
|
|
snprintf(new_line->name1, sizeof(new_line->name1), "%s", name1);
|
|
|
|
len += strlen(new_line->name1);
|
2014-04-19 23:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (name2) {
|
2014-06-01 18:54:45 +02:00
|
|
|
snprintf(new_line->name2, sizeof(new_line->name2), "%s", name2);
|
|
|
|
len += strlen(new_line->name2);
|
2014-03-24 12:18:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
new_line->len = len;
|
2014-03-25 13:21:50 +01:00
|
|
|
new_line->type = type;
|
2014-03-24 12:18:58 +01:00
|
|
|
new_line->bold = bold;
|
|
|
|
new_line->colour = colour;
|
|
|
|
|
2014-06-14 07:43:59 +02:00
|
|
|
line_info_add_queue(hst, new_line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adds a single queue item to hst if possible. only called once per call to line_info_print() */
|
|
|
|
static void line_info_check_queue(ToxWindow *self)
|
|
|
|
{
|
|
|
|
struct history *hst = self->chatwin->hst;
|
|
|
|
struct line_info *line = line_info_ret_queue(hst);
|
|
|
|
|
|
|
|
if (line == NULL)
|
|
|
|
return;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
if (hst->start_id > user_settings_->history_size)
|
2014-04-01 03:26:09 +02:00
|
|
|
line_info_root_fwd(hst);
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-06-14 07:43:59 +02:00
|
|
|
line->id = hst->line_end->id + 1;
|
|
|
|
line->prev = hst->line_end;
|
|
|
|
hst->line_end->next = line;
|
|
|
|
hst->line_end = line;
|
2014-03-26 02:43:49 +01:00
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
int y, y2, x, x2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-03-25 08:17:22 +01:00
|
|
|
getyx(self->chatwin->history, y, x);
|
2014-07-07 04:15:35 +02:00
|
|
|
(void) x;
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-03-27 00:14:28 +01:00
|
|
|
if (x2 <= SIDEBAR_WIDTH)
|
|
|
|
return;
|
|
|
|
|
2014-03-26 02:43:49 +01:00
|
|
|
int offst = self->is_groupchat ? SIDEBAR_WIDTH : 0; /* offset width of groupchat sidebar */
|
2014-06-14 08:54:58 +02:00
|
|
|
int lines = 1 + line->newlines + (line->len / (x2 - offst));
|
2014-06-29 00:40:22 +02:00
|
|
|
int max_y = y2 - CHATBOX_HEIGHT;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-03-26 02:43:49 +01:00
|
|
|
/* move line_start forward proportionate to the number of new lines */
|
2014-06-14 08:54:58 +02:00
|
|
|
if (y + lines - 1 >= max_y) {
|
|
|
|
while (lines > 0 && hst->line_start->next) {
|
2014-06-19 00:29:07 +02:00
|
|
|
lines -= 1 + hst->line_start->next->newlines + (hst->line_start->next->len / (x2 - offst));
|
2014-06-14 08:54:58 +02:00
|
|
|
hst->line_start = hst->line_start->next;
|
2014-03-24 12:18:58 +01:00
|
|
|
++hst->start_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void line_info_print(ToxWindow *self)
|
|
|
|
{
|
|
|
|
ChatContext *ctx = self->chatwin;
|
2014-06-01 09:38:20 +02:00
|
|
|
|
|
|
|
if (ctx == NULL)
|
|
|
|
return;
|
|
|
|
|
2014-06-14 07:43:59 +02:00
|
|
|
struct history *hst = ctx->hst;
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-06-14 07:43:59 +02:00
|
|
|
/* Only allow one new item to be added to chat window per call to this function */
|
|
|
|
line_info_check_queue(self);
|
2014-03-28 22:33:23 +01:00
|
|
|
|
2014-06-14 07:43:59 +02:00
|
|
|
WINDOW *win = ctx->history;
|
2014-03-24 12:37:52 +01:00
|
|
|
wclear(win);
|
2014-03-24 12:18:58 +01:00
|
|
|
int y2, x2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
|
|
|
|
2014-03-27 00:14:28 +01:00
|
|
|
if (x2 <= SIDEBAR_WIDTH)
|
|
|
|
return;
|
|
|
|
|
2014-03-25 13:21:50 +01:00
|
|
|
if (self->is_groupchat)
|
|
|
|
wmove(win, 0, 0);
|
|
|
|
else
|
|
|
|
wmove(win, 2, 0);
|
|
|
|
|
2014-06-14 07:43:59 +02:00
|
|
|
struct line_info *line = hst->line_start->next;
|
2014-03-24 12:18:58 +01:00
|
|
|
int numlines = 0;
|
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
while (line && numlines++ <= y2) {
|
2014-03-25 13:21:50 +01:00
|
|
|
uint8_t type = line->type;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
|
|
|
switch (type) {
|
2014-04-19 23:58:13 +02:00
|
|
|
case OUT_MSG:
|
|
|
|
case IN_MSG:
|
|
|
|
wattron(win, COLOR_PAIR(BLUE));
|
|
|
|
wprintw(win, "%s", line->timestamp);
|
|
|
|
wattroff(win, COLOR_PAIR(BLUE));
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
int nameclr = GREEN;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
if (line->colour)
|
|
|
|
nameclr = line->colour;
|
|
|
|
else if (type == IN_MSG)
|
|
|
|
nameclr = CYAN;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
wattron(win, COLOR_PAIR(nameclr));
|
|
|
|
wprintw(win, "%s: ", line->name1);
|
|
|
|
wattroff(win, COLOR_PAIR(nameclr));
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
if (line->msg[0] == '>')
|
|
|
|
wattron(win, COLOR_PAIR(GREEN));
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
wprintw(win, "%s\n", line->msg);
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
if (line->msg[0] == '>')
|
|
|
|
wattroff(win, COLOR_PAIR(GREEN));
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
break;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
case ACTION:
|
2014-03-24 12:37:52 +01:00
|
|
|
wattron(win, COLOR_PAIR(BLUE));
|
|
|
|
wprintw(win, "%s", line->timestamp);
|
|
|
|
wattroff(win, COLOR_PAIR(BLUE));
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
wattron(win, COLOR_PAIR(YELLOW));
|
|
|
|
wprintw(win, "* %s %s\n", line->name1, line->msg);
|
|
|
|
wattroff(win, COLOR_PAIR(YELLOW));
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
break;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
case SYS_MSG:
|
|
|
|
if (line->timestamp[0]) {
|
|
|
|
wattron(win, COLOR_PAIR(BLUE));
|
|
|
|
wprintw(win, "%s", line->timestamp);
|
|
|
|
wattroff(win, COLOR_PAIR(BLUE));
|
|
|
|
}
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
if (line->bold)
|
|
|
|
wattron(win, A_BOLD);
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
if (line->colour)
|
|
|
|
wattron(win, COLOR_PAIR(line->colour));
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
wprintw(win, "%s\n", line->msg);
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
if (line->bold)
|
|
|
|
wattroff(win, A_BOLD);
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
if (line->colour)
|
|
|
|
wattroff(win, COLOR_PAIR(line->colour));
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
break;
|
2014-03-25 08:17:22 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
case PROMPT:
|
|
|
|
wattron(win, COLOR_PAIR(GREEN));
|
|
|
|
wprintw(win, "$ ");
|
|
|
|
wattroff(win, COLOR_PAIR(GREEN));
|
|
|
|
|
|
|
|
if (line->msg[0])
|
|
|
|
wprintw(win, "%s", line->msg);
|
2014-03-25 13:21:50 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
wprintw(win, "\n");
|
|
|
|
break;
|
2014-03-25 13:21:50 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
case CONNECTION:
|
|
|
|
wattron(win, COLOR_PAIR(BLUE));
|
|
|
|
wprintw(win, "%s", line->timestamp);
|
|
|
|
wattroff(win, COLOR_PAIR(BLUE));
|
2014-03-25 13:21:50 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
wattron(win, COLOR_PAIR(line->colour));
|
|
|
|
wattron(win, A_BOLD);
|
|
|
|
wprintw(win, "* %s ", line->name1);
|
|
|
|
wattroff(win, A_BOLD);
|
|
|
|
wprintw(win, "%s\n", line->msg);
|
|
|
|
wattroff(win, COLOR_PAIR(line->colour));
|
2014-03-25 13:21:50 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
break;
|
2014-03-25 13:21:50 +01:00
|
|
|
|
2014-04-19 23:58:13 +02:00
|
|
|
case NAME_CHANGE:
|
|
|
|
wattron(win, COLOR_PAIR(BLUE));
|
|
|
|
wprintw(win, "%s", line->timestamp);
|
|
|
|
wattroff(win, COLOR_PAIR(BLUE));
|
|
|
|
|
|
|
|
wattron(win, COLOR_PAIR(MAGENTA));
|
|
|
|
wattron(win, A_BOLD);
|
|
|
|
wprintw(win, "* %s", line->name1);
|
|
|
|
wattroff(win, A_BOLD);
|
|
|
|
|
|
|
|
wprintw(win, "%s", line->msg);
|
|
|
|
|
|
|
|
wattron(win, A_BOLD);
|
|
|
|
wprintw(win, "%s\n", line->name2);
|
|
|
|
wattroff(win, A_BOLD);
|
|
|
|
wattroff(win, COLOR_PAIR(MAGENTA));
|
|
|
|
|
|
|
|
break;
|
2014-03-24 12:18:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
line = line->next;
|
|
|
|
}
|
2014-06-14 07:43:59 +02:00
|
|
|
|
|
|
|
/* keep calling until queue is empty */
|
|
|
|
if (hst->queue_sz > 0)
|
|
|
|
line_info_print(self);
|
2014-03-24 12:18:58 +01:00
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
void line_info_set(ToxWindow *self, uint32_t id, char *msg)
|
2014-03-28 04:05:50 +01:00
|
|
|
{
|
|
|
|
struct line_info *line = self->chatwin->hst->line_end;
|
|
|
|
|
|
|
|
while (line) {
|
|
|
|
if (line->id == id) {
|
|
|
|
snprintf(line->msg, sizeof(line->msg), "%s", msg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
line = line->prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-07 04:15:35 +02:00
|
|
|
/* static void line_info_goto_root(struct history *hst)
|
2014-03-24 12:18:58 +01:00
|
|
|
{
|
|
|
|
hst->line_start = hst->line_root;
|
2014-07-07 04:15:35 +02:00
|
|
|
} */
|
2014-03-24 12:18:58 +01:00
|
|
|
|
|
|
|
static void line_info_scroll_up(struct history *hst)
|
|
|
|
{
|
|
|
|
if (hst->line_start->prev)
|
|
|
|
hst->line_start = hst->line_start->prev;
|
|
|
|
else beep();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void line_info_scroll_down(struct history *hst)
|
|
|
|
{
|
|
|
|
if (hst->line_start->next)
|
|
|
|
hst->line_start = hst->line_start->next;
|
|
|
|
else beep();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void line_info_page_up(ToxWindow *self, struct history *hst)
|
|
|
|
{
|
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-07-07 04:15:35 +02:00
|
|
|
(void) x2;
|
2014-03-24 12:18:58 +01:00
|
|
|
int jump_dist = y2 / 2;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < jump_dist && hst->line_start->prev; ++i)
|
|
|
|
hst->line_start = hst->line_start->prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void line_info_page_down(ToxWindow *self, struct history *hst)
|
|
|
|
{
|
|
|
|
int x2, y2;
|
|
|
|
getmaxyx(self->window, y2, x2);
|
2014-07-07 04:15:35 +02:00
|
|
|
(void) x2;
|
2014-03-24 12:18:58 +01:00
|
|
|
int jump_dist = y2 / 2;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < jump_dist && hst->line_start->next; ++i)
|
|
|
|
hst->line_start = hst->line_start->next;
|
|
|
|
}
|
|
|
|
|
2014-06-13 07:42:20 +02:00
|
|
|
bool line_info_onKey(ToxWindow *self, wint_t key)
|
2014-03-24 12:18:58 +01:00
|
|
|
{
|
|
|
|
struct history *hst = self->chatwin->hst;
|
2014-06-13 07:42:20 +02:00
|
|
|
bool match = true;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
|
|
|
switch (key) {
|
2014-06-19 02:07:34 +02:00
|
|
|
/* TODO: Find good key bindings for all this stuff */
|
2014-06-20 20:27:33 +02:00
|
|
|
case T_KEY_C_F:
|
2014-04-19 23:58:13 +02:00
|
|
|
line_info_page_up(self, hst);
|
|
|
|
break;
|
|
|
|
|
2014-06-20 20:27:33 +02:00
|
|
|
case T_KEY_C_V:
|
2014-04-19 23:58:13 +02:00
|
|
|
line_info_page_down(self, hst);
|
2014-06-19 02:07:34 +02:00
|
|
|
break;
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-06-13 07:42:20 +02:00
|
|
|
case KEY_PPAGE:
|
2014-04-19 23:58:13 +02:00
|
|
|
line_info_scroll_up(hst);
|
|
|
|
break;
|
|
|
|
|
2014-06-13 07:42:20 +02:00
|
|
|
case KEY_NPAGE:
|
2014-04-19 23:58:13 +02:00
|
|
|
line_info_scroll_down(hst);
|
|
|
|
break;
|
|
|
|
|
2014-06-19 02:07:34 +02:00
|
|
|
/* case ?:
|
2014-04-19 23:58:13 +02:00
|
|
|
line_info_goto_root(hst);
|
2014-06-20 20:27:33 +02:00
|
|
|
break; */
|
2014-04-19 23:58:13 +02:00
|
|
|
|
2014-06-20 20:27:33 +02:00
|
|
|
case T_KEY_C_H:
|
2014-06-13 21:37:04 +02:00
|
|
|
line_info_reset_start(self, hst);
|
2014-06-20 20:27:33 +02:00
|
|
|
break;
|
2014-03-26 02:43:49 +01:00
|
|
|
|
2014-06-13 07:42:20 +02:00
|
|
|
default:
|
|
|
|
match = false;
|
|
|
|
break;
|
|
|
|
}
|
2014-03-27 10:08:48 +01:00
|
|
|
|
2014-06-13 07:42:20 +02:00
|
|
|
return match;
|
2014-03-27 10:08:48 +01:00
|
|
|
}
|
|
|
|
|
2014-03-26 02:43:49 +01:00
|
|
|
void line_info_clear(struct history *hst)
|
|
|
|
{
|
|
|
|
hst->line_start = hst->line_end;
|
2014-03-27 00:14:28 +01:00
|
|
|
hst->start_id = hst->line_start->id;
|
2014-03-26 02:43:49 +01:00
|
|
|
}
|