File: colors.py

package info (click to toggle)
libcaca 0.99.beta19-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,200 kB
  • ctags: 3,824
  • sloc: ansic: 22,346; python: 2,316; cs: 1,213; cpp: 1,114; java: 916; objc: 836; makefile: 606; sh: 457; ruby: 193; asm: 65
file content (76 lines) | stat: -rwxr-xr-x 2,115 bytes parent folder | download | duplicates (7)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# colors        display all possible libcaca colour pairs
# Copyright (c) 2010 Alex Foulon <alxf@lavabit.com>
#
# This file is a Python port of "examples/colors.c"
# which is:
# Copyright (c) 2003-2010 Sam Hocevar <sam@hocevar.net>
#               All Rights Reserverd
#
# This library is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What the Fuck You Want
# to Public License, Version 2, as published by Sam Hocevar. See
# http://www.wtfpl.net/ for more details.
#

import sys

import caca
from caca.canvas import Canvas, CanvasError
from caca.display import Display, DisplayError, Event

def main():
    """ Main function. """

    try:
        cv = Canvas(80, 24)
        dp = Display(cv)
    except (CanvasError, DisplayError) as err:
        sys.stderr.write("%s\n" % err)
        sys.exit(127)

    cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
    cv.clear()

    for i in range(0, 16):
        if i >= 8:
            y = i + 3
        else:
            y = i + 2

        cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
        cv.printf(3, y, "ANSI %i", i)

        for j in range(0, 16):
            if j >= 8:
                x = 13 + (j * 4)
            else:
                x = 12 + (j * 4)
            if i >= 8:
                y = i + 3
            else:
                y = i + 2

            cv.set_color_ansi(i, j)
            cv.put_str(x, y, "Aaホ")

    cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
    cv.put_str(3, 20, "This is bold    This is blink    This is italics    This is underline")
    cv.set_attr(caca.STYLE_BOLD)
    cv.put_str(3 + 8, 20, "bold")
    cv.set_attr(caca.STYLE_BLINK)
    cv.put_str(3 + 24, 20, "blink")
    cv.set_attr(caca.STYLE_ITALICS)
    cv.put_str(3 + 41, 20, "italics")
    cv.set_attr(caca.STYLE_UNDERLINE)
    cv.put_str(3 + 60, 20, "underline")

    dp.refresh()
    dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)

if __name__ == "__main__":
    main()