diff options
Diffstat (limited to 'other/zylyx/src/screen.c')
| -rw-r--r-- | other/zylyx/src/screen.c | 311 |
1 files changed, 311 insertions, 0 deletions
diff --git a/other/zylyx/src/screen.c b/other/zylyx/src/screen.c new file mode 100644 index 0000000..a4c707c --- /dev/null +++ b/other/zylyx/src/screen.c | |||
| @@ -0,0 +1,311 @@ | |||
| 1 | /* zylyx - file find | ||
| 2 | * | ||
| 3 | * screen and output module | ||
| 4 | * | ||
| 5 | * by team teso | ||
| 6 | */ | ||
| 7 | |||
| 8 | #define _ZYL_SCR_MAIN | ||
| 9 | |||
| 10 | #include <pthread.h> | ||
| 11 | #include <stdarg.h> | ||
| 12 | #include <stdlib.h> | ||
| 13 | #include <stdio.h> | ||
| 14 | #include <string.h> | ||
| 15 | #include <slang.h> | ||
| 16 | #include "screen.h" | ||
| 17 | #include "zylyx.h" | ||
| 18 | |||
| 19 | |||
| 20 | pthread_mutex_t screen_mutex; | ||
| 21 | |||
| 22 | void | ||
| 23 | scr_init (void) | ||
| 24 | { | ||
| 25 | int n; | ||
| 26 | |||
| 27 | pthread_mutex_init (&screen_mutex, NULL); | ||
| 28 | SLtt_get_terminfo (); | ||
| 29 | SLang_init_tty (-1, 0, 0); | ||
| 30 | n = SLsmg_init_smg (); | ||
| 31 | if (n == -1) { | ||
| 32 | fprintf (stderr, "SLsmg_init_smg failed\n"); | ||
| 33 | exit (EXIT_FAILURE); | ||
| 34 | } | ||
| 35 | SLsmg_cls (); | ||
| 36 | scr_init_col (); | ||
| 37 | SLsmg_refresh (); | ||
| 38 | |||
| 39 | return; | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | void | ||
| 44 | scr_init_col (void) | ||
| 45 | { | ||
| 46 | /* give us some sneezy colors, oh yeah | ||
| 47 | */ | ||
| 48 | |||
| 49 | SLtt_set_color (COL_SPICY, NULL, "white", "black"); | ||
| 50 | SLtt_set_color (COL_MSPICY, NULL, "brightblue", "black"); | ||
| 51 | SLtt_set_color (COL_LSPICY, NULL, "blue", "black"); | ||
| 52 | SLtt_set_color (COL_TEXT, NULL, "gray", "black"); | ||
| 53 | SLtt_set_color (COL_STEXT, NULL, "brightgreen", "black"); | ||
| 54 | SLtt_set_color (COL_PRX_INACT, NULL, "green", "black"); | ||
| 55 | |||
| 56 | return; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | void | ||
| 61 | scr_prg_init (void) | ||
| 62 | { | ||
| 63 | scr_build_box (0, 0, SLtt_Screen_Cols - 1, 6); | ||
| 64 | scr_build_box (0, 6, SLtt_Screen_Cols - 1, SLtt_Screen_Rows - 1); | ||
| 65 | |||
| 66 | scr_banner (); | ||
| 67 | |||
| 68 | SLsmg_refresh (); | ||
| 69 | |||
| 70 | return; | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | void | ||
| 75 | scr_banner (void) | ||
| 76 | { | ||
| 77 | scr_cprint (2, 1, ":05zylyx v"VERSION":01 - :05file find:01 - :02"AUTHORS"\n"); | ||
| 78 | |||
| 79 | scr_cprint (2, 3, ":05o :02opening connection :02c connected :04- :02connection failed\n"); | ||
| 80 | scr_cprint (2, 4, ":02g :02try to get file :02r receiving :03j :02junk :04f :02file not found\n"); | ||
| 81 | scr_cprint (2, 5, ":04t :02timeouted :01! :02file found\n"); | ||
| 82 | |||
| 83 | return; | ||
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | int | ||
| 88 | scr_rprintf (int x, int y, const char *str, ...) | ||
| 89 | { | ||
| 90 | char tmp[1025]; | ||
| 91 | va_list vl; | ||
| 92 | int i; | ||
| 93 | |||
| 94 | va_start (vl, str); | ||
| 95 | memset (tmp, '\0', sizeof (tmp)); | ||
| 96 | i = vsnprintf (tmp, sizeof (tmp) - 1, str, vl); | ||
| 97 | va_end (vl); | ||
| 98 | |||
| 99 | scr_rprint (x, y, tmp); | ||
| 100 | SLsmg_refresh (); | ||
| 101 | |||
| 102 | return (i); | ||
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | void | ||
| 107 | scr_rprint (int x, int y, char *str) | ||
| 108 | { | ||
| 109 | scr_cprint (x, y, str); | ||
| 110 | SLsmg_refresh (); | ||
| 111 | } | ||
| 112 | |||
| 113 | |||
| 114 | void | ||
| 115 | scr_cprint (int x, int y, char *str) | ||
| 116 | { | ||
| 117 | pthread_mutex_lock (&screen_mutex); | ||
| 118 | SLsmg_gotorc (y, x); | ||
| 119 | scr_print (str); | ||
| 120 | pthread_mutex_unlock (&screen_mutex); | ||
| 121 | } | ||
| 122 | |||
| 123 | |||
| 124 | void | ||
| 125 | scr_print (char *str1) | ||
| 126 | { | ||
| 127 | char *str = strdup (str1); | ||
| 128 | char *prc = str; /* process pointer */ | ||
| 129 | char *print_str; | ||
| 130 | int color; | ||
| 131 | |||
| 132 | if (str[0] == ':') { | ||
| 133 | if (sscanf (str + 1, "%d", &color) != 1) | ||
| 134 | goto p_fail; | ||
| 135 | SLsmg_set_color (color); | ||
| 136 | prc += 3; | ||
| 137 | } | ||
| 138 | |||
| 139 | while ((print_str = strsep (&prc, ":")) != NULL) { | ||
| 140 | SLsmg_write_string (print_str); | ||
| 141 | if (prc == NULL) | ||
| 142 | goto p_fail; | ||
| 143 | if (sscanf (prc, "%d", &color) != 1) | ||
| 144 | goto p_fail; | ||
| 145 | SLsmg_set_color (color); | ||
| 146 | prc += 2; | ||
| 147 | } | ||
| 148 | |||
| 149 | p_fail: | ||
| 150 | free (str); | ||
| 151 | |||
| 152 | return; | ||
| 153 | } | ||
| 154 | |||
| 155 | |||
| 156 | void | ||
| 157 | scr_build_box (int x1, int y1, int x2, int y2) | ||
| 158 | { | ||
| 159 | pthread_mutex_lock (&screen_mutex); | ||
| 160 | |||
| 161 | scr_build_sline_v (x1, y1, ((y2 - y1) / 2) + y1, '+', '|', '+', COL_SPICY, COL_MSPICY, COL_LSPICY); | ||
| 162 | scr_build_sline_v (x2, y1, ((y2 - y1) / 2) + y1, '+', '|', '+', COL_SPICY, COL_MSPICY, COL_LSPICY); | ||
| 163 | scr_build_sline_h (y1, x1 + 1, ((x2 - x1 - 2) / 2) + x1, '-', '-', '-', COL_SPICY, COL_MSPICY, COL_LSPICY); | ||
| 164 | scr_build_sline_h (y2, x1 + 1, ((x2 - x1 - 2) / 2) + x1, '-', '-', '-', COL_SPICY, COL_MSPICY, COL_LSPICY); | ||
| 165 | |||
| 166 | scr_build_sline_v (x1, y2, ((y2 - y1) / 2) + y1, '|', '|', '+', COL_SPICY, COL_MSPICY, COL_LSPICY); | ||
| 167 | scr_build_sline_v (x2, y2, ((y2 - y1) / 2) + y1, '|', '|', '+', COL_SPICY, COL_MSPICY, COL_LSPICY); | ||
| 168 | scr_build_sline_h (y1, x2 - 1, ((x2 - x1) / 2) + x1, '-', '-', '-', COL_SPICY, COL_MSPICY, COL_LSPICY); | ||
| 169 | scr_build_sline_h (y2, x2 - 1, ((x2 - x1) / 2) + x1, '-', '-', '-', COL_SPICY, COL_MSPICY, COL_LSPICY); | ||
| 170 | |||
| 171 | pthread_mutex_unlock (&screen_mutex); | ||
| 172 | |||
| 173 | return; | ||
| 174 | } | ||
| 175 | |||
| 176 | |||
| 177 | void | ||
| 178 | scr_build_sline_v (int x, int y1, int y2, char start, char fill, char end, | ||
| 179 | int objhigh, int objmed, int objlow) | ||
| 180 | { | ||
| 181 | int ly2, ly3; | ||
| 182 | |||
| 183 | if (y1 > y2) { | ||
| 184 | int obj_tmp; | ||
| 185 | |||
| 186 | y2 ^= y1; | ||
| 187 | y1 ^= y2; | ||
| 188 | y2 ^= y1; | ||
| 189 | |||
| 190 | obj_tmp = objhigh; | ||
| 191 | objhigh = objlow; | ||
| 192 | objlow = objmed; | ||
| 193 | objmed = obj_tmp; | ||
| 194 | |||
| 195 | ly2 = ((y2 - y1) - ((y2 - y1) / 8)) + y1; | ||
| 196 | ly3 = ((y2 - y1) - ((y2 - y1) / 4)) + y1; | ||
| 197 | } else { | ||
| 198 | ly2 = ((y2 - y1) / 8) + y1; | ||
| 199 | ly3 = ((y2 - y1) / 4) + y1; | ||
| 200 | } | ||
| 201 | |||
| 202 | SLsmg_set_color (objhigh); | ||
| 203 | SLsmg_gotorc (y1, x); | ||
| 204 | SLsmg_write_char (start); | ||
| 205 | |||
| 206 | for (++y1 ; y1 < y2 ; ++y1) { | ||
| 207 | if (y1 == ly2) { | ||
| 208 | SLsmg_set_color (objmed); | ||
| 209 | } else if (y1 == ly3) { | ||
| 210 | SLsmg_set_color (objlow); | ||
| 211 | } | ||
| 212 | SLsmg_gotorc (y1, x); | ||
| 213 | SLsmg_write_char (fill); | ||
| 214 | } | ||
| 215 | SLsmg_gotorc (y2, x); | ||
| 216 | SLsmg_write_char (end); | ||
| 217 | |||
| 218 | return; | ||
| 219 | } | ||
| 220 | |||
| 221 | |||
| 222 | void | ||
| 223 | scr_build_sline_h (int y, int x1, int x2, char start, char fill, char end, | ||
| 224 | int objhigh, int objmed, int objlow) | ||
| 225 | { | ||
| 226 | int lx2, lx3; | ||
| 227 | |||
| 228 | if (x1 > x2) { | ||
| 229 | int obj_tmp; | ||
| 230 | |||
| 231 | x2 ^= x1; | ||
| 232 | x1 ^= x2; | ||
| 233 | x2 ^= x1; | ||
| 234 | obj_tmp = objhigh; | ||
| 235 | objhigh = objlow; | ||
| 236 | objlow = objmed; | ||
| 237 | objmed = obj_tmp; | ||
| 238 | lx2 = ((x2 - x1) - ((x2 - x1) / 8)) + x1; | ||
| 239 | lx3 = ((x2 - x1) - ((x2 - x1) / 4)) + x1; | ||
| 240 | } else { | ||
| 241 | lx2 = ((x2 - x1) / 8) + x1; | ||
| 242 | lx3 = ((x2 - x1) / 4) + x1; | ||
| 243 | } | ||
| 244 | |||
| 245 | SLsmg_set_color (objhigh); | ||
| 246 | SLsmg_gotorc (y, x1); | ||
| 247 | SLsmg_write_char (start); | ||
| 248 | |||
| 249 | for (++x1 ; x1 < x2 ; ++x1) { | ||
| 250 | if (x1 == lx2) { | ||
| 251 | SLsmg_set_color (objmed); | ||
| 252 | } else if (x1 == lx3) { | ||
| 253 | SLsmg_set_color (objlow); | ||
| 254 | } | ||
| 255 | SLsmg_gotorc (y, x1); | ||
| 256 | SLsmg_write_char (fill); | ||
| 257 | } | ||
| 258 | SLsmg_gotorc (y, x2); | ||
| 259 | SLsmg_write_char (end); | ||
| 260 | |||
| 261 | return; | ||
| 262 | } | ||
| 263 | |||
| 264 | |||
| 265 | void | ||
| 266 | scr_build_line_v (int obj, int x, int y1, int y2, char start, char fill, char end) | ||
| 267 | { | ||
| 268 | SLsmg_set_color (obj); | ||
| 269 | SLsmg_gotorc (y1, x); | ||
| 270 | SLsmg_write_char (start); | ||
| 271 | |||
| 272 | for (++y1 ; y1 < y2 ; ++y1) { | ||
| 273 | SLsmg_gotorc (y1, x); | ||
| 274 | SLsmg_write_char (fill); | ||
| 275 | } | ||
| 276 | |||
| 277 | SLsmg_gotorc (y2, x); | ||
| 278 | SLsmg_write_char (end); | ||
| 279 | |||
| 280 | return; | ||
| 281 | } | ||
| 282 | |||
| 283 | |||
| 284 | void | ||
| 285 | scr_build_line_h (int obj, int y, int x1, int x2, char start, char fill, char end) | ||
| 286 | { | ||
| 287 | SLsmg_set_color (obj); | ||
| 288 | SLsmg_gotorc (y, x1); | ||
| 289 | SLsmg_write_char (start); | ||
| 290 | |||
| 291 | for (++x1 ; x1 < x2 ; ++x1) { | ||
| 292 | SLsmg_gotorc (y, x1); | ||
| 293 | SLsmg_write_char (fill); | ||
| 294 | } | ||
| 295 | |||
| 296 | SLsmg_gotorc (y, x2); | ||
| 297 | SLsmg_write_char (end); | ||
| 298 | |||
| 299 | return; | ||
| 300 | } | ||
| 301 | |||
| 302 | |||
| 303 | void | ||
| 304 | scr_exit (void) | ||
| 305 | { | ||
| 306 | SLsmg_reset_smg (); | ||
| 307 | SLang_reset_tty (); | ||
| 308 | |||
| 309 | return; | ||
| 310 | } | ||
| 311 | |||
