From 85fc0d57cdb31b681851b4a6eea850bf4eec3780 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Wed, 17 Jan 2018 16:03:15 +1000 Subject: [PATCH] File area choosers now use lightbars --- magicka.strings | 2 + src/bbs.h | 4 +- src/files.c | 206 +++++++++++++++++++++++++++++++++++++++++++++++- src/mail_menu.c | 30 ------- src/menus.c | 4 +- 5 files changed, 211 insertions(+), 35 deletions(-) diff --git a/magicka.strings b/magicka.strings index af648f4..6580bdf 100644 --- a/magicka.strings +++ b/magicka.strings @@ -250,3 +250,5 @@ File exists!\r\n \e[%d;1H\e[1;30;40m[\e[1;34;44m%.4d\e[1;30;40m] \e[1;37m%s\e[K \e[%d;1H\e[1;30;40m[\e[1;34m%.4d\e[1;30;40m] \e[1;37m%s\e[K \e[1;37;44mChoose an Area in %s\e[K +\e[1;37;44mChoose an Subdir in %s\e[K +\e[1;37;44mChoose a Directory\e[K diff --git a/src/bbs.h b/src/bbs.h index 80cc36e..5e1daa6 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -306,8 +306,8 @@ extern void upload_zmodem(struct user_record *user, char *upload_p); extern int ttySetRaw(int fd, struct termios *prevTermios); extern int do_upload(struct user_record *user, char *final_path); extern int do_download(struct user_record *user, char *file); -extern void choose_directory(struct user_record *user); -extern void choose_subdir(struct user_record *user); +extern void choose_directory(); +extern void choose_subdir(); extern void list_files(struct user_record *user); extern void upload(struct user_record *user); extern void download(struct user_record *user); diff --git a/src/files.c b/src/files.c index cfc33af..8a1a54b 100644 --- a/src/files.c +++ b/src/files.c @@ -1341,6 +1341,107 @@ void list_files(struct user_record *user) { do_list_files(files_e, files_c); } +struct subdir_tmp_t { + struct file_sub *sub; + int index; +}; + +void choose_subdir() { + int i; + int list_tmp = 0; + struct subdir_tmp_t **sub_tmp; + int redraw = 1; + int start = 0; + int selected = 0; + char c; + + for (i=0;icur_file_dir]->file_sub_count;i++) { + if (conf.file_directories[gUser->cur_file_dir]->file_subs[i]->download_sec_level <= gUser->sec_level) { + if (list_tmp == 0) { + sub_tmp = (struct subdir_tmp_t **)malloc(sizeof(struct subdir_tmp_t *)); + } else { + sub_tmp = (struct subdir_tmp_t **)realloc(sub_tmp, sizeof(struct subdir_tmp_t *) * (list_tmp + 1)); + } + + sub_tmp[list_tmp] = (struct subdir_tmp_t *)malloc(sizeof(struct subdir_tmp_t)); + sub_tmp[list_tmp]->sub = conf.file_directories[gUser->cur_file_dir]->file_subs[i]; + sub_tmp[list_tmp]->index = i; + list_tmp++; + } + } + + while (1) { + if (redraw) { + s_printf("\e[2J\e[1;1H"); + s_printf(get_string(252), conf.file_directories[gUser->cur_file_dir]->name); + s_printf(get_string(248)); + for (i=start;iindex, sub_tmp[i]->sub->name); + } else { + s_printf(get_string(250), i - start + 2, sub_tmp[i]->index, sub_tmp[i]->sub->name); + } + } + redraw = 0; + } + c = s_getchar(); + if (tolower(c) == 'q') { + break; + } else if (c == 27) { + c = s_getchar(); + if (c == 91) { + c = s_getchar(); + if (c == 66) { + // down + if (selected + 1 > start + 22) { + start += 22; + if (start >= list_tmp) { + start = list_tmp - 22; + } + redraw = 1; + } + selected++; + if (selected >= list_tmp) { + selected = list_tmp - 1; + } else { + if (!redraw) { + s_printf(get_string(250), selected - start + 1, sub_tmp[selected - 1]->index, sub_tmp[selected - 1]->sub->name); + s_printf(get_string(249), selected - start + 2, sub_tmp[selected]->index, sub_tmp[selected]->sub->name); + } + } + } else if (c == 65) { + // up + if (selected - 1 < start) { + start -= 22; + if (start < 0) { + start = 0; + } + redraw = 1; + } + selected--; + if (selected < 0) { + selected = 0; + } else { + if (!redraw) { + s_printf(get_string(249), selected - start + 2, sub_tmp[selected]->index, sub_tmp[selected]->sub->name); + s_printf(get_string(250), selected - start + 3, sub_tmp[selected + 1]->index, sub_tmp[selected + 1]->sub->name); + } + } + } + } + } else if (c == 13) { + gUser->cur_file_sub = sub_tmp[selected]->index; + break; + } + } + + for (i=0;isec_level <= gUser->sec_level) { + if (list_tmp == 0) { + dir_tmp = (struct dir_tmp_t **)malloc(sizeof(struct dir_tmp_t *)); + } else { + dir_tmp = (struct dir_tmp_t **)realloc(dir_tmp, sizeof(struct dir_tmp_t *) * (list_tmp + 1)); + } + + dir_tmp[list_tmp] = (struct dir_tmp_t *)malloc(sizeof(struct dir_tmp_t)); + dir_tmp[list_tmp]->dir = conf.file_directories[i]; + dir_tmp[list_tmp]->index = i; + list_tmp++; + } + } + + while (1) { + if (redraw) { + s_printf("\e[2J\e[1;1H"); + s_printf(get_string(253)); + s_printf(get_string(248)); + for (i=start;iindex, dir_tmp[i]->dir->name); + } else { + s_printf(get_string(250), i - start + 2, dir_tmp[i]->index, dir_tmp[i]->dir->name); + } + } + redraw = 0; + } + c = s_getchar(); + if (tolower(c) == 'q') { + break; + } else if (c == 27) { + c = s_getchar(); + if (c == 91) { + c = s_getchar(); + if (c == 66) { + // down + if (selected + 1 > start + 22) { + start += 22; + if (start >= list_tmp) { + start = list_tmp - 22; + } + redraw = 1; + } + selected++; + if (selected >= list_tmp) { + selected = list_tmp - 1; + } else { + if (!redraw) { + s_printf(get_string(250), selected - start + 1, dir_tmp[selected - 1]->index, dir_tmp[selected - 1]->dir->name); + s_printf(get_string(249), selected - start + 2, dir_tmp[selected]->index, dir_tmp[selected]->dir->name); + } + } + } else if (c == 65) { + // up + if (selected - 1 < start) { + start -= 22; + if (start < 0) { + start = 0; + } + redraw = 1; + } + selected--; + if (selected < 0) { + selected = 0; + } else { + if (!redraw) { + s_printf(get_string(249), selected - start + 2, dir_tmp[selected]->index, dir_tmp[selected]->dir->name); + s_printf(get_string(250), selected - start + 3, dir_tmp[selected + 1]->index, dir_tmp[selected + 1]->dir->name); + } + } + } + } + } else if (c == 13) { + gUser->cur_file_dir = dir_tmp[selected]->index; + gUser->cur_file_sub = 0; + break; + } + } + + for (i=0;icur_mail_conf]->mail_area_count;i++) { - if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->read_sec_level <= user->sec_level) { - s_printf(get_string(136), i, conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->name); - } - if (i != 0 && i % 20 == 0) { - s_printf(get_string(6)); - c = s_getc(); - } - } - s_printf(get_string(137)); - s_readstring(buffer, 5); - if (tolower(buffer[0]) != 'q') { - j = atoi(buffer); - if (j < 0 || j >= conf.mail_conferences[user->cur_mail_conf]->mail_area_count || conf.mail_conferences[user->cur_mail_conf]->mail_areas[j]->read_sec_level > user->sec_level) { - s_printf(get_string(138)); - } else { - s_printf("\r\n"); - user->cur_mail_area = j; - } - } -} -*/ void next_mail_conf(struct user_record *user) { int i; diff --git a/src/menus.c b/src/menus.c index 74fc501..12e15a1 100644 --- a/src/menus.c +++ b/src/menus.c @@ -451,10 +451,10 @@ int menu_system(char *menufile) { bwave_upload_reply(); break; case MENU_CHOOSEFILEDIR: - choose_directory(gUser); + choose_directory(); break; case MENU_CHOOSEFILESUB: - choose_subdir(gUser); + choose_subdir(); break; case MENU_LISTFILES: list_files(gUser);