/[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.1 by sysadm, Wed May 28 07:30:23 2025 UTC Revision 1.4 by sysadm, Wed May 28 13:08:41 2025 UTC
# Line 31  enum select_cmd_t Line 31  enum select_cmd_t
31          VIEW_ARTICLE = 1,          VIEW_ARTICLE = 1,
32          CHANGE_PAGE = 2,          CHANGE_PAGE = 2,
33          REFRESH_SCREEN = 3,          REFRESH_SCREEN = 3,
34            CHANGE_NAME_DISPLAY = 4,
35  };  };
36    
37  static int section_list_draw_items(SECTION_LIST *p_section, int page_id, ARTICLE *p_articles[], int article_count)  static int section_list_draw_items(SECTION_LIST *p_section, int page_id, ARTICLE *p_articles[], int article_count, int display_nickname)
38  {  {
39          char str_time[LINE_BUFFER_LEN];          char str_time[LINE_BUFFER_LEN];
40          struct tm tm_sub;          struct tm tm_sub;
# Line 42  static int section_list_draw_items(SECTI Line 43  static int section_list_draw_items(SECTI
43          int eol;          int eol;
44          int len;          int len;
45          int i;          int i;
46            char article_flag;
47            time_t tm_now;
48    
49            time(&tm_now);
50    
51          clrline(4, 23);          clrline(4, 23);
52    
53          for (i = 0; i < article_count; i++)          for (i = 0; i < article_count; i++)
54          {          {
55                    article_flag = ' ';
56    
57                    if (p_articles[i]->excerption)
58                    {
59                            article_flag = 'm';
60                    }
61                    else if (p_articles[i]->lock)
62                    {
63                            article_flag = 'x';
64                    }
65    
66                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);                  localtime_r(&p_articles[i]->sub_dt, &tm_sub);
67                  strftime(str_time, sizeof(str_time), "%b %e", &tm_sub);                  if (tm_now - p_articles[i]->sub_dt < 3600 * 24 * 365)
68                  strncpy(title_f, p_articles[i]->title, sizeof(title_f) - 1);                  {
69                            strftime(str_time, sizeof(str_time), "%b %e ", &tm_sub);
70                    }
71                    else
72                    {
73                            strftime(str_time, sizeof(str_time), "%m/%Y", &tm_sub);
74                    }
75    
76                    strncpy(title_f, (p_articles[i]->tid == 0 ? "● " : ""), sizeof(title_f) - 1);
77                  title_f[sizeof(title_f) - 1] = '\0';                  title_f[sizeof(title_f) - 1] = '\0';
78                  len = split_line(title_f, (p_articles[i]->tid == 0 ? 40 : 37), &eol, &title_f_len);                  strncat(title_f, (p_articles[i]->transship ? "[转载]" : ""), sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
79                    strncat(title_f, p_articles[i]->title, sizeof(title_f) - 1 - strnlen(title_f, sizeof(title_f)));
80                    len = split_line(title_f, 47 - (display_nickname ? 8 : 0), &eol, &title_f_len);
81                  if (title_f[len] != '\0')                  if (title_f[len] != '\0')
82                  {                  {
83                          title_f[len] = '\0';                          title_f[len] = '\0';
84                  }                  }
85    
86                  moveto(4 + i, 1);                  moveto(4 + i, 1);
87                  prints("  %7d %s%*s %s  %s%s",                  prints("  %7d %c %s%*s %s %s",
88                             p_articles[i]->aid,                             p_articles[i]->aid,
89                             p_articles[i]->username,                             article_flag,
90                             BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username)),                             (display_nickname ? p_articles[i]->nickname : p_articles[i]->username),
91                               (display_nickname ? BBS_nickname_max_len - (int)strnlen(p_articles[i]->nickname, sizeof(p_articles[i]->nickname))
92                                                                     : BBS_username_max_len - (int)strnlen(p_articles[i]->username, sizeof(p_articles[i]->username))),
93                             "",                             "",
94                             str_time,                             str_time,
                            (p_articles[i]->tid == 0 ? "● " : ""),  
95                             title_f);                             title_f);
96          }          }
97    
98          return 0;          return 0;
99  }  }
100    
101  static int section_list_draw_screen(SECTION_LIST *p_section)  static int section_list_draw_screen(SECTION_LIST *p_section, int display_nickname)
102  {  {
103          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";          char str_section_master[LINE_BUFFER_LEN] = "诚征版主中";
104          char str_section_name[LINE_BUFFER_LEN];          char str_section_name[LINE_BUFFER_LEN];
# Line 85  static int section_list_draw_screen(SECT Line 112  static int section_list_draw_screen(SECT
112          clearscr();          clearscr();
113          show_top(str_section_master, p_section->stitle, str_section_name);          show_top(str_section_master, p_section->stitle, str_section_name);
114          moveto(2, 0);          moveto(2, 0);
115          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");          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");
116          moveto(3, 0);          moveto(3, 0);
117          prints("\033[44;37m  \033[1;37m 编 号  发 布 者     日  期  文 章 标 题                                      \033[m");          if (display_nickname)
118            {
119                    prints("\033[44;37m  \033[1;37m 编  号   发 布 者 昵 称       日  期  文 章 标 题                            \033[m");
120            }
121            else
122            {
123                    prints("\033[44;37m  \033[1;37m 编  号   发 布 者     日  期  文 章 标 题                                    \033[m");
124            }
125          show_bottom("");          show_bottom("");
126    
127          return 0;          return 0;
# Line 124  static enum select_cmd_t section_list_se Line 158  static enum select_cmd_t section_list_se
158                                  return EXIT_SECTION; // exit section                                  return EXIT_SECTION; // exit section
159                          }                          }
160                          continue;                          continue;
161                    case 'n':
162                            return CHANGE_NAME_DISPLAY;
163                  case CR:                  case CR:
164                          igetch_reset();                          igetch_reset();
165                  case KEY_RIGHT:                  case KEY_RIGHT:
# Line 207  static enum select_cmd_t section_list_se Line 243  static enum select_cmd_t section_list_se
243    
244  int section_list_display(const char *sname)  int section_list_display(const char *sname)
245  {  {
246            static int display_nickname = 0;
247    
248          SECTION_LIST *p_section;          SECTION_LIST *p_section;
249          ARTICLE *p_articles[BBS_article_limit_per_page];          ARTICLE *p_articles[BBS_article_limit_per_page];
250          int article_count;          int article_count;
# Line 221  int section_list_display(const char *sna Line 259  int section_list_display(const char *sna
259                  return -1;                  return -1;
260          }          }
261    
262          if (section_list_draw_screen(p_section) < 0)          if (section_list_draw_screen(p_section, display_nickname) < 0)
263          {          {
264                  log_error("section_list_draw_screen() error\n");                  log_error("section_list_draw_screen() error\n");
265                  return -2;                  return -2;
# Line 244  int section_list_display(const char *sna Line 282  int section_list_display(const char *sna
282    
283          while (!SYS_server_exit)          while (!SYS_server_exit)
284          {          {
285                  ret = section_list_draw_items(p_section, page_id, p_articles, article_count);                  ret = section_list_draw_items(p_section, page_id, p_articles, article_count, display_nickname);
286                  if (ret < 0)                  if (ret < 0)
287                  {                  {
288                          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);
# Line 280  int section_list_display(const char *sna Line 318  int section_list_display(const char *sna
318                  case VIEW_ARTICLE:                  case VIEW_ARTICLE:
319                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);                          log_std("Debug: article %d selected\n", p_articles[selected_index]->aid);
320                  case REFRESH_SCREEN:                  case REFRESH_SCREEN:
321                          if (section_list_draw_screen(p_section) < 0)                          if (section_list_draw_screen(p_section, display_nickname) < 0)
322                            {
323                                    log_error("section_list_draw_screen() error\n");
324                                    return -2;
325                            }
326                            break;
327                    case CHANGE_NAME_DISPLAY:
328                            display_nickname = !display_nickname;
329                            if (section_list_draw_screen(p_section, display_nickname) < 0)
330                          {                          {
331                                  log_error("section_list_draw_screen() error\n");                                  log_error("section_list_draw_screen() error\n");
332                                  return -2;                                  return -2;


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

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