updated tgl
This commit is contained in:
parent
224160d804
commit
2cc75016aa
@ -2858,13 +2858,14 @@ void user_status_upd (struct tgl_state *TLS, struct tgl_user *U) {
|
||||
|
||||
void on_login (struct tgl_state *TLS);
|
||||
void on_started (struct tgl_state *TLS);
|
||||
void do_get_string (struct tgl_state *TLS, const char *prompt, int flags, void (*cb)(struct tgl_state *, const char *, void *), void *arg);
|
||||
void do_get_values (struct tgl_state *TLS, enum tgl_value_type type, const char *prompt, int num_values,
|
||||
void (*callback)(struct tgl_state *TLS, const char *string[], void *arg), void *arg);
|
||||
|
||||
struct tgl_update_callback upd_cb = {
|
||||
.new_msg = print_message_gw,
|
||||
.marked_read = mark_read_upd,
|
||||
.logprintf = logprintf,
|
||||
.get_string = do_get_string,
|
||||
.get_values = do_get_values,
|
||||
.logged_in = on_login,
|
||||
.started = on_started,
|
||||
.type_notification = type_notification_upd,
|
||||
|
115
loop.c
115
loop.c
@ -114,7 +114,12 @@ int read_one_string;
|
||||
#define MAX_ONE_STRING_LEN 511
|
||||
char one_string[MAX_ONE_STRING_LEN + 1];
|
||||
int one_string_len;
|
||||
void (*on_string_cb)(struct tgl_state *TLS, char *str, void *arg);
|
||||
void (*one_string_cb)(struct tgl_state *TLS, const char *string[], void *arg);
|
||||
enum tgl_value_type one_string_type;
|
||||
int one_string_num;
|
||||
int one_string_total_args;
|
||||
char *one_string_results[10];
|
||||
|
||||
void *string_cb_arg;
|
||||
char *one_string_prompt;
|
||||
int one_string_flags;
|
||||
@ -123,29 +128,121 @@ extern int disable_link_preview;
|
||||
void deactivate_readline (void);
|
||||
void reactivate_readline (void);
|
||||
|
||||
void do_get_string (struct tgl_state *TLS);
|
||||
static void one_string_read_end (void) {
|
||||
printf ("\n");
|
||||
fflush (stdout);
|
||||
|
||||
read_one_string = 0;
|
||||
free (one_string_prompt);
|
||||
tfree_str (one_string_prompt);
|
||||
one_string_prompt = NULL;
|
||||
reactivate_readline ();
|
||||
on_string_cb (TLS, one_string, string_cb_arg);
|
||||
|
||||
one_string_results[one_string_num] = tstrdup (one_string);
|
||||
++one_string_num;
|
||||
|
||||
if (one_string_num < one_string_total_args) {
|
||||
do_get_string (TLS);
|
||||
} else {
|
||||
one_string_cb (TLS, (void *)one_string_results, string_cb_arg);
|
||||
int i;
|
||||
for (i = 0; i < one_string_total_args; i++) {
|
||||
tfree_str (one_string_results[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void do_get_string (struct tgl_state *TLS, const char *prompt, int flags, void (*cb)(struct tgl_state *, char *, void *), void *arg) {
|
||||
void generate_prompt (enum tgl_value_type type, int num) {
|
||||
switch (type) {
|
||||
case tgl_phone_number:
|
||||
assert (!num);
|
||||
one_string_prompt = tstrdup ("phone number: ");
|
||||
one_string_flags = 0;
|
||||
return;
|
||||
case tgl_code:
|
||||
assert (!num);
|
||||
one_string_prompt = tstrdup ("code ('CALL' for phone code): ");
|
||||
one_string_flags = 0;
|
||||
return;
|
||||
case tgl_register_info:
|
||||
one_string_flags = 0;
|
||||
switch (num) {
|
||||
case 0:
|
||||
one_string_prompt = tstrdup ("register (Y/n): ");
|
||||
return;
|
||||
case 1:
|
||||
one_string_prompt = tstrdup ("first name: ");
|
||||
return;
|
||||
case 2:
|
||||
one_string_prompt = tstrdup ("last name: ");
|
||||
return;
|
||||
default:
|
||||
assert (0);
|
||||
}
|
||||
return;
|
||||
case tgl_new_password:
|
||||
one_string_flags = 1;
|
||||
switch (num) {
|
||||
case 0:
|
||||
one_string_prompt = tstrdup ("new password: ");
|
||||
return;
|
||||
case 1:
|
||||
one_string_prompt = tstrdup ("retype new password: ");
|
||||
return;
|
||||
default:
|
||||
assert (0);
|
||||
}
|
||||
return;
|
||||
case tgl_cur_and_new_password:
|
||||
one_string_flags = 1;
|
||||
switch (num) {
|
||||
case 0:
|
||||
one_string_prompt = tstrdup ("old password: ");
|
||||
return;
|
||||
case 1:
|
||||
one_string_prompt = tstrdup ("new password: ");
|
||||
return;
|
||||
case 2:
|
||||
one_string_prompt = tstrdup ("retype new password: ");
|
||||
return;
|
||||
default:
|
||||
assert (0);
|
||||
}
|
||||
return;
|
||||
case tgl_cur_password:
|
||||
one_string_flags = 1;
|
||||
assert (!num);
|
||||
one_string_prompt = tstrdup ("password: ");
|
||||
return;
|
||||
case tgl_bot_hash:
|
||||
one_string_flags = 0;
|
||||
assert (!num);
|
||||
one_string_prompt = tstrdup ("hash: ");
|
||||
return;
|
||||
default:
|
||||
assert (0);
|
||||
}
|
||||
}
|
||||
|
||||
void do_get_string (struct tgl_state *TLS) {
|
||||
deactivate_readline ();
|
||||
printf ("%s ", prompt);
|
||||
generate_prompt (one_string_type, one_string_num);
|
||||
printf ("%s", one_string_prompt);
|
||||
fflush (stdout);
|
||||
one_string_prompt = strdup (prompt);
|
||||
one_string_flags = flags;
|
||||
read_one_string = 1;
|
||||
on_string_cb = cb;
|
||||
string_cb_arg = arg;
|
||||
one_string_len = 0;
|
||||
}
|
||||
|
||||
void do_get_values (struct tgl_state *TLS, enum tgl_value_type type, const char *prompt, int num_values,
|
||||
void (*callback)(struct tgl_state *TLS, const char *string[], void *arg), void *arg) {
|
||||
one_string_cb = callback;
|
||||
one_string_num = 0;
|
||||
one_string_total_args = num_values;
|
||||
one_string_type = type;
|
||||
string_cb_arg = arg;
|
||||
do_get_string (TLS);
|
||||
}
|
||||
|
||||
static void stdin_read_callback (evutil_socket_t fd, short what, void *arg) {
|
||||
if (!readline_disabled && !read_one_string) {
|
||||
rl_callback_read_char ();
|
||||
|
2
tgl
2
tgl
@ -1 +1 @@
|
||||
Subproject commit 7bfaae149a08d1e205e5188d548c3d54e5a1ce64
|
||||
Subproject commit e279fef0dc34c12d02e88f82a2fbde5917bc9c56
|
Loading…
x
Reference in New Issue
Block a user