/[LeafOK_CVS]/lbbs/src/section_list_display.c
ViewVC logotype

Diff of /lbbs/src/section_list_display.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.7 by sysadm, Thu May 29 02:45:23 2025 UTC Revision 1.10 by sysadm, Fri May 30 12:51:00 2025 UTC
# Line 16  Line 16 
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"
# Line 113  static int section_list_draw_screen(cons Line 114  static int section_list_draw_screen(cons
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;
# Line 241  static enum select_cmd_t section_list_se Line 244  static enum select_cmd_t section_list_se
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;
# Line 254  int section_list_display(const char *sna Line 296  int section_list_display(const char *sna
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);
# Line 310  int section_list_display(const char *sna Line 353  int section_list_display(const char *sna
353                  snprintf(page_info_str, sizeof(page_info_str),                  snprintf(page_info_str, sizeof(page_info_str),
354                                   "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",                                   "\033[33m[第\033[36m%d\033[33m/\033[36m%d\033[33m页]",
355                                   page_id + 1, MAX(page_count, 1));                                   page_id + 1, MAX(page_count, 1));
356                    
357                  show_bottom(page_info_str);                  show_bottom(page_info_str);
358                  iflush();                  iflush();
359    
# Line 336  int section_list_display(const char *sna Line 379  int section_list_display(const char *sna
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                          {                          {


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1