heartbeat

Simple server monitor system using encrypted messages over udp
git clone https://noulin.net/git/heartbeat.git
Log | Files | Refs | README

gallery.c (3352B)


      1 #! /usr/bin/env sheepy
      2 /* or direct path to sheepy: #! /usr/local/bin/sheepy */
      3 
      4 /* Libsheepy documentation: https://spartatek.se/libsheepy/ */
      5 #include "libsheepyObject.h"
      6 #include "termbox.h"
      7 #include <stdarg.h>
      8 
      9 #include "images.h"
     10 
     11 int argc; char **argv;
     12 
     13 /* enable/disable logging */
     14 /* #undef pLog */
     15 /* #define pLog(...) */
     16 
     17 typ struct {
     18   bool quit;
     19   u32 onCount;
     20 } contextt;
     21 
     22 typ struct {
     23   u32 x;
     24   u32 y;
     25   u32 width;
     26   u32 height;
     27   u32 color;
     28   char line[2048];
     29 } bubblet;
     30 
     31 bubblet bub[300] = init0Var;
     32 
     33 void print_tb(const char *str, int x, int y, uint16_t fg, uint16_t bg)
     34 {
     35   while (*str) {
     36     uint32_t uni;
     37     str += tb_utf8_char_to_unicode(&uni, str);
     38     tb_change_cell(x, y, uni, fg, bg);
     39     x++;
     40   }
     41 }
     42 
     43 void printf_tb(int x, int y, uint16_t fg, uint16_t bg, const char *fmt, ...)
     44 {
     45   char buf[4096];
     46   va_list vl;
     47   va_start(vl, fmt);
     48   vsnprintf(buf, sizeof(buf), fmt, vl);
     49   va_end(vl);
     50   print_tb(buf, x, y, fg, bg);
     51 }
     52 
     53 
     54 int main(int ARGC, char** ARGV) {
     55 
     56   argc = ARGC; argv = ARGV;
     57 
     58   initLibsheepy(ARGV[0]);
     59   setLogMode(LOG_FUNC);
     60   //openProgLogFile();
     61   //setLogSymbols(LOG_UTF8);
     62   //disableLibsheepyErrorLogs;
     63 
     64   int r = tb_init();
     65   if (r) {
     66     logE("tb_init() failed with error code %d\n", r);
     67     XFailure;
     68   }
     69 
     70   tb_select_output_mode(TB_OUTPUT_TRUECOLOR);
     71 
     72   //tb_set_cursor(0,0);
     73 
     74   void draw_all(void) {
     75     tb_clear();
     76     //tb_change_cell(/*x*/ 2, /*y*/ 2, '@', TB_GREEN, TB_WHITE | TB_BOLD);
     77     tb_present();
     78   }
     79 
     80   draw_all();
     81 
     82   /* range(j, ybmXT_549309366Height) { */
     83   /*   range(i, ybmXT_549309366Width) { */
     84   /*     if (j & 1) { */
     85   /*       // odd line */
     86   /*       tb_change_cell(#<{(|x|)}># i, #<{(|y|)}># j/2, 0x2584, ybmXT_549309366Pixels[j * ybmXT_549309366Width + i], ybmXT_549309366Pixels[(j-1) * ybmXT_549309366Width + i]); */
     87   /*     } */
     88   /*     else { */
     89   /*       // even line */
     90   /*       tb_change_cell(#<{(|x|)}># i, #<{(|y|)}># j/2, 0x2584, TB_DEFAULT, ybmXT_549309366Pixels[j * ybmXT_549309366Width + i]); */
     91   /*     } */
     92   /*   } */
     93   /* } */
     94 
     95   int imageIndex = 0;
     96 
     97   void showImage() {
     98     tb_clear();
     99     range(j, heights[imageIndex]) {
    100       range(i, widths[imageIndex]) {
    101         if (j & 1) {
    102           // odd line
    103           tb_change_cell(/*x*/ i, /*y*/ j/2, 0x2584, pixels[imageIndex][j * widths[imageIndex] + i], pixels[imageIndex][(j-1) * widths[imageIndex] + i]);
    104         }
    105         else {
    106           // even line
    107           tb_change_cell(/*x*/ i, /*y*/ j/2, 0x2584, TB_BLACK, pixels[imageIndex][j * widths[imageIndex] + i]);
    108         }
    109       }
    110     }
    111   }
    112   showImage();
    113 
    114   tb_present();
    115 
    116   struct tb_event ev;
    117   while (tb_poll_event(&ev)) {
    118     switch (ev.type) {
    119       case TB_EVENT_KEY:
    120         switch (ev.key) {
    121           /* case TB_KEY_ESC: */
    122           /*   ctx.quit = yes; */
    123           /*   goto done; */
    124           /*   break; */
    125           case TB_KEY_SPACE:
    126             inc imageIndex;
    127             if (imageIndex == ARRAY_SIZE(widths)) imageIndex = 0;
    128             showImage();
    129             break;
    130         }
    131         if (ev.ch == 'q') {
    132           goto done;
    133         }
    134 
    135         //tb_stringf(2, 30, TB_WHITE, TB_DEFAULT, "key code: %5d, char: %5d, mod: %5d", ev.key, ev.ch, ev.mod);
    136         break;
    137       case TB_EVENT_RESIZE:
    138         draw_all();
    139         break;
    140     }
    141     tb_present();
    142   }
    143 
    144   done:
    145   tb_shutdown();
    146   XSuccess;
    147 }
    148 // vim: set expandtab ts=2 sw=2: