| 16 |
|
|
| 17 |
#include "section_list_display.h" |
#include "section_list_display.h" |
| 18 |
#include "section_list_loader.h" |
#include "section_list_loader.h" |
| 19 |
|
#include "article_cache.h" |
| 20 |
#include "common.h" |
#include "common.h" |
| 21 |
#include "io.h" |
#include "io.h" |
| 22 |
#include "screen.h" |
#include "screen.h" |
| 23 |
#include "log.h" |
#include "log.h" |
| 24 |
#include "str_process.h" |
#include "str_process.h" |
| 25 |
#include <time.h> |
#include <time.h> |
| 26 |
|
#include <sys/param.h> |
| 27 |
#define _POSIX_C_SOURCE 200809L |
#define _POSIX_C_SOURCE 200809L |
| 28 |
#include <string.h> |
#include <string.h> |
| 29 |
|
|
| 30 |
|
static int section_topic_view_mode = 0; |
| 31 |
|
|
| 32 |
enum select_cmd_t |
enum select_cmd_t |
| 33 |
{ |
{ |
| 34 |
EXIT_SECTION = 0, |
EXIT_SECTION = 0, |
| 116 |
clearscr(); |
clearscr(); |
| 117 |
show_top(str_section_master, stitle, str_section_name); |
show_top(str_section_master, stitle, str_section_name); |
| 118 |
moveto(2, 0); |
moveto(2, 0); |
| 119 |
prints("离开[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] 阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m]\033[m 昵称[\033[1;32mn\033[0;37m]\033[m"); |
prints("返回[\033[1;32m←\033[0;37m,\033[1;32mESC\033[0;37m] 选择[\033[1;32m↑\033[0;37m,\033[1;32m↓\033[0;37m] " |
| 120 |
|
"阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m]\033[m %s[\033[1;32mn\033[0;37m]\033[m", |
| 121 |
|
(display_nickname ? "显示用户名" : "显示昵称")); |
| 122 |
moveto(3, 0); |
moveto(3, 0); |
| 123 |
if (display_nickname) |
if (display_nickname) |
| 124 |
{ |
{ |
| 125 |
prints("\033[44;37m \033[1;37m 编 号 发 布 者 昵 称 日 期 文 章 标 题 \033[m"); |
prints("\033[44;37m \033[1;37m 编 号 发布者昵称 日 期 文章标题 \033[m"); |
| 126 |
} |
} |
| 127 |
else |
else |
| 128 |
{ |
{ |
| 129 |
prints("\033[44;37m \033[1;37m 编 号 发 布 者 日 期 文 章 标 题 \033[m"); |
prints("\033[44;37m \033[1;37m 编 号 发 布 者 日 期 文章标题 \033[m"); |
| 130 |
} |
} |
|
show_bottom(""); |
|
| 131 |
|
|
| 132 |
return 0; |
return 0; |
| 133 |
} |
} |
| 246 |
return EXIT_SECTION; |
return EXIT_SECTION; |
| 247 |
} |
} |
| 248 |
|
|
| 249 |
|
static int display_article_key_handler(int *p_key, DISPLAY_CTX *p_ctx) |
| 250 |
|
{ |
| 251 |
|
switch (*p_key) |
| 252 |
|
{ |
| 253 |
|
case 'p': |
| 254 |
|
section_topic_view_mode = !section_topic_view_mode; |
| 255 |
|
case 0: // Set msg |
| 256 |
|
if (section_topic_view_mode) |
| 257 |
|
{ |
| 258 |
|
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 259 |
|
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ " |
| 260 |
|
"同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] │ " |
| 261 |
|
"帮助[\033[32mh\033[33m] |"); |
| 262 |
|
} |
| 263 |
|
else |
| 264 |
|
{ |
| 265 |
|
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 266 |
|
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ " |
| 267 |
|
"移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ " |
| 268 |
|
"帮助[\033[32mh\033[33m] |"); |
| 269 |
|
} |
| 270 |
|
*p_key = 0; |
| 271 |
|
break; |
| 272 |
|
} |
| 273 |
|
|
| 274 |
|
return 0; |
| 275 |
|
} |
| 276 |
|
|
| 277 |
int section_list_display(const char *sname) |
int section_list_display(const char *sname) |
| 278 |
{ |
{ |
| 279 |
static int display_nickname = 0; |
static int display_nickname = 0; |
| 281 |
SECTION_LIST *p_section; |
SECTION_LIST *p_section; |
| 282 |
char stitle[BBS_section_title_max_len + 1]; |
char stitle[BBS_section_title_max_len + 1]; |
| 283 |
char master_list[(BBS_username_max_len + 1) * 3 + 1]; |
char master_list[(BBS_username_max_len + 1) * 3 + 1]; |
| 284 |
|
char page_info_str[LINE_BUFFER_LEN]; |
| 285 |
ARTICLE *p_articles[BBS_article_limit_per_page]; |
ARTICLE *p_articles[BBS_article_limit_per_page]; |
| 286 |
int article_count; |
int article_count; |
| 287 |
|
int page_count; |
| 288 |
int page_id = 0; |
int page_id = 0; |
| 289 |
int selected_index = 0; |
int selected_index = 0; |
| 290 |
|
ARTICLE_CACHE cache; |
| 291 |
int ret; |
int ret; |
| 292 |
|
|
| 293 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 320 |
return -2; |
return -2; |
| 321 |
} |
} |
| 322 |
|
|
| 323 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 324 |
if (ret < 0) |
if (ret < 0) |
| 325 |
{ |
{ |
| 326 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 340 |
log_error("section_list_draw_items(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("section_list_draw_items(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 341 |
return -4; |
return -4; |
| 342 |
} |
} |
| 343 |
|
|
| 344 |
|
snprintf(page_info_str, sizeof(page_info_str), |
| 345 |
|
"\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]", |
| 346 |
|
page_id + 1, MAX(page_count, 1)); |
| 347 |
|
|
| 348 |
|
show_bottom(page_info_str); |
| 349 |
iflush(); |
iflush(); |
| 350 |
|
|
| 351 |
ret = section_list_select(p_section->page_count, article_count, &page_id, &selected_index); |
ret = section_list_select(page_count, article_count, &page_id, &selected_index); |
| 352 |
switch (ret) |
switch (ret) |
| 353 |
{ |
{ |
| 354 |
case EXIT_SECTION: |
case EXIT_SECTION: |
| 355 |
return 0; |
return 0; |
| 356 |
case CHANGE_PAGE: |
case CHANGE_PAGE: |
| 357 |
ret = query_section_articles(p_section, page_id, p_articles, &article_count); |
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 358 |
if (ret < 0) |
if (ret < 0) |
| 359 |
{ |
{ |
| 360 |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 370 |
} |
} |
| 371 |
break; |
break; |
| 372 |
case VIEW_ARTICLE: |
case VIEW_ARTICLE: |
| 373 |
log_std("Debug: article %d selected\n", p_articles[selected_index]->aid); |
ret = article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]); |
| 374 |
|
if (ret < 0) |
| 375 |
|
{ |
| 376 |
|
log_error("article_cache_load(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 377 |
|
break; |
| 378 |
|
} |
| 379 |
|
|
| 380 |
|
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 1, 0, |
| 381 |
|
display_article_key_handler, DATA_READ_HELP); |
| 382 |
|
if (ret < 0) |
| 383 |
|
{ |
| 384 |
|
log_error("display_data(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 385 |
|
break; |
| 386 |
|
} |
| 387 |
|
|
| 388 |
|
ret = article_cache_unload(&cache); |
| 389 |
|
if (ret < 0) |
| 390 |
|
{ |
| 391 |
|
log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 392 |
|
break; |
| 393 |
|
} |
| 394 |
|
|
| 395 |
|
// TODO: locate last viewed article |
| 396 |
case REFRESH_SCREEN: |
case REFRESH_SCREEN: |
| 397 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 398 |
{ |
{ |