File: driver.py

package info (click to toggle)
libcaca 0.99.beta20-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,264 kB
  • sloc: ansic: 25,091; php: 2,763; python: 2,637; cs: 1,213; cpp: 1,127; java: 916; objc: 836; makefile: 543; perl: 505; sh: 472; asm: 297; ruby: 215; xml: 33
file content (67 lines) | stat: -rwxr-xr-x 1,812 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# driver        libcaca test drivers program
# Copyright (c) 2010 Alex Foulon <alxf@lavabit.com>
#
# This file is a Python port of "examples/driver.c"
# which is:
# Copyright (c) 2006-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. """

    lst = caca.get_display_driver_list()
    cur = 0

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

    cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK)

    while True:
        cv.put_str(1, 0, "Available drivers:")
        cur_driver = dp.get_driver()
        n = 0
        for driver, desc in lst:
            if driver == cur_driver:
                cv.put_str(2, n + 2, "%s %s (%s)" % ('*', driver, desc))
            else:
                cv.put_str(2, n + 2, "%s %s (%s)" % (' ', driver, desc))
            n += 1

        cv.put_str(2, n + 3, "Switching driver in 5 seconds")
        dp.refresh()

        if dp.get_event(caca.EVENT_KEY_PRESS, Event(), 5000000):
            break

        cur += 1
        if cur < len(lst) and lst[cur][0] == "raw":
            cur += 1
        if cur >= len(lst):
            cur = 0

        dp.set_driver(lst[cur][0])

if __name__ == "__main__":
    main()