| 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" |
| 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 |
} |
} |
| 131 |
|
|
| 132 |
return 0; |
return 0; |
| 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 |
|
case KEY_UP: |
| 273 |
|
if (p_ctx->reach_begin) |
| 274 |
|
{ |
| 275 |
|
if (section_topic_view_mode) |
| 276 |
|
{ |
| 277 |
|
*p_key = KEY_PGUP; |
| 278 |
|
} |
| 279 |
|
return 1; |
| 280 |
|
} |
| 281 |
|
break; |
| 282 |
|
case KEY_DOWN: |
| 283 |
|
if (p_ctx->reach_end) |
| 284 |
|
{ |
| 285 |
|
if (section_topic_view_mode) |
| 286 |
|
{ |
| 287 |
|
*p_key = KEY_PGDN; |
| 288 |
|
} |
| 289 |
|
return 1; |
| 290 |
|
} |
| 291 |
|
break; |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
return 0; |
| 295 |
|
} |
| 296 |
|
|
| 297 |
int section_list_display(const char *sname) |
int section_list_display(const char *sname) |
| 298 |
{ |
{ |
| 299 |
static int display_nickname = 0; |
static int display_nickname = 0; |
| 307 |
int page_count; |
int page_count; |
| 308 |
int page_id = 0; |
int page_id = 0; |
| 309 |
int selected_index = 0; |
int selected_index = 0; |
| 310 |
|
ARTICLE_CACHE cache; |
| 311 |
int ret; |
int ret; |
| 312 |
|
int loop; |
| 313 |
|
int direction; |
| 314 |
|
|
| 315 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 316 |
if (p_section == NULL) |
if (p_section == NULL) |
| 366 |
snprintf(page_info_str, sizeof(page_info_str), |
snprintf(page_info_str, sizeof(page_info_str), |
| 367 |
"\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]", |
"\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]", |
| 368 |
page_id + 1, MAX(page_count, 1)); |
page_id + 1, MAX(page_count, 1)); |
| 369 |
|
|
| 370 |
show_bottom(page_info_str); |
show_bottom(page_info_str); |
| 371 |
iflush(); |
iflush(); |
| 372 |
|
|
| 392 |
} |
} |
| 393 |
break; |
break; |
| 394 |
case VIEW_ARTICLE: |
case VIEW_ARTICLE: |
| 395 |
log_std("Debug: article %d selected\n", p_articles[selected_index]->aid); |
do |
| 396 |
|
{ |
| 397 |
|
loop = 0; |
| 398 |
|
|
| 399 |
|
if (article_cache_load(&cache, VAR_ARTICLE_CACHE_DIR, p_articles[selected_index]) < 0) |
| 400 |
|
{ |
| 401 |
|
log_error("article_cache_load(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 402 |
|
break; |
| 403 |
|
} |
| 404 |
|
|
| 405 |
|
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 1, 0, |
| 406 |
|
display_article_key_handler, DATA_READ_HELP); |
| 407 |
|
|
| 408 |
|
if (article_cache_unload(&cache) < 0) |
| 409 |
|
{ |
| 410 |
|
log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 411 |
|
break; |
| 412 |
|
} |
| 413 |
|
|
| 414 |
|
switch (ret) |
| 415 |
|
{ |
| 416 |
|
case KEY_UP: |
| 417 |
|
if (selected_index <= 0) |
| 418 |
|
{ |
| 419 |
|
if (page_id > 0) |
| 420 |
|
{ |
| 421 |
|
page_id--; |
| 422 |
|
selected_index = BBS_article_limit_per_page - 1; |
| 423 |
|
|
| 424 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 425 |
|
if (ret < 0) |
| 426 |
|
{ |
| 427 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 428 |
|
return -3; |
| 429 |
|
} |
| 430 |
|
|
| 431 |
|
if (article_count != BBS_article_limit_per_page) // page is not full |
| 432 |
|
{ |
| 433 |
|
selected_index = MAX(0, article_count - 1); |
| 434 |
|
} |
| 435 |
|
else |
| 436 |
|
{ |
| 437 |
|
loop = 1; |
| 438 |
|
} |
| 439 |
|
} |
| 440 |
|
} |
| 441 |
|
else |
| 442 |
|
{ |
| 443 |
|
selected_index--; |
| 444 |
|
loop = 1; |
| 445 |
|
} |
| 446 |
|
break; |
| 447 |
|
case KEY_DOWN: |
| 448 |
|
if (selected_index + 1 >= article_count) // next page |
| 449 |
|
{ |
| 450 |
|
if (page_id + 1 < page_count) |
| 451 |
|
{ |
| 452 |
|
page_id++; |
| 453 |
|
selected_index = 0; |
| 454 |
|
|
| 455 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 456 |
|
if (ret < 0) |
| 457 |
|
{ |
| 458 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 459 |
|
return -3; |
| 460 |
|
} |
| 461 |
|
|
| 462 |
|
if (article_count == 0) // empty page |
| 463 |
|
{ |
| 464 |
|
selected_index = 0; |
| 465 |
|
} |
| 466 |
|
else |
| 467 |
|
{ |
| 468 |
|
loop = 1; |
| 469 |
|
} |
| 470 |
|
} |
| 471 |
|
} |
| 472 |
|
else |
| 473 |
|
{ |
| 474 |
|
selected_index++; |
| 475 |
|
loop = 1; |
| 476 |
|
} |
| 477 |
|
break; |
| 478 |
|
case KEY_PGUP: |
| 479 |
|
case KEY_PGDN: |
| 480 |
|
direction = (ret == KEY_PGUP ? -1 : 1); |
| 481 |
|
ret = locate_article_in_section(p_section, p_articles[selected_index], direction, &page_id, &selected_index, &page_count); |
| 482 |
|
if (ret < 0) |
| 483 |
|
{ |
| 484 |
|
log_error("locate_article_in_section(sid=%d, aid=%d, direction=%d) error\n", |
| 485 |
|
p_section->sid, p_articles[selected_index]->aid, direction); |
| 486 |
|
return -3; |
| 487 |
|
} |
| 488 |
|
else if (ret > 0) |
| 489 |
|
{ |
| 490 |
|
ret = query_section_articles(p_section, page_id, p_articles, &article_count, &page_count); |
| 491 |
|
if (ret < 0) |
| 492 |
|
{ |
| 493 |
|
log_error("query_section_articles(sid=%d, page_id=%d) error\n", p_section->sid, page_id); |
| 494 |
|
return -3; |
| 495 |
|
} |
| 496 |
|
loop = 1; |
| 497 |
|
} |
| 498 |
|
break; |
| 499 |
|
} |
| 500 |
|
} while (loop); |
| 501 |
case REFRESH_SCREEN: |
case REFRESH_SCREEN: |
| 502 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 503 |
{ |
{ |