heartbeat

Log

Files

Refs

README

main.c (4085B)

     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 int argc; char **argv;
    10 
    11 /* enable/disable logging */
    12 /* #undef pLog */
    13 /* #define pLog(...) */
    14 
    15 void print_tb(const char *str, int x, int y, uint16_t fg, uint16_t bg)
    16 {
    17   while (*str) {
    18     uint32_t uni;
    19     str += tb_utf8_char_to_unicode(&uni, str);
    20     tb_change_cell(x, y, uni, fg, bg);
    21     x++;
    22   }
    23 }
    24 
    25 void printf_tb(int x, int y, uint16_t fg, uint16_t bg, const char *fmt, ...)
    26 {
    27   char buf[4096];
    28   va_list vl;
    29   va_start(vl, fmt);
    30   vsnprintf(buf, sizeof(buf), fmt, vl);
    31   va_end(vl);
    32   print_tb(buf, x, y, fg, bg);
    33 }
    34 
    35 int main(int ARGC, char** ARGV) {
    36 
    37   argc = ARGC; argv = ARGV;
    38 
    39   initLibsheepy(ARGV[0]);
    40   setLogMode(LOG_FUNC);
    41   //openProgLogFile();
    42   //setLogSymbols(LOG_UTF8);
    43   //disableLibsheepyErrorLogs;
    44 
    45   int r = tb_init();
    46   if (r) {
    47     logE("tb_init() failed with error code %d\n", r);
    48     XFailure;
    49   }
    50 
    51   tb_select_output_mode(TB_OUTPUT_TRUECOLOR);
    52 
    53   //tb_set_cursor(0,0);
    54 
    55   void draw_all(void) {
    56     tb_clear();
    57     //tb_change_cell(/*x*/ 2, /*y*/ 2, '@', TB_GREEN, TB_WHITE | TB_BOLD);
    58     tb_present();
    59   }
    60 
    61   draw_all();
    62   // normal mode
    63   //tb_change_cell(/*x*/ 2, /*y*/ 2, '@', TB_GREEN, TB_WHITE);
    64   //truecolor mode
    65   //tb_change_cell(/*x*/ 2, /*y*/ 2, '@', 0x00DD00, 0xBB0000);
    66 
    67   range(i, 50) {
    68     tb_change_cell(/*x*/ i+2, /*y*/ 2, '@', TB_BOLD | 0x00a100 + i << 8, 0x000010 + i);
    69     tb_change_cell(/*x*/ i+2, /*y*/ 3, '@', TB_UNDERLINE | 0x00a100 + i << 8, 0x000020 + i);
    70     tb_change_cell(/*x*/ i+2, /*y*/ 4, '@', TB_REVERSE | 0x00a100 + i << 8, 0x000030 + i);
    71     tb_change_cell(/*x*/ i+2, /*y*/ 5, '@', 0x00a100 + i << 8, 0x000000 + i);
    72     tb_change_cell(/*x*/ i+2, /*y*/ 6, '@', TB_FAINT | 0x00a100 + i << 8, 0x000030 + i);
    73     tb_change_cell(/*x*/ i+2, /*y*/ 7, '@', TB_ITALIC | 0x00a100 + i << 8, 0x000030 + i);
    74     tb_change_cell(/*x*/ i+2, /*y*/ 8, '@', 0x00a100 + i << 8, TB_BLINK | 0x000030 + i);
    75     tb_change_cell(/*x*/ i+2, /*y*/ 9, '@', 0x00a100 + i << 8, TB_HIDDEN | 0x000030 + i);
    76     tb_change_cell(/*x*/ i+2, /*y*/10, '@', 0x00a100 + i << 8, TB_CROSSED | 0x000030 + i);
    77   }
    78 
    79   range(i, 16) {
    80     tb_change_cell(/*x*/ i+2, /*y*/ 10, '#', TB_PALETTE | i, TB_DEFAULT);
    81   }
    82   range(i, 16) {
    83     tb_change_cell(/*x*/ i+2, /*y*/ 11, '.', TB_DEFAULT, TB_PALETTE | i);
    84   }
    85 
    86   tb_stringf_with_limit(2, 20, TB_WHITE, TB_DEFAULT, 10, "%s", "123457890abcd");
    87 
    88   range(i, 8) {
    89     tb_change_cell(i+2, 13, 0x2581+i, 0xFFEECC, 0x001122);
    90   }
    91 
    92   range(i, 8) {
    93     tb_change_cell(20, 10 + i, 0x2588+i, 0xFFEECC, 0x001122);
    94   }
    95 
    96   tb_change_cell(2, 15, 0x2191, 0xFFAACC, TB_DEFAULT); // arrow up
    97   tb_change_cell(3, 15, 0x2193, 0xFFAACC, TB_DEFAULT); // arrow down
    98   /* tb_change_cell(4, 15, 0x2B06, 0xFFAACC, TB_DEFAULT); // page up */
    99   /* tb_change_cell(5, 15, 0x2B07, 0xFFAACC, TB_DEFAULT); // page down */
   100   tb_change_cell(6, 15, 0x21D1, TB_BOLD | 0xFFAACC, TB_DEFAULT); // arrow up
   101   tb_change_cell(7, 15, 0x21D3, TB_BOLD | 0xFFAACC, TB_DEFAULT); // arrow down
   102   tb_change_cell(10, 15, 0x25B6, TB_BOLD | 0xFFAACC, TB_DEFAULT); // black right-pointing triangle
   103   tb_change_cell(11, 15, 0x25BC, TB_BOLD | 0xFFAACC, TB_DEFAULT); // black down-pointing triangle
   104   tb_change_cell(13, 15, 0x25B8, TB_BOLD | 0xFFAACC, TB_DEFAULT); // black right-pointing small triangle
   105   tb_change_cell(14, 15, 0x25BE, TB_BOLD | 0xFFAACC, TB_DEFAULT); // black down-pointing small triangle
   106 
   107 
   108   tb_present();
   109 
   110   struct tb_event ev;
   111   while (tb_poll_event(&ev, 0/*sock disabled*/)) {
   112     switch (ev.type) {
   113       case TB_EVENT_KEY:
   114         switch (ev.key) {
   115           case TB_KEY_ESC:
   116             goto done;
   117         }
   118         if (ev.ch == 'q') goto done;
   119 
   120         tb_stringf(2, 30, TB_WHITE, TB_DEFAULT, "key code: %5d, char: %5d, mod: %5d", ev.key, ev.ch, ev.mod);
   121         break;
   122       case TB_EVENT_RESIZE:
   123         draw_all();
   124         break;
   125     }
   126     tb_present();
   127   }
   128 
   129   done:
   130   tb_shutdown();
   131   XSuccess;
   132 }
   133 // vim: set expandtab ts=2 sw=2: