mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 07:13:25 +01:00
Merge pull request #215 from plutooo/master
toxic: Made everything 1000x more userfriendly.
This commit is contained in:
commit
e72ff9de6d
27
chat.c
27
chat.c
@ -1,3 +1,7 @@
|
||||
/*
|
||||
* Toxic -- Tox Curses Client
|
||||
*/
|
||||
|
||||
#include <curses.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -38,7 +42,13 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len)
|
||||
fix_name(msg);
|
||||
fix_name(nick);
|
||||
|
||||
wprintw(ctx->history, "%s: %s\n", nick, msg);
|
||||
wattron(ctx->history, COLOR_PAIR(4));
|
||||
wprintw(ctx->history, "%s: ", nick);
|
||||
wattroff(ctx->history, COLOR_PAIR(4));
|
||||
|
||||
wprintw(ctx->history, "%s\n", msg);
|
||||
|
||||
self->blink = true;
|
||||
}
|
||||
|
||||
static void chat_onNickChange(ToxWindow* self, int num, uint8_t* nick, uint16_t len) {
|
||||
@ -70,15 +80,27 @@ static void chat_onKey(ToxWindow* self, int key) {
|
||||
}
|
||||
}
|
||||
else if(key == '\n') {
|
||||
wprintw(ctx->history, "you: %s\n", ctx->line);
|
||||
wattron(ctx->history, COLOR_PAIR(1));
|
||||
wprintw(ctx->history, "you: ", ctx->line);
|
||||
wattroff(ctx->history, COLOR_PAIR(1));
|
||||
|
||||
wprintw(ctx->history, "%s\n", ctx->line);
|
||||
|
||||
if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) {
|
||||
wattron(ctx->history, COLOR_PAIR(3));
|
||||
wprintw(ctx->history, " * Failed to send message.\n");
|
||||
wattroff(ctx->history, COLOR_PAIR(3));
|
||||
}
|
||||
|
||||
ctx->line[0] = '\0';
|
||||
ctx->pos = 0;
|
||||
}
|
||||
else if(key == 0x107) {
|
||||
if(ctx->pos != 0) {
|
||||
ctx->line[--ctx->pos] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void chat_onDraw(ToxWindow* self) {
|
||||
@ -105,7 +127,6 @@ static void chat_onInit(ToxWindow* self) {
|
||||
getmaxyx(self->window, y, x);
|
||||
|
||||
ctx->history = subwin(self->window, y - 4, x, 0, 0);
|
||||
wprintw(ctx->history, "Here goes chat\n");
|
||||
scrollok(ctx->history, 1);
|
||||
|
||||
ctx->linewin = subwin(self->window, 2, x, y - 3, 0);
|
||||
|
37
friendlist.c
37
friendlist.c
@ -22,7 +22,7 @@ typedef struct {
|
||||
uint8_t name[MAX_NAME_LENGTH];
|
||||
uint8_t status[MAX_USERSTATUS_LENGTH];
|
||||
int num;
|
||||
|
||||
int chatwin;
|
||||
} friend_t;
|
||||
|
||||
static friend_t friends[MAX_FRIENDS_NUM];
|
||||
@ -37,7 +37,7 @@ void fix_name(uint8_t* name) {
|
||||
uint8_t* q = name;
|
||||
|
||||
while(*p != 0) {
|
||||
if(isalnum(*p)) {
|
||||
if(isprint(*p)) {
|
||||
*q++ = *p;
|
||||
}
|
||||
|
||||
@ -47,6 +47,16 @@ void fix_name(uint8_t* name) {
|
||||
*q = 0;
|
||||
}
|
||||
|
||||
void friendlist_onMessage(ToxWindow* self, int num, uint8_t* str, uint16_t len) {
|
||||
|
||||
if(num >= num_friends)
|
||||
return;
|
||||
|
||||
if(friends[num].chatwin == -1) {
|
||||
friends[num].chatwin = add_window(new_chat(num));
|
||||
}
|
||||
}
|
||||
|
||||
void friendlist_onNickChange(ToxWindow* self, int num, uint8_t* str, uint16_t len) {
|
||||
|
||||
if(len >= MAX_NAME_LENGTH || num >= num_friends)
|
||||
@ -55,8 +65,6 @@ void friendlist_onNickChange(ToxWindow* self, int num, uint8_t* str, uint16_t le
|
||||
memcpy((char*) &friends[num].name, (char*) str, len);
|
||||
friends[num].name[len] = 0;
|
||||
fix_name(friends[num].name);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void friendlist_onStatusChange(ToxWindow* self, int num, uint8_t* str, uint16_t len) {
|
||||
@ -67,8 +75,6 @@ void friendlist_onStatusChange(ToxWindow* self, int num, uint8_t* str, uint16_t
|
||||
memcpy((char*) &friends[num].status, (char*) str, len);
|
||||
friends[num].status[len] = 0;
|
||||
fix_name(friends[num].status);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int friendlist_onFriendAdded(int num) {
|
||||
@ -80,6 +86,7 @@ int friendlist_onFriendAdded(int num) {
|
||||
getname(num, friends[num_friends].name);
|
||||
strcpy((char*) friends[num_friends].name, "unknown");
|
||||
strcpy((char*) friends[num_friends].status, "unknown");
|
||||
friends[num_friends].chatwin = -1;
|
||||
|
||||
num_friends++;
|
||||
return 0;
|
||||
@ -96,7 +103,12 @@ static void friendlist_onKey(ToxWindow* self, int key) {
|
||||
num_selected = (num_selected+1) % num_friends;
|
||||
}
|
||||
else if(key == '\n') {
|
||||
focus_window(add_window(new_chat(num_selected)));
|
||||
|
||||
if(friends[num_selected].chatwin != -1)
|
||||
return;
|
||||
|
||||
friends[num_selected].chatwin = add_window(new_chat(num_selected));
|
||||
focus_window(friends[num_selected].chatwin);
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,12 +122,8 @@ static void friendlist_onDraw(ToxWindow* self) {
|
||||
}
|
||||
else {
|
||||
wattron(self->window, COLOR_PAIR(2) | A_BOLD);
|
||||
wprintw(self->window, "Friend list:\n");
|
||||
wattroff(self->window, A_BOLD);
|
||||
|
||||
wprintw(self->window, " ENTER: start a chat\n");
|
||||
wprintw(self->window, " UP/DOWN: navigate list\n");
|
||||
wattroff(self->window, COLOR_PAIR(2));
|
||||
wprintw(self->window, "Open chat with.. (up/down keys, enter)\n");
|
||||
wattroff(self->window, COLOR_PAIR(2) | A_BOLD);
|
||||
}
|
||||
|
||||
wprintw(self->window, "\n");
|
||||
@ -123,7 +131,7 @@ static void friendlist_onDraw(ToxWindow* self) {
|
||||
for(i=0; i<num_friends; i++) {
|
||||
|
||||
if(i == num_selected) wattron(self->window, COLOR_PAIR(3));
|
||||
wprintw(self->window, " [%d] ", friends[i].num);
|
||||
wprintw(self->window, " [#%d] ", friends[i].num);
|
||||
if(i == num_selected) wattroff(self->window, COLOR_PAIR(3));
|
||||
|
||||
attron(A_BOLD);
|
||||
@ -149,6 +157,7 @@ ToxWindow new_friendlist() {
|
||||
ret.onKey = &friendlist_onKey;
|
||||
ret.onDraw = &friendlist_onDraw;
|
||||
ret.onInit = &friendlist_onInit;
|
||||
ret.onMessage = &friendlist_onMessage;
|
||||
ret.onNickChange = &friendlist_onNickChange;
|
||||
ret.onStatusChange = &friendlist_onStatusChange;
|
||||
strcpy(ret.title, "[friends]");
|
||||
|
25
main.c
25
main.c
@ -32,7 +32,14 @@ void on_request(uint8_t* public_key, uint8_t* data, uint16_t length) {
|
||||
size_t i;
|
||||
int n = add_req(public_key);
|
||||
|
||||
wprintw(prompt->window, "\nFriend request.\nUse \"accept %d\" to accept it.\n", n);
|
||||
wprintw(prompt->window, "\nFriend request from:\n");
|
||||
|
||||
for(i=0; i<32; i++) {
|
||||
wprintw(prompt->window, "%02x", public_key[i] & 0xff);
|
||||
}
|
||||
wprintw(prompt->window, "\n");
|
||||
|
||||
wprintw(prompt->window, "Use \"accept %d\" to accept it.\n", n);
|
||||
|
||||
for(i=0; i<w_num; i++) {
|
||||
if(windows[i].onFriendRequest != NULL)
|
||||
@ -230,6 +237,7 @@ static void load_data() {
|
||||
}
|
||||
|
||||
static void draw_bar() {
|
||||
static int odd = 0;
|
||||
size_t i;
|
||||
|
||||
attron(COLOR_PAIR(4));
|
||||
@ -238,17 +246,27 @@ static void draw_bar() {
|
||||
|
||||
move(LINES - 1, 0);
|
||||
|
||||
attron(COLOR_PAIR(3) | A_BOLD);
|
||||
attron(COLOR_PAIR(4) | A_BOLD);
|
||||
printw(" TOXIC 1.0 |");
|
||||
attroff(COLOR_PAIR(3) | A_BOLD);
|
||||
attroff(COLOR_PAIR(4) | A_BOLD);
|
||||
|
||||
for(i=0; i<w_num; i++) {
|
||||
if(i == w_active) {
|
||||
attron(A_BOLD);
|
||||
}
|
||||
|
||||
odd = (odd+1) % 2;
|
||||
|
||||
if(windows[i].blink && odd) {
|
||||
attron(COLOR_PAIR(3));
|
||||
}
|
||||
|
||||
printw(" %s", windows[i].title);
|
||||
|
||||
if(windows[i].blink && odd) {
|
||||
attron(COLOR_PAIR(3));
|
||||
}
|
||||
|
||||
if(i == w_active) {
|
||||
attroff(A_BOLD);
|
||||
}
|
||||
@ -278,6 +296,7 @@ int main(int argc, char* argv[]) {
|
||||
// Draw.
|
||||
a = &windows[w_active];
|
||||
prepare_window(a->window);
|
||||
a->blink = false;
|
||||
a->onDraw(a);
|
||||
draw_bar();
|
||||
|
||||
|
7
prompt.c
7
prompt.c
@ -42,7 +42,7 @@ static int prompt_buf_pos=0;
|
||||
|
||||
static void execute(ToxWindow* self, char* cmd) {
|
||||
|
||||
if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit")) {
|
||||
if(!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) {
|
||||
endwin();
|
||||
exit(0);
|
||||
}
|
||||
@ -282,12 +282,11 @@ static void prompt_onDraw(ToxWindow* self) {
|
||||
|
||||
static void print_usage(ToxWindow* self) {
|
||||
wattron(self->window, COLOR_PAIR(2) | A_BOLD);
|
||||
wprintw(self->window, "Usage:\n");
|
||||
wprintw(self->window, "Commands:\n");
|
||||
wattroff(self->window, A_BOLD);
|
||||
|
||||
wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n");
|
||||
wprintw(self->window, " add <id> <message> : Add friend\n");
|
||||
wprintw(self->window, " msg <number> <message> : Send message\n");
|
||||
wprintw(self->window, " status <message> : Set your status\n");
|
||||
wprintw(self->window, " nick <nickname> : Set your nickname\n");
|
||||
wprintw(self->window, " accept <number> : Accept friend request\n");
|
||||
@ -296,7 +295,7 @@ static void print_usage(ToxWindow* self) {
|
||||
|
||||
|
||||
wattron(self->window, A_BOLD);
|
||||
wprintw(self->window, "Use the TAB key to navigate through the tabs.\n");
|
||||
wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n");
|
||||
wattroff(self->window, A_BOLD);
|
||||
|
||||
wattroff(self->window, COLOR_PAIR(2));
|
||||
|
Loading…
Reference in New Issue
Block a user