| 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, |
| 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; |
| 287 |
int page_count; |
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); |
| 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 |
{ |
{ |