Commit 65c5cbe1 authored by vysheng's avatar vysheng

Added unread count

parent f9cf3929
...@@ -35,10 +35,18 @@ ...@@ -35,10 +35,18 @@
#include "structures.h" #include "structures.h"
#include "mtproto-common.h" #include "mtproto-common.h"
char *default_prompt = ">"; char *default_prompt = "> ";
int unread_messages;
char *get_default_prompt (void) { 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) { char *complete_none (const char *text UU, int state UU) {
...@@ -385,7 +393,8 @@ void print_start (void) { ...@@ -385,7 +393,8 @@ void print_start (void) {
void print_end (void) { void print_end (void) {
assert (prompt_was); assert (prompt_was);
if (readline_active) { if (readline_active) {
rl_restore_prompt(); rl_set_prompt (get_default_prompt ());
rl_redisplay();
rl_replace_line(saved_line, 0); rl_replace_line(saved_line, 0);
rl_point = saved_point; rl_point = saved_point;
rl_redisplay(); rl_redisplay();
......
...@@ -48,6 +48,7 @@ int default_dc_num; ...@@ -48,6 +48,7 @@ int default_dc_num;
extern int unknown_user_list_pos; extern int unknown_user_list_pos;
extern int unknown_user_list[]; extern int unknown_user_list[];
int unread_messages;
void net_loop (int flags, int (*is_end)(void)) { void net_loop (int flags, int (*is_end)(void)) {
while (!is_end ()) { while (!is_end ()) {
struct pollfd fds[101]; struct pollfd fds[101];
...@@ -75,6 +76,7 @@ void net_loop (int flags, int (*is_end)(void)) { ...@@ -75,6 +76,7 @@ void net_loop (int flags, int (*is_end)(void)) {
} }
work_timers (); work_timers ();
if ((flags & 1) && (fds[0].revents & POLLIN)) { if ((flags & 1) && (fds[0].revents & POLLIN)) {
unread_messages = 0;
rl_callback_read_char (); rl_callback_read_char ();
} }
connections_poll_result (fds + cc, x - cc); connections_poll_result (fds + cc, x - cc);
......
...@@ -633,6 +633,8 @@ int auth_work_start (struct connection *c UU) { ...@@ -633,6 +633,8 @@ int auth_work_start (struct connection *c UU) {
void rpc_execute_answer (struct connection *c, long long msg_id 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) { void work_update (struct connection *c UU, long long msg_id UU) {
unsigned op = fetch_int (); unsigned op = fetch_int ();
switch (op) { switch (op) {
...@@ -640,6 +642,7 @@ void work_update (struct connection *c UU, long long msg_id UU) { ...@@ -640,6 +642,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
{ {
struct message *M = fetch_alloc_message (); struct message *M = fetch_alloc_message ();
fetch_int (); //pts fetch_int (); //pts
unread_messages ++;
print_message (M); print_message (M);
break; break;
}; };
...@@ -936,12 +939,14 @@ void work_updates (struct connection *c, long long msg_id) { ...@@ -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) { void work_update_short_message (struct connection *c UU, long long msg_id UU) {
assert (fetch_int () == (int)CODE_update_short_message); assert (fetch_int () == (int)CODE_update_short_message);
struct message *M = fetch_alloc_message_short (); struct message *M = fetch_alloc_message_short ();
unread_messages ++;
print_message (M); print_message (M);
} }
void work_update_short_chat_message (struct connection *c UU, long long msg_id UU) { void work_update_short_chat_message (struct connection *c UU, long long msg_id UU) {
assert (fetch_int () == CODE_update_short_chat_message); assert (fetch_int () == CODE_update_short_chat_message);
struct message *M = fetch_alloc_message_short_chat (); struct message *M = fetch_alloc_message_short_chat ();
unread_messages ++;
print_message (M); print_message (M);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment