File: colourz.c

package info (click to toggle)
hx 0.7.14-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 564 kB
  • ctags: 834
  • sloc: ansic: 7,901; sh: 152; makefile: 81
file content (58 lines) | stat: -rw-r--r-- 1,030 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
#include "hx_types.h"
#include "htlc.h"
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include "hxlib.h"
#include "xmalloc.h"
#include "auto_array.h"

static int use_colourz;

int cmd_colourz (void);

int
cmd_colourz (void)
{
	use_colourz = use_colourz ? 0 : 1;

	return use_colourz;
}

void
colourz (char *str)
{
	if (!use_colourz) {
		if (!curchat)
			htlc_snd_chat(str, (u_int16_t)strlen(str));
		else
			htlc_snd_chat_chat(curchat->ref, str, (u_int16_t)strlen(str));
	} else {
		register char *p, *b;
		static unsigned short asf = 31;
		register unsigned short col = asf;
		auto_array(str, buf, (strlen(str) * 5) + 0xff);

		b = buf;
		strcpy(b, "\033[1m");
		b += 4;
		for (p = str; *p; p++) {
			if (isspace(*p)) {
				*b++ = *p;
				continue;
			}
			sprintf(b, "\033[%um%c", col++, *p);
			b += 6;
			if (col == 37)
				col = 31;
		}
		strcpy(b, "\033[0m");
		b += 4;
		if (!curchat)
			htlc_snd_chat(buf, b - buf);
		else
			htlc_snd_chat_chat(curchat->ref, buf, b - buf);
		asf = col;
		auto_free(buf);
	}
}