[BACK]Return to clock.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/clock.c, Revision 1.6

1.6     ! nicm        1: /* $OpenBSD: clock.c,v 1.5 2009/11/26 23:13:47 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
                     15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                     16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18:
                     19: #include <sys/types.h>
                     20:
                     21: #include <string.h>
                     22: #include <time.h>
                     23:
                     24: #include "tmux.h"
                     25:
                     26: const char clock_table[14][5][5] = {
                     27:        { { 1,1,1,1,1 }, /* 0 */
                     28:          { 1,0,0,0,1 },
                     29:          { 1,0,0,0,1 },
                     30:          { 1,0,0,0,1 },
                     31:          { 1,1,1,1,1 } },
                     32:        { { 0,0,0,0,1 }, /* 1 */
                     33:          { 0,0,0,0,1 },
                     34:          { 0,0,0,0,1 },
                     35:          { 0,0,0,0,1 },
                     36:          { 0,0,0,0,1 } },
                     37:        { { 1,1,1,1,1 }, /* 2 */
                     38:          { 0,0,0,0,1 },
                     39:          { 1,1,1,1,1 },
                     40:          { 1,0,0,0,0 },
                     41:          { 1,1,1,1,1 } },
                     42:        { { 1,1,1,1,1 }, /* 3 */
                     43:          { 0,0,0,0,1 },
                     44:          { 1,1,1,1,1 },
                     45:          { 0,0,0,0,1 },
                     46:          { 1,1,1,1,1 } },
                     47:        { { 1,0,0,0,1 }, /* 4 */
                     48:          { 1,0,0,0,1 },
                     49:          { 1,1,1,1,1 },
                     50:          { 0,0,0,0,1 },
                     51:          { 0,0,0,0,1 } },
                     52:        { { 1,1,1,1,1 }, /* 5 */
                     53:          { 1,0,0,0,0 },
                     54:          { 1,1,1,1,1 },
                     55:          { 0,0,0,0,1 },
                     56:          { 1,1,1,1,1 } },
                     57:        { { 1,1,1,1,1 }, /* 6 */
                     58:          { 1,0,0,0,0 },
                     59:          { 1,1,1,1,1 },
                     60:          { 1,0,0,0,1 },
                     61:          { 1,1,1,1,1 } },
                     62:        { { 1,1,1,1,1 }, /* 7 */
                     63:          { 0,0,0,0,1 },
                     64:          { 0,0,0,0,1 },
                     65:          { 0,0,0,0,1 },
                     66:          { 0,0,0,0,1 } },
                     67:        { { 1,1,1,1,1 }, /* 8 */
                     68:          { 1,0,0,0,1 },
                     69:          { 1,1,1,1,1 },
                     70:          { 1,0,0,0,1 },
                     71:          { 1,1,1,1,1 } },
                     72:        { { 1,1,1,1,1 }, /* 9 */
                     73:          { 1,0,0,0,1 },
                     74:          { 1,1,1,1,1 },
                     75:          { 0,0,0,0,1 },
                     76:          { 1,1,1,1,1 } },
                     77:        { { 0,0,0,0,0 }, /* : */
                     78:          { 0,0,1,0,0 },
                     79:          { 0,0,0,0,0 },
                     80:          { 0,0,1,0,0 },
                     81:          { 0,0,0,0,0 } },
                     82:        { { 1,1,1,1,1 }, /* A */
                     83:          { 1,0,0,0,1 },
                     84:          { 1,1,1,1,1 },
                     85:          { 1,0,0,0,1 },
                     86:          { 1,0,0,0,1 } },
                     87:        { { 1,1,1,1,1 }, /* P */
                     88:          { 1,0,0,0,1 },
                     89:          { 1,1,1,1,1 },
                     90:          { 1,0,0,0,0 },
                     91:          { 1,0,0,0,0 } },
                     92:        { { 1,0,0,0,1 }, /* M */
                     93:          { 1,1,0,1,1 },
                     94:          { 1,0,1,0,1 },
                     95:          { 1,0,0,0,1 },
                     96:          { 1,0,0,0,1 } },
                     97: };
                     98:
                     99: void
1.5       nicm      100: clock_draw(struct screen_write_ctx *ctx, int colour, int style)
1.1       nicm      101: {
                    102:        struct screen           *s = ctx->s;
                    103:        struct grid_cell         gc;
                    104:        char                     tim[64], *ptr;
                    105:        time_t                   t;
                    106:        u_int                    i, j, x, y, idx;
                    107:
                    108:        t = time(NULL);
                    109:        if (style == 0)
                    110:                strftime(tim, sizeof tim, "%l:%M %p", localtime(&t));
                    111:        else
                    112:                strftime(tim, sizeof tim, "%H:%M", localtime(&t));
                    113:
                    114:        screen_write_clearscreen(ctx);
                    115:
                    116:        if (screen_size_x(s) < 6 * strlen(tim) || screen_size_y(s) < 6) {
                    117:                if (screen_size_x(s) >= strlen(tim) && screen_size_y(s) != 0) {
                    118:                        x = (screen_size_x(s) / 2) - (strlen(tim) / 2);
                    119:                        y = screen_size_y(s) / 2;
                    120:                        screen_write_cursormove(ctx, x, y);
                    121:
1.3       nicm      122:                        memcpy(&gc, &grid_default_cell, sizeof gc);
1.4       nicm      123:                        colour_set_fg(&gc, colour);
1.1       nicm      124:                        screen_write_puts(ctx, &gc, "%s", tim);
                    125:                }
                    126:                return;
                    127:        }
                    128:
                    129:        x = (screen_size_x(s) / 2) - 3 * strlen(tim);
                    130:        y = (screen_size_y(s) / 2) - 3;
                    131:
1.3       nicm      132:        memcpy(&gc, &grid_default_cell, sizeof gc);
1.4       nicm      133:        colour_set_bg(&gc, colour);
1.1       nicm      134:        for (ptr = tim; *ptr != '\0'; ptr++) {
                    135:                if (*ptr >= '0' && *ptr <= '9')
                    136:                        idx = *ptr - '0';
1.6     ! nicm      137:                else if (*ptr == ':')
1.1       nicm      138:                        idx = 10;
1.6     ! nicm      139:                else if (*ptr == 'A')
1.1       nicm      140:                        idx = 11;
1.6     ! nicm      141:                else if (*ptr == 'P')
1.1       nicm      142:                        idx = 12;
1.6     ! nicm      143:                else if (*ptr == 'M')
1.1       nicm      144:                        idx = 13;
                    145:                else {
                    146:                        x += 6;
                    147:                        continue;
                    148:                }
                    149:
                    150:                for (j = 0; j < 5; j++) {
                    151:                        for (i = 0; i < 5; i++) {
1.2       nicm      152:                                screen_write_cursormove(ctx, x + i, y + j);
1.1       nicm      153:                                if (clock_table[idx][j][i])
1.2       nicm      154:                                        screen_write_putc(ctx, &gc, ' ');
1.1       nicm      155:                        }
                    156:                }
                    157:                x += 6;
                    158:        }
                    159: }