Added unread count

This commit is contained in:
vysheng 2013-10-24 19:44:54 +04:00
parent f9cf392960
commit 65c5cbe137
3 changed files with 19 additions and 3 deletions

View File

@ -35,10 +35,18 @@
#include "structures.h"
#include "mtproto-common.h"
char *default_prompt = ">";
char *default_prompt = "> ";
int unread_messages;
char *get_default_prompt (void) {
return default_prompt;
static char buf[100];
if (unread_messages) {
sprintf (buf, COLOR_RED "[%d unread]" COLOR_NORMAL "%s", unread_messages, default_prompt);
return buf;
} else {
return default_prompt;
}
}
char *complete_none (const char *text UU, int state UU) {
@ -385,7 +393,8 @@ void print_start (void) {
void print_end (void) {
assert (prompt_was);
if (readline_active) {
rl_restore_prompt();
rl_set_prompt (get_default_prompt ());
rl_redisplay();
rl_replace_line(saved_line, 0);
rl_point = saved_point;
rl_redisplay();

2
loop.c
View File

@ -48,6 +48,7 @@ int default_dc_num;
extern int unknown_user_list_pos;
extern int unknown_user_list[];
int unread_messages;
void net_loop (int flags, int (*is_end)(void)) {
while (!is_end ()) {
struct pollfd fds[101];
@ -75,6 +76,7 @@ void net_loop (int flags, int (*is_end)(void)) {
}
work_timers ();
if ((flags & 1) && (fds[0].revents & POLLIN)) {
unread_messages = 0;
rl_callback_read_char ();
}
connections_poll_result (fds + cc, x - cc);

View File

@ -633,6 +633,8 @@ int auth_work_start (struct connection *c UU) {
void rpc_execute_answer (struct connection *c, long long msg_id UU);
int unread_messages;
int our_id;
void work_update (struct connection *c UU, long long msg_id UU) {
unsigned op = fetch_int ();
switch (op) {
@ -640,6 +642,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
{
struct message *M = fetch_alloc_message ();
fetch_int (); //pts
unread_messages ++;
print_message (M);
break;
};
@ -936,12 +939,14 @@ void work_updates (struct connection *c, long long msg_id) {
void work_update_short_message (struct connection *c UU, long long msg_id UU) {
assert (fetch_int () == (int)CODE_update_short_message);
struct message *M = fetch_alloc_message_short ();
unread_messages ++;
print_message (M);
}
void work_update_short_chat_message (struct connection *c UU, long long msg_id UU) {
assert (fetch_int () == CODE_update_short_chat_message);
struct message *M = fetch_alloc_message_short_chat ();
unread_messages ++;
print_message (M);
}