Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
3be908e7
Commit
3be908e7
authored
Oct 29, 2013
by
vysheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed interface: show download/upload progress
parent
e858db09
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
2 deletions
+56
-2
interface.c
interface.c
+31
-2
interface.h
interface.h
+2
-0
mtproto-client.c
mtproto-client.c
+3
-0
queries.c
queries.c
+20
-0
No files found.
interface.c
View file @
3be908e7
...
...
@@ -40,10 +40,32 @@ char *default_prompt = "> ";
int
unread_messages
;
int
msg_num_mode
;
long
long
cur_uploading_bytes
;
long
long
cur_uploaded_bytes
;
long
long
cur_downloading_bytes
;
long
long
cur_downloaded_bytes
;
char
*
get_default_prompt
(
void
)
{
static
char
buf
[
100
];
if
(
unread_messages
)
{
sprintf
(
buf
,
COLOR_RED
"[%d unread]"
COLOR_NORMAL
"%s"
,
unread_messages
,
default_prompt
);
if
(
unread_messages
||
cur_uploading_bytes
||
cur_downloading_bytes
)
{
int
l
=
sprintf
(
buf
,
COLOR_RED
"["
);
int
ok
=
0
;
if
(
unread_messages
)
{
l
+=
sprintf
(
buf
+
l
,
"%d unread"
,
unread_messages
);
ok
=
1
;
}
if
(
cur_uploading_bytes
)
{
if
(
ok
)
{
*
(
buf
+
l
)
=
' '
;
l
++
;
}
ok
=
1
;
l
+=
sprintf
(
buf
+
l
,
"%lld%%Up"
,
100
*
cur_uploaded_bytes
/
cur_uploading_bytes
);
}
if
(
cur_downloading_bytes
)
{
if
(
ok
)
{
*
(
buf
+
l
)
=
' '
;
l
++
;
}
ok
=
1
;
l
+=
sprintf
(
buf
+
l
,
"%lld%%Down"
,
100
*
cur_downloaded_bytes
/
cur_downloading_bytes
);
}
sprintf
(
buf
+
l
,
"]"
COLOR_NORMAL
"%s"
,
default_prompt
);
return
buf
;
}
else
{
return
default_prompt
;
...
...
@@ -54,6 +76,13 @@ char *complete_none (const char *text UU, int state UU) {
return
0
;
}
void
update_prompt
(
void
)
{
print_start
();
rl_set_prompt
(
get_default_prompt
());
rl_redisplay
();
print_end
();
}
char
*
commands
[]
=
{
"help"
,
"msg"
,
...
...
interface.h
View file @
3be908e7
...
...
@@ -50,4 +50,6 @@ void push_color (const char *color);
void
print_start
(
void
);
void
print_end
(
void
);
void
print_date_full
(
long
t
);
void
update_prompt
(
void
);
#endif
mtproto-client.c
View file @
3be908e7
...
...
@@ -644,6 +644,7 @@ void work_update (struct connection *c UU, long long msg_id UU) {
fetch_int
();
//pts
unread_messages
++
;
print_message
(
M
);
update_prompt
();
break
;
};
case
CODE_update_message_i_d
:
...
...
@@ -939,6 +940,7 @@ void work_update_short_message (struct connection *c UU, long long msg_id UU) {
struct
message
*
M
=
fetch_alloc_message_short
();
unread_messages
++
;
print_message
(
M
);
update_prompt
();
}
void
work_update_short_chat_message
(
struct
connection
*
c
UU
,
long
long
msg_id
UU
)
{
...
...
@@ -946,6 +948,7 @@ void work_update_short_chat_message (struct connection *c UU, long long msg_id U
struct
message
*
M
=
fetch_alloc_message_short_chat
();
unread_messages
++
;
print_message
(
M
);
update_prompt
();
}
void
work_container
(
struct
connection
*
c
,
long
long
msg_id
UU
)
{
...
...
queries.c
View file @
3be908e7
...
...
@@ -39,6 +39,11 @@
char
*
get_downloads_directory
(
void
);
int
verbosity
;
long
long
cur_uploading_bytes
;
long
long
cur_uploaded_bytes
;
long
long
cur_downloading_bytes
;
long
long
cur_downloaded_bytes
;
#define QUERY_TIMEOUT 0.3
#define memcmp8(a,b) memcmp ((a), (b), 8)
...
...
@@ -914,6 +919,9 @@ struct query_methods send_file_methods = {
void
send_part
(
struct
send_file
*
f
)
{
if
(
f
->
fd
>=
0
)
{
if
(
!
f
->
part_num
)
{
cur_uploading_bytes
+=
f
->
size
;
}
clear_packet
();
out_int
(
CODE_upload_save_file_part
);
out_long
(
f
->
id
);
...
...
@@ -923,6 +931,7 @@ void send_part (struct send_file *f) {
assert
(
x
>
0
);
out_cstring
(
buf
,
x
);
f
->
offset
+=
x
;
cur_uploaded_bytes
+=
x
;
if
(
verbosity
>=
2
)
{
logprintf
(
"offset=%lld size=%lld
\n
"
,
f
->
offset
,
f
->
size
);
}
...
...
@@ -932,6 +941,8 @@ void send_part (struct send_file *f) {
}
send_query
(
DC_working
,
packet_ptr
-
packet_buffer
,
packet_buffer
,
&
send_file_part_methods
,
f
);
}
else
{
cur_uploaded_bytes
-=
f
->
size
;
cur_uploading_bytes
-=
f
->
size
;
clear_packet
();
out_int
(
CODE_messages_send_media
);
out_peer_id
(
f
->
to_id
);
...
...
@@ -1175,6 +1186,9 @@ struct download {
void
end_load
(
struct
download
*
D
)
{
cur_downloading_bytes
-=
D
->
size
;
cur_downloaded_bytes
-=
D
->
size
;
update_prompt
();
close
(
D
->
fd
);
if
(
D
->
next
==
1
)
{
logprintf
(
"Done: %s
\n
"
,
D
->
name
);
...
...
@@ -1234,6 +1248,8 @@ int download_on_answer (struct query *q) {
fetch_int
();
// mtime
int
len
=
prefetch_strlen
();
assert
(
len
>=
0
);
cur_downloaded_bytes
+=
len
;
update_prompt
();
assert
(
write
(
D
->
fd
,
fetch_str
(
len
),
len
)
==
len
);
D
->
offset
+=
len
;
if
(
D
->
offset
<
D
->
size
)
{
...
...
@@ -1250,6 +1266,10 @@ struct query_methods download_methods = {
};
void
load_next_part
(
struct
download
*
D
)
{
if
(
!
D
->
offset
)
{
cur_downloading_bytes
+=
D
->
size
;
update_prompt
();
}
clear_packet
();
out_int
(
CODE_upload_get_file
);
if
(
!
D
->
id
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment