File: kitty.c

package info (click to toggle)
gnuplot 6.0.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 14,940 kB
  • sloc: ansic: 95,319; cpp: 7,590; makefile: 2,470; javascript: 2,328; sh: 1,531; lisp: 664; perl: 304; pascal: 191; tcl: 88; python: 46
file content (62 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Kitty terminal support using existing PNG routines.
 * This file is #included from term.h if either the gd or cairo
 * libraries are present.
 */

#ifdef TERM_BODY

#ifndef KITTY_C
#define KITTY_C

/* Kitty graphics spec says this must be <= 4096 */
#define KITTY_BUFSIZ 4096

#define KITTY_FORMAT_RGB 24
#define KITTY_FORMAT_RGBA 32
#define KITTY_FORMAT_PNG 100

static unsigned char kitty_format;
static unsigned char *kitty_buf = NULL;	/* Will be initialized to kitty_buf[KITTY_BUFSIZ] */
static unsigned char *kitty_writepos;
static TBOOLEAN kitty_init_sent;

static void
kitty_init(unsigned char format)
{
    kitty_format = format;
    if (!kitty_buf)
	kitty_buf = gp_alloc(sizeof(unsigned char) * KITTY_BUFSIZ, "kitty buffer");
    kitty_writepos = kitty_buf;
    kitty_init_sent = FALSE;
}

static int
kitty_flush(TBOOLEAN more)
{
    /* TODO: return EOF if any writes error */

    if (!kitty_init_sent) {
        fprintf(gpoutfile, "\033_Ga=T,f=%d,m=%d;", kitty_format, more);
        kitty_init_sent = TRUE;
    } else {
        fprintf(gpoutfile, "\033_Gm=%d;", more);
    }
    fwrite(kitty_buf, sizeof(unsigned char), kitty_writepos - kitty_buf, gpoutfile);
    fprintf(gpoutfile, "\033\\");
    kitty_writepos = kitty_buf;
    return 0;
}

static int
kitty_writechar(void *closure, unsigned char ch)
{
    *(kitty_writepos++) = ch;
    if (kitty_writepos - kitty_buf >= KITTY_BUFSIZ) {
        return kitty_flush(TRUE);
    }
    return 0;
}

#endif /* KITTY_C */
#endif /* TERM_BODY */