Fix a bug with displaying blank spaces with bce on.
[screen-lua.git] / src / list_display.c
blob4e740c11db2696eefddcce5e9fd88593839ae911
1 /* Copyright (c) 2010
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
4 * Copyright (c) 2008, 2009
5 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
6 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
7 * Micah Cowan (micah@cowan.name)
8 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
9 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
10 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
11 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
12 * Copyright (c) 1987 Oliver Laumann
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3, or (at your option)
17 * any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program (see the file COPYING); if not, see
26 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
29 ****************************************************************
32 /* Deals with the list of displays */
34 #include "config.h"
36 #include "screen.h"
37 #include "list_generic.h"
39 #ifdef MULTI
41 extern struct layer *flayer;
42 extern struct display *display, *displays;
43 extern struct mchar mchar_blank, mchar_so;
45 static char ListID[] = "display";
48 * layout of the displays page is as follows:
50 xterm 80x42 jnweiger@/dev/ttyp4 0(m11) &rWx
51 facit 80x24 nb mlschroe@/dev/ttyhf 11(tcsh) rwx
52 xterm 80x42 jnhollma@/dev/ttyp5 0(m11) &R.x
54 | | | | | | | | ¦___ window permissions
55 | | | | | | | | (R. is locked r-only,
56 | | | | | | | | W has wlock)
57 | | | | | | | |___ Window is shared
58 | | | | | | |___ Name/Title of window
59 | | | | | |___ Number of window
60 | | | | |___ Name of the display (the attached device)
61 | | | |___ Username who is logged in at the display
62 | | |___ Display is in nonblocking mode. Shows 'NB' if obuf is full.
63 | |___ Displays geometry as width x height.
64 |___ the terminal type known by screen for this display.
68 static int
69 gl_Display_header(struct ListData *ldata)
71 leftline("term-type size user interface window Perms", 0, 0);
72 leftline("---------- ------- ---------- ----------------- ---------- -----", 1, 0);
73 return 2;
76 static int
77 gl_Display_footer(struct ListData *ldata)
79 centerline("[Press Space to refresh; Return to end.]", flayer->l_height - 1);
82 static int
83 gl_Display_row(struct ListData *ldata, struct ListRow *lrow)
85 struct display *d = lrow->data;
86 char tbuf[80];
87 static char *blockstates[5] = {"nb", "NB", "Z<", "Z>", "BL"};
88 struct win *w = d->d_fore;
89 struct mchar m_current = mchar_blank;
90 m_current.attr = A_BD;
92 sprintf(tbuf, " %-10.10s%4dx%-4d%10.10s@%-16.16s%s",
93 d->d_termname, d->d_width, d->d_height, d->d_user->u_name,
94 d->d_usertty,
95 (d->d_blocked || d->d_nonblock >= 0) && d->d_blocked <= 4 ? blockstates[d->d_blocked] : " ");
97 if (w)
99 int l = 10 - strlen(w->w_title);
100 if (l < 0)
101 l = 0;
102 sprintf(tbuf + strlen(tbuf), "%3d(%.10s)%*s%c%c%c%c",
103 w->w_number, w->w_title, l, "",
104 /* w->w_dlist->next */ 0 ? '&' : ' ',
106 * The rwx triple:
107 * -,r,R no read, read, read only due to foreign wlock
108 * -,.,w,W no write, write suppressed by foreign wlock,
109 * write, own wlock
110 * -,x no execute, execute
112 #ifdef MULTIUSER
113 (AclCheckPermWin(d->d_user, ACL_READ, w) ? '-' :
114 ((w->w_wlock == WLOCK_OFF || d->d_user == w->w_wlockuser) ?
115 'r' : 'R')),
116 (AclCheckPermWin(d->d_user, ACL_READ, w) ? '-' :
117 ((w->w_wlock == WLOCK_OFF) ? 'w' :
118 ((d->d_user == w->w_wlockuser) ? 'W' : 'v'))),
119 (AclCheckPermWin(d->d_user, ACL_READ, w) ? '-' : 'x')
120 #else
121 'r', 'w', 'x'
122 #endif
125 leftline(tbuf, lrow->y, lrow == ldata->selected ? &mchar_so : d == display ? &m_current : 0);
127 return 1;
130 static void
131 gl_Display_rebuild(struct ListData *ldata)
133 /* recreate the rows */
134 struct display *d;
135 struct ListRow *row = NULL;
136 for (d = displays; d; d = d->d_next)
138 row = glist_add_row(ldata, d, row);
139 if (d == display)
140 ldata->selected = row;
143 glist_display_all(ldata);
146 static int
147 gl_Display_input(struct ListData *ldata, char **inp, int *len)
149 struct display *cd = display;
150 unsigned char ch;
152 if (!ldata->selected)
153 return 0;
155 ch = (unsigned char) **inp;
156 ++*inp;
157 --*len;
159 switch (ch)
161 case ' ': /* Space to refresh */
162 glist_remove_rows(ldata);
163 gl_Display_rebuild(ldata);
164 break;
166 case '\r':
167 case '\n':
168 glist_abort();
169 *len = 0;
170 break;
172 #ifdef REMOTE_DETACH
173 case 'd': /* Detach */
174 case 'D': /* Power detach */
175 display = ldata->selected->data;
176 if (display == cd) /* We do not allow detaching the current display */
177 break;
178 Detach(
179 #ifdef POW_DETACH
180 ch == 'D' ? D_REMOTE_POWER : D_REMOTE
181 #else
182 D_REMOTE
183 #endif
185 display = cd;
186 glist_remove_rows(ldata);
187 gl_Display_rebuild(ldata);
188 break;
189 #endif
191 default:
192 /* We didn't actually process the input. */
193 --*inp;
194 ++*len;
195 return 0;
197 return 1;
200 static int
201 gl_Display_freerow(struct ListData *ldata, struct ListRow *row)
203 /* There was no allocation when row->data was set. So nothing to do here. */
204 return 0;
207 static int
208 gl_Display_free(struct ListData *ldata)
210 /* There was no allocation in ldata->data. So nothing to do here. */
211 return 0;
214 static struct GenericList gl_Display =
216 gl_Display_header,
217 gl_Display_footer,
218 gl_Display_row,
219 gl_Display_input,
220 gl_Display_freerow,
221 gl_Display_free,
222 NULL /* We do not allow searching in the display list, at the moment */
225 void
226 display_displays()
228 struct ListData *ldata;
229 if (flayer->l_width < 10 || flayer->l_height < 5)
231 LMsg(0, "Window size too small for displays page");
232 return;
235 ldata = glist_display(&gl_Display, ListID);
236 if (!ldata)
237 return;
239 gl_Display_rebuild(ldata);
242 #endif /* MULTI */