Debian Codegraph @

python/examples/colors.py

raw
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # colors display all possible libcaca colour pairs
5 # Copyright (c) 2010 Alex Foulon <[email protected]>
6 #
7 # This file is a Python port of "examples/colors.c"
8 # which is:
9 # Copyright (c) 2003-2010 Sam Hocevar <[email protected]>
10 # All Rights Reserverd
11 #
12 # This library is free software. It comes without any warranty, to
13 # the extent permitted by applicable law. You can redistribute it
14 # and/or modify it under the terms of the Do What the Fuck You Want
15 # to Public License, Version 2, as published by Sam Hocevar. See
16 # http://www.wtfpl.net/ for more details.
17 #
18
19 import sys
20
21 import caca
22 from caca.canvas import Canvas, CanvasError
23 from caca.display import Display, DisplayError, Event
24
25 def main():
26 """ Main function. """
27
28 try:
29 cv = Canvas(80, 24)
30 dp = Display(cv)
31 except (CanvasError, DisplayError) as err:
32 sys.stderr.write("%s\n" % err)
33 sys.exit(127)
34
35 cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
36 cv.clear()
37
38 for i in range(0, 16):
39 if i >= 8:
40 y = i + 3
41 else:
42 y = i + 2
43
44 cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
45 cv.printf(3, y, "ANSI %i", i)
46
47 for j in range(0, 16):
48 if j >= 8:
49 x = 13 + (j * 4)
50 else:
51 x = 12 + (j * 4)
52 if i >= 8:
53 y = i + 3
54 else:
55 y = i + 2
56
57 cv.set_color_ansi(i, j)
58 cv.put_str(x, y, "Aaホ")
59
60 cv.set_color_ansi(caca.COLOR_LIGHTGRAY, caca.COLOR_BLACK)
61 cv.put_str(3, 20, "This is bold This is blink This is italics This is underline")
62 cv.set_attr(caca.STYLE_BOLD)
63 cv.put_str(3 + 8, 20, "bold")
64 cv.set_attr(caca.STYLE_BLINK)
65 cv.put_str(3 + 24, 20, "blink")
66 cv.set_attr(caca.STYLE_ITALICS)
67 cv.put_str(3 + 41, 20, "italics")
68 cv.set_attr(caca.STYLE_UNDERLINE)
69 cv.put_str(3 + 60, 20, "underline")
70
71 dp.refresh()
72 dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1)
73
74 if __name__ == "__main__":
75 main()
76