| 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" |
| 114 |
clearscr(); |
clearscr(); |
| 115 |
show_top(str_section_master, stitle, str_section_name); |
show_top(str_section_master, stitle, str_section_name); |
| 116 |
moveto(2, 0); |
moveto(2, 0); |
| 117 |
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] " |
| 118 |
|
"阅读[\033[1;32m→\033[0;37m,\033[1;32mENTER\033[0;37m]\033[m %s[\033[1;32mn\033[0;37m]\033[m", |
| 119 |
|
(display_nickname ? "显示用户名" : "显示昵称")); |
| 120 |
moveto(3, 0); |
moveto(3, 0); |
| 121 |
if (display_nickname) |
if (display_nickname) |
| 122 |
{ |
{ |
| 123 |
prints("\033[44;37m \033[1;37m 编 号 发 布 者 昵 称 日 期 文 章 标 题 \033[m"); |
prints("\033[44;37m \033[1;37m 编 号 发布者昵称 日 期 文章标题 \033[m"); |
| 124 |
} |
} |
| 125 |
else |
else |
| 126 |
{ |
{ |
| 127 |
prints("\033[44;37m \033[1;37m 编 号 发 布 者 日 期 文 章 标 题 \033[m"); |
prints("\033[44;37m \033[1;37m 编 号 发 布 者 日 期 文章标题 \033[m"); |
| 128 |
} |
} |
| 129 |
|
|
| 130 |
return 0; |
return 0; |
| 244 |
return EXIT_SECTION; |
return EXIT_SECTION; |
| 245 |
} |
} |
| 246 |
|
|
| 247 |
|
static int display_article_key_handler(int *key, char *msg, size_t msg_len) |
| 248 |
|
{ |
| 249 |
|
static int topic_view = 0; |
| 250 |
|
|
| 251 |
|
switch (*key) |
| 252 |
|
{ |
| 253 |
|
case 0: // Set msg |
| 254 |
|
snprintf(msg, msg_len, |
| 255 |
|
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ " |
| 256 |
|
"移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ " |
| 257 |
|
"帮助[\033[32mh\033[33m] |"); |
| 258 |
|
break; |
| 259 |
|
case 'p': |
| 260 |
|
break; |
| 261 |
|
topic_view = !topic_view; |
| 262 |
|
if (topic_view) |
| 263 |
|
{ |
| 264 |
|
snprintf(msg, msg_len, |
| 265 |
|
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ " |
| 266 |
|
"同主题阅读[\033[32m↑\033[33m/\033[32m↓\033[33m] │ " |
| 267 |
|
"帮助[\033[32mh\033[33m] |"); |
| 268 |
|
} |
| 269 |
|
else |
| 270 |
|
{ |
| 271 |
|
snprintf(msg, msg_len, |
| 272 |
|
"| 返回[\033[32m←\033[33m,\033[32mESC\033[33m] │ " |
| 273 |
|
"移动[\033[32m↑\033[33m/\033[32m↓\033[33m/\033[32mPgUp\033[33m/\033[32mPgDn\033[33m] │ " |
| 274 |
|
"帮助[\033[32mh\033[33m] |"); |
| 275 |
|
} |
| 276 |
|
*key = 0; |
| 277 |
|
break; |
| 278 |
|
case 'H': |
| 279 |
|
*key = 'h'; |
| 280 |
|
return 0; |
| 281 |
|
} |
| 282 |
|
|
| 283 |
|
return 0; |
| 284 |
|
} |
| 285 |
|
|
| 286 |
int section_list_display(const char *sname) |
int section_list_display(const char *sname) |
| 287 |
{ |
{ |
| 288 |
static int display_nickname = 0; |
static int display_nickname = 0; |
| 296 |
int page_count; |
int page_count; |
| 297 |
int page_id = 0; |
int page_id = 0; |
| 298 |
int selected_index = 0; |
int selected_index = 0; |
| 299 |
|
ARTICLE_CACHE cache; |
| 300 |
int ret; |
int ret; |
| 301 |
|
|
| 302 |
p_section = section_list_find_by_name(sname); |
p_section = section_list_find_by_name(sname); |
| 350 |
return -4; |
return -4; |
| 351 |
} |
} |
| 352 |
|
|
| 353 |
snprintf(page_info_str, sizeof(page_info_str), "第%d/%d页", page_id + 1, MAX(page_count, 1)); |
snprintf(page_info_str, sizeof(page_info_str), |
| 354 |
|
"\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]", |
| 355 |
|
page_id + 1, MAX(page_count, 1)); |
| 356 |
|
|
| 357 |
show_bottom(page_info_str); |
show_bottom(page_info_str); |
| 358 |
iflush(); |
iflush(); |
| 359 |
|
|
| 379 |
} |
} |
| 380 |
break; |
break; |
| 381 |
case VIEW_ARTICLE: |
case VIEW_ARTICLE: |
| 382 |
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]); |
| 383 |
|
if (ret < 0) |
| 384 |
|
{ |
| 385 |
|
log_error("article_cache_load(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 386 |
|
break; |
| 387 |
|
} |
| 388 |
|
|
| 389 |
|
ret = display_data(cache.p_data, cache.line_total, cache.line_offsets, 1, 0, |
| 390 |
|
display_article_key_handler, DATA_READ_HELP); |
| 391 |
|
if (ret < 0) |
| 392 |
|
{ |
| 393 |
|
log_error("display_data(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 394 |
|
break; |
| 395 |
|
} |
| 396 |
|
|
| 397 |
|
ret = article_cache_unload(&cache); |
| 398 |
|
if (ret < 0) |
| 399 |
|
{ |
| 400 |
|
log_error("article_cache_unload(aid=%d, cid=%d) error\n", p_articles[selected_index]->aid, p_articles[selected_index]->cid); |
| 401 |
|
break; |
| 402 |
|
} |
| 403 |
|
|
| 404 |
|
// TODO: locate last viewed article |
| 405 |
case REFRESH_SCREEN: |
case REFRESH_SCREEN: |
| 406 |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
if (section_list_draw_screen(sname, stitle, master_list, display_nickname) < 0) |
| 407 |
{ |
{ |