sys

A set of unix utils in hare!
Log | Files | Refs | README

color.ha (659B)


      1 use fmt;
      2 use strings;
      3 use strconv;
      4 
      5 export type colors = enum uint {
      6 	BLACK = 30,
      7 	RED,
      8 	GREEN,
      9 	YELLOW,
     10 	BLUE,
     11 	MAGENTA,
     12 	CYAN,
     13 	WHITE,
     14 	NORM = 39,
     15 };
     16 
     17 export type mode = enum uint {
     18 	NORM = 0,
     19 	BOLD = 1,
     20 	DIM = 2,
     21 	ITAL = 3,
     22 	UL = 4,
     23 	BLINK = 5,
     24 	REV = 7,
     25 	INVIS = 8,
     26 	STRIKE = 9
     27 };
     28 
     29 export type col = (colors, mode);
     30 
     31 export fn print(s: str, c: col) void = {
     32 	let out = strings::concat(
     33 		`[`,
     34 		strings::dup(strconv::itos(c.1: int))!,
     35 		";",
     36 		strings::dup(strconv::itos(c.0: int))!,
     37 		"m"
     38 	)!;
     39 	defer free(out);
     40 
     41 	fmt::print(out)!;
     42 	fmt::print(s)!;
     43 	fmt::print(``)!;
     44 };
     45 
     46 export fn println(s: str, c: col) void = {
     47 	print(s, c);
     48 	fmt::println()!;
     49 };