├── .gitignore ├── .travis.yml ├── .travis └── before_install.sh ├── AUTHORS ├── COPYING ├── COPYING.GPL ├── COPYING.ISC ├── COPYING.LGPL ├── Makefile.am ├── NEWS ├── NOTES ├── README ├── THANKS ├── XCode └── libcacaXCode.xcodeproj │ └── project.pbxproj ├── bootstrap ├── build ├── Makefile.am ├── autotools │ └── common.am ├── build-dos ├── build-kernel ├── build-win32 ├── build-win64 └── win32 │ └── config.h ├── caca-config.in ├── caca-php ├── caca.php ├── config.m4 ├── examples │ ├── cacainfo.php │ ├── cacapig.php │ ├── colors.php │ ├── demo.php │ ├── dithering.php │ ├── export.php │ ├── figfont.php │ ├── fullwidth.php │ ├── img2txt.php │ ├── import.php │ ├── logo-caca.png │ ├── polyline.php │ ├── render.php │ ├── test.php │ ├── text.php │ ├── transform.php │ ├── truecolor.php │ ├── unicode.php │ └── www │ │ ├── cacainfo.php │ │ ├── colors.php │ │ ├── dithering.php │ │ ├── export.php │ │ ├── figlet.php │ │ ├── fullwidth.php │ │ ├── img2txt.php │ │ ├── import.php │ │ ├── logo-caca.png │ │ ├── render.php │ │ ├── text.php │ │ ├── transform.php │ │ ├── truecolor.php │ │ └── unicode.php ├── package.xml ├── php_caca.c └── php_caca.h ├── caca-sharp ├── AssemblyInfo.cs ├── Attr.cs ├── Caca.cs ├── Canvas.cs ├── Display.cs ├── Dither.cs ├── Event.cs ├── Font.cs ├── Makefile.am ├── caca-sharp.csproj ├── caca-sharp.dll.config.in ├── caca-sharp.pc.in ├── caca-sharp.snk ├── test-csharp.csproj └── test.cs ├── caca ├── Makefile.am ├── attr.c ├── box.c ├── caca.c ├── caca.h ├── caca.pc.in ├── caca0.c ├── caca0.h ├── caca_conio.c ├── caca_conio.h ├── caca_debug.h ├── caca_internals.h ├── caca_prof.h ├── caca_stubs.h ├── caca_types.h ├── canvas.c ├── charset.c ├── codec │ ├── codec.h │ ├── export.c │ ├── import.c │ └── text.c ├── conic.c ├── dirty.c ├── dither.c ├── driver │ ├── cocoa.m │ ├── conio.c │ ├── gl.c │ ├── ncurses.c │ ├── null.c │ ├── raw.c │ ├── slang.c │ ├── vga.c │ ├── win32.c │ └── x11.c ├── event.c ├── figfont.c ├── file.c ├── font.c ├── frame.c ├── getopt.c ├── graphics.c ├── libcaca.def ├── libcaca.vcxproj ├── libcaca.vcxproj.filters ├── line.c ├── mono9.data ├── monobold12.data ├── prof.c ├── string.c ├── t │ ├── Makefile.am │ ├── bench.c │ ├── bench.vcxproj │ ├── bug-setlocale.c │ ├── caca-test.cpp │ ├── canvas.cpp │ ├── check-copyright │ ├── check-doxygen │ ├── check-source │ ├── check-win32 │ ├── dirty.cpp │ ├── driver.cpp │ ├── export.cpp │ └── simple.c ├── time.c ├── transform.c └── triangle.c ├── configure.ac ├── cxx ├── Makefile.am ├── caca++.cpp ├── caca++.h ├── caca++.pc.in ├── cxxtest.cpp ├── libcaca++.def ├── libcaca++.vcxproj └── test-cxx.vcxproj ├── doc ├── Makefile.am ├── caca-config.1 ├── cacafire.1 ├── cacaplay.1 ├── cacaserver.1 ├── cacaview.1 ├── canvas.dox ├── doxygen.cfg.in ├── doxygen.css ├── font.dox ├── footer.html ├── header.html ├── img2txt.1 ├── libcaca.dox ├── migrating.dox ├── style.dox ├── tutorial.dox └── user.dox ├── examples ├── Makefile.am ├── blit.c ├── blit.vcxproj ├── canvas.c ├── colors.c ├── colors.vcxproj ├── conio-snake.cpp ├── conio-snake.vcxproj ├── conio.c ├── conio.vcxproj ├── demo.c ├── demo.vcxproj ├── demo0.c ├── dithering.c ├── dithering.vcxproj ├── driver.c ├── driver.vcxproj ├── event.c ├── event.vcxproj ├── export.c ├── figfont.c ├── font.c ├── font.vcxproj ├── font2tga.c ├── frames.c ├── frames.vcxproj ├── fullwidth.c ├── fullwidth.vcxproj ├── gamma.c ├── gamma.vcxproj ├── hsv.c ├── hsv.vcxproj ├── import.c ├── import.vcxproj ├── input.c ├── input.vcxproj ├── mouse.c ├── spritedit.c ├── swallow.c ├── text.c ├── transform.c ├── transform.vcxproj ├── trifiller.c ├── truecolor.c ├── truecolor.vcxproj ├── unicode.c └── unicode.vcxproj ├── java ├── .gitignore ├── Makefile.am ├── README ├── caca_java_common.c ├── caca_java_common.h ├── examples │ ├── Driver │ ├── Driver.java │ ├── TrueColor │ └── TrueColor.java ├── org │ └── zoy │ │ └── caca │ │ ├── Attribute.java │ │ ├── Caca.java │ │ ├── CacaException.java │ │ ├── CacaObject.java │ │ ├── Canvas.java │ │ ├── Color.java │ │ ├── Display.java │ │ ├── Dither.java │ │ ├── Event.java │ │ ├── Font.java │ │ ├── NativeObject.java │ │ └── TimeoutException.java ├── org_zoy_caca_Attribute.c ├── org_zoy_caca_Caca.c ├── org_zoy_caca_Canvas.c ├── org_zoy_caca_Display.c ├── org_zoy_caca_Dither.c ├── org_zoy_caca_Event.c └── org_zoy_caca_Font.c ├── kernel ├── Makefile.am ├── boot │ ├── bootsect.asm │ ├── gdt.c │ ├── idt.c │ ├── int.asm │ ├── interruptions.c │ ├── pic.c │ ├── stage2.c │ └── stage2.h ├── bootsect.S ├── drivers │ ├── floppy.c │ ├── floppy.h │ ├── keyboard.c │ ├── memory.c │ ├── memory.h │ ├── processor.c │ ├── processor.h │ ├── timer.c │ └── timer.h ├── kernel.c ├── kernel.h ├── klibc.c ├── klibc.h └── multiboot.h ├── libcaca.sln ├── libcaca.spec ├── perl ├── Build.PL ├── MANIFEST ├── MANIFEST.SKIP ├── META.yml ├── Makefile.PL ├── README ├── lib │ └── Term │ │ ├── Caca.pm │ │ ├── Caca.xs │ │ ├── Caca │ │ ├── Bitmap.pm │ │ ├── Constants.pm │ │ └── Sprite.pm │ │ ├── Kaka.pm │ │ └── Kaka │ │ ├── Bitmap.pm │ │ ├── Constants.pm │ │ └── Sprite.pm └── t │ └── data │ └── caca.txt ├── python ├── Makefile.am ├── caca │ ├── __init__.py │ ├── canvas.py │ ├── common.py │ ├── display.py │ ├── dither.py │ └── font.py ├── examples │ ├── blit.py │ ├── cacainfo.py │ ├── colors.py │ ├── drawing.py │ ├── driver.py │ ├── event.py │ ├── figfont.py │ ├── font.py │ ├── frames.py │ ├── gol.py │ ├── img2txt.py │ └── text.py ├── setup.py └── test │ ├── __init__.py │ └── canvas.py ├── ruby ├── Makefile.am ├── README ├── caca-canvas.c ├── caca-canvas.h ├── caca-display.c ├── caca-display.h ├── caca-dither.c ├── caca-dither.h ├── caca-event.c ├── caca-event.h ├── caca-font.c ├── caca-font.h ├── caca.c ├── common.h ├── lib │ └── caca.rb ├── ruby-caca.dox ├── ruby.dox ├── t │ ├── tc_canvas.rb │ ├── tc_display.rb │ ├── tc_dither.rb │ ├── tc_font.rb │ └── tc_frame.rb └── test ├── src ├── Makefile.am ├── aafire.c ├── caca.txt ├── cacaclock.c ├── cacademo.c ├── cacademo.vcxproj ├── cacadraw.c ├── cacafire.vcxproj ├── cacaplay.c ├── cacaserver.c ├── cacaview.c ├── cacaview.vcxproj ├── common-image.c ├── common-image.h ├── img2txt.c └── texture.h └── tools ├── Makefile.am ├── makefont.c ├── optipal.c └── sortchars.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Autotools cruft 2 | *.o 3 | *.lo 4 | *.la 5 | *.exe 6 | *.pc 7 | *.userprefs 8 | *.usertasks 9 | *.pidb 10 | .auto 11 | .libs 12 | .deps 13 | .dirstamp 14 | Makefile 15 | Makefile.in 16 | aclocal.m4 17 | autom4te.cache 18 | config.h.in 19 | config.h 20 | config.log 21 | config.status 22 | configure 23 | libtool 24 | stamp-* 25 | *-stamp 26 | INSTALL 27 | caca-config 28 | # Testsuite binaries 29 | caca/t/bench 30 | caca/t/bug-setlocale 31 | caca/t/caca-test 32 | caca/t/simple 33 | caca/t/*.log 34 | caca/t/*.trs 35 | ruby/*.log 36 | ruby/*.trs 37 | # caca-sharp binaries 38 | caca-sharp/*.dll 39 | caca-sharp/*.config 40 | caca-sharp/*.mdb 41 | # libcaca++ binaries 42 | cxx/cxxtest 43 | # Doxygen cruft 44 | doc/doxygen.cfg 45 | doc/doxygen.log 46 | doc/man 47 | doc/html 48 | doc/latex 49 | # Visual Studio cruft 50 | *.vcxproj.user 51 | *.sdf 52 | *.suo 53 | ipch 54 | win32/*Debug 55 | win32/*Release 56 | # example binaries 57 | examples/blit 58 | examples/canvas 59 | examples/colors 60 | examples/conio 61 | examples/conio-snake 62 | examples/demo 63 | examples/demo0 64 | examples/dithering 65 | examples/driver 66 | examples/event 67 | examples/export 68 | examples/figfont 69 | examples/font 70 | examples/font2tga 71 | examples/frames 72 | examples/fullwidth 73 | examples/gamma 74 | examples/hsv 75 | examples/import 76 | examples/input 77 | examples/mouse 78 | examples/spritedit 79 | examples/swallow 80 | examples/term 81 | examples/text 82 | examples/transform 83 | examples/trifiller 84 | examples/truecolor 85 | examples/unicode 86 | # Ruby binaries 87 | ruby/*/mkmf.log 88 | ruby/*/*.so 89 | # Python binaries 90 | python/*/*.pyc 91 | python/*.egg-info 92 | # Demo binaries 93 | src/cacaview 94 | src/cacadraw 95 | src/cacademo 96 | src/cacafire 97 | src/cacaplay 98 | src/cacaserver 99 | src/cacaclock 100 | src/img2txt 101 | # Tools binaries 102 | tools/optipal 103 | tools/makefont 104 | tools/sortchars 105 | 106 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: c 3 | env: 4 | matrix: 5 | - VERBOSE=1 6 | global: 7 | # Added using “travis encrypt COVERITY_SCAN_TOKEN= --add” 8 | secure: NxBaKlGmAXMaz8GU0tOir3KV0x/0AwINXBxIY0x66C8yU8lvrzumzpoeGZBDCL8Nugq8p9EI73+pdvuwnsoAGFYDiYNVYefegVwSpz7XBpD8yyKMOdtRtaJLH/vApjzI7s/h+FA7a/j9QFikJ7PVZPIJiVjKNH9URClCaj0EpXLXxQkzg9o1ZCY27+JVWrg5v2HJn6+LddK8iiQhezXw+m9QPVkQiPZmYdvjuFjklulgTguAlWVm307AS2/QJ4sYECTbLiWJ3FTScRZMhuSq6XXGqJ3H3F8ku52QOkyUIIlpNAKKtm0VvPcUgs3SlIxodYykegLsVwm0+RKJN4lbsIN1w0uG/ThWi86T7zwbt6giuoAC4H387zVrd9080zwRedUWSuRB5yR6nsK0lROBquPJ7qnM7xPKwrnW4oyi/6u/syzcbVLOPNoYClYy7Mf8TX5rVBxPUSJ3Ch28GqWXwabKwPSH6jtkXlfvPyMMs29wI8d8i0C80lijhtXeeJNzfOx8MHhEikVc2r67lrqOjGTTIord6fbxTQnqfjiMrWRxvz1ogpdbrsQ1s2xsedvqvNr1v1Xt8IOuHMGQ635G0d12Q+wqHzEbdCmAg1v2VXSfVZcl4faPMNiIdfnZJn+5q14sjznX81IHpyzEWgiMgUXaJ2k49kAMIESripZk4bU= 9 | 10 | addons: 11 | apt: 12 | packages: 13 | - build-essential 14 | - pkg-config 15 | - libncursesw5-dev 16 | - libx11-dev 17 | - freeglut3-dev 18 | - ruby-dev 19 | # XXX: not supported by Travis-CI, see 20 | # https://github.com/travis-ci/apt-package-whitelist/issues/1422 21 | # ... so we just build-dep on libcaca-dev! 22 | - libslang2-dev 23 | - libcaca-dev 24 | - libimlib2-dev 25 | # FIXME: disable this for now, as it just outputs garbage 26 | #- texlive-fonts-recommended 27 | #- doxygen-latex 28 | - ruby-minitest 29 | coverity_scan: 30 | project: 31 | name: cacalabs/libcaca 32 | build_command_prepend: 33 | - ".travis/before_install.sh" 34 | - "./bootstrap" 35 | - "./configure" 36 | build_command: make 37 | branch_pattern: master 38 | 39 | # Travis does shallow clones, but we use the Git history 40 | # for check-copyright. Disable shallow clones; our whole 41 | # history is about 5 MiB anyway. 42 | git: 43 | depth: 9999999 44 | 45 | before_install: 46 | - ".travis/before_install.sh" 47 | - "./bootstrap" 48 | 49 | os: 50 | - linux 51 | - osx 52 | 53 | compiler: 54 | - gcc 55 | - clang 56 | 57 | -------------------------------------------------------------------------------- /.travis/before_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if brew --version 2>/dev/null 2>&1; then 4 | # FIXME: no ncurses formula for now; also add ruby 5 | brew install slang doxygen 6 | fi 7 | 8 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | /** \page libcaca-authors Libcaca authors 2 | 3 | Sam Hocevar 4 | - main programmer 5 | 6 | Jean-Yves Lamoureux 7 | - cacaball 8 | - OpenGL driver 9 | - exporters 10 | - network driver 11 | - C# bindings 12 | 13 | John Beppu 14 | - Term::Caca Perl wrapper 15 | 16 | Ben Wiley Sittler 17 | - numerous bugfixes and enhancements 18 | 19 | Pascal Terjan 20 | - Ruby bindings 21 | 22 | Daniele "Eriol" Tricoli 23 | - Python CTypes sample program 24 | 25 | Nicolas Vion 26 | - PHP bindings 27 | 28 | Adrien Grand 29 | - Java bindings 30 | 31 | Alex Foulon 32 | - Python bindings 33 | 34 | */ 35 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | 15 | -------------------------------------------------------------------------------- /COPYING.ISC: -------------------------------------------------------------------------------- 1 | Copyright (c) Year(s), Company or Person's Name 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | SUBDIRS = kernel caca src examples tools \ 5 | cxx caca-sharp python ruby java doc 6 | DIST_SUBDIRS = $(SUBDIRS) build 7 | 8 | EXTRA_DIST = NOTES COPYING.GPL COPYING.ISC COPYING.LGPL bootstrap caca-config.in libcaca.spec libcaca.sln 9 | AUTOMAKE_OPTIONS = dist-bzip2 10 | 11 | bin_SCRIPTS = caca-config 12 | 13 | webhost = poulet.zoy.org 14 | webdir = /srv/caca.zoy.org/var/www/ 15 | doxdir = /srv/caca.zoy.org/var/cache/doxygen/libcaca 16 | 17 | upload: upload-source upload-doc 18 | 19 | upload-source: FORCE 20 | scp $(distdir).tar.gz $(webhost):$(webdir)/files/ 21 | 22 | upload-doc: doc/html FORCE 23 | ssh $(webhost) rm -f '$(doxdir)/*' || true 24 | scp -r doc/html/* $(webhost):$(doxdir)/ 25 | 26 | update-fonts: tools/makefont 27 | tools/makefont mono9 "Monospace 9" 96 4 >| $(srcdir)/caca/mono9.data 28 | tools/makefont monobold12 "Monospace Bold 12" 96 4 >| $(srcdir)/caca/monobold12.data 29 | 30 | # Travis CI uses “make test” instead of “make check” 31 | test: check 32 | 33 | echo-dirs: ; echo caca kernel src cxx examples ruby python tools 34 | 35 | FORCE: 36 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | Building libcaca 3 | 4 | o If you are using a Git or SVN checkout, you need to run the 5 | bootstrap script in order to generate configure. This is not 6 | necessary for official tarballs. 7 | 8 | o Run configure then make. Useful configure flags are: 9 | 10 | --enable-ncurses: support for the ncurses library 11 | --enable-slang: support for the SLang library 12 | --enable-conio: support for MS-DOS conio.h 13 | --enable-x11: support for native X11 rendering 14 | --enable-gl: support for OpenGL rendering 15 | --enable-win32: support for the Windows console 16 | --enable-network: support for the network server 17 | 18 | --disable-imlib2: remove Imlib2 support in cacaview 19 | 20 | --disable-doc: do not build documentation 21 | 22 | o Cross-compilation examples: 23 | 24 | ./configure --disable-imlib2 --host=i386-pc-msdosdjgpp 25 | 26 | ./configure --disable-imlib2 --host=i586-mingw32msvc 27 | 28 | 29 | Using libcaca 30 | 31 | o Look into the src/ and test/ directories for source code examples. 32 | 33 | o Compiling a libcaca program is fairly simple: 34 | 35 | gcc -c foobar.c -o foobar.o `pkg-config --cflags caca` 36 | gcc foobar.o -o foobar `pkg-config --libs caca` 37 | 38 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | /** \page libcaca-thanks Libcaca thanks 2 | 3 | \section thanks1 Bugfixes and improvements 4 | 5 | - Gildas Bazin - win32 driver improvements 6 | - Jari Komppa - win32 speed improvements 7 | - Bastian Märkisch - bugfixes and win32 driver improvements 8 | - Denis Fondras - IPv6 support in cacaserver 9 | 10 | \section thanks2 Reused code 11 | 12 | - Jan Hubicka - aafire 13 | - Michele Bini - original SDL plasma 14 | - Free Software Foundation, Inc. - multiboot.S 15 | - Simon Huggins - conio-snake 16 | 17 | \section thanks3 Porters and packagers 18 | 19 | - Derk-Jan Hartman - Gentoo ebuild file 20 | - Ladislav Hagara - Source Mage spell 21 | - Philip Balinov - Slackware package 22 | - Richard Zidlicky - rpm specfile 23 | - Thomas Klausner - NetBSD port maintainer 24 | - Vincent Tantardini - FreeBSD port maintainer 25 | 26 | */ 27 | -------------------------------------------------------------------------------- /build/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | EXTRA_DIST = autotools/common.am \ 5 | win32/config.h \ 6 | build-dos build-kernel build-win32 build-win64 7 | 8 | -------------------------------------------------------------------------------- /build/autotools/common.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/caca -I$(top_builddir)/caca 3 | 4 | echo-topdir: ; echo $(top_srcdir) 5 | echo-sources: ; echo $(SOURCES) $(EXTRA_CHECKS) 6 | 7 | -------------------------------------------------------------------------------- /build/build-dos: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | ## DOS cross-compilation for libcaca -- Sam Hocevar 4 | 5 | set -x 6 | set -e 7 | 8 | # Clean up our working directory 9 | SRCDIR="`pwd`" 10 | DIRNAME="libcaca-dos-`sed -ne 's/^AM_INIT_AUTOMAKE(.*, \(.*\)).*/\1/p' configure.ac`" 11 | INSTALLDIR="`pwd`/${DIRNAME}" 12 | BUILDDIR="${INSTALLDIR}/build" 13 | rm -Rf "${INSTALLDIR}" 14 | rm -f "${INSTALLDIR}.zip" 15 | mkdir "${INSTALLDIR}" 16 | mkdir "${BUILDDIR}" 17 | 18 | cd "${BUILDDIR}" 19 | # Build for DOS 20 | "${SRCDIR}/configure" --host=i386-pc-msdosdjgpp --prefix=/ --bindir=/ --libdir=/ --disable-imlib2 --disable-doc --disable-ruby --disable-csharp --disable-cxx 21 | make pkglibdir=/lib pkgdatadir=/data 22 | # Install into our private directory 23 | make install DESTDIR="${INSTALLDIR}" pkglibdir=/lib pkgdatadir=/ 24 | cd "${SRCDIR}" 25 | rm -Rf "${BUILDDIR}" 26 | 27 | i386-pc-msdosdjgpp-strip "${INSTALLDIR}/"*.exe 28 | 29 | mkdir "${INSTALLDIR}/doc" 30 | for f in COPYING COPYING.LGPL COPYING.GPL README AUTHORS NEWS NOTES THANKS; do 31 | sed -e 's/$/^M/' < "${SRCDIR}/${f}" > "${INSTALLDIR}/doc/${f}.txt" 32 | done 33 | 34 | rm -Rf "${INSTALLDIR}/share" 35 | rm -Rf "${INSTALLDIR}/man" 36 | rm -Rf "${INSTALLDIR}/include" 37 | rm -Rf "${INSTALLDIR}/pkg-config" 38 | rm -f "${INSTALLDIR}/caca-config" 39 | rm -f "${INSTALLDIR}/"*.a 40 | rm -f "${INSTALLDIR}/"*.la 41 | 42 | # Pack the directory 43 | zip "${DIRNAME}.zip" `find "${DIRNAME}"` 44 | rm -Rf "${INSTALLDIR}" 45 | 46 | -------------------------------------------------------------------------------- /build/build-kernel: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | ## Kernel-mode libcaca compilation script -- Sam Hocevar 4 | 5 | set -x 6 | set -e 7 | 8 | MYCFLAGS="-fno-builtin -O0 -I. -I.. -I../caca/ -Wall -D__KERNEL__ -fno-stack-protector -m32" 9 | 10 | ./configure --enable-kernel --disable-doc --host i386 11 | 12 | # Compile cacademo, leave it as an object 13 | cd caca && make && cd .. 14 | cd examples && make dithering.o && cd .. 15 | 16 | cd kernel 17 | 18 | # Bootsector 19 | nasm -f bin -o bootsect.bin boot/bootsect.asm 20 | # Interruption handlers 21 | nasm -f elf -o int.o boot/int.asm 22 | 23 | ##### Boot (x86) 24 | # Stage2, loads GDT, PIC, IDT, interrupts, then calls kmain() 25 | gcc $MYCFLAGS boot/stage2.c -c 26 | # GDT installation, called by stage2 27 | gcc $MYCFLAGS boot/gdt.c -c 28 | # PIC installation, called by stage2 29 | gcc $MYCFLAGS boot/pic.c -c 30 | # IDT installation, called by stage2 31 | gcc $MYCFLAGS boot/idt.c -c 32 | # Interruptions installation, called by stage2 33 | gcc $MYCFLAGS boot/interruptions.c -c 34 | 35 | ##### Drivers 36 | # Floppy driver 37 | gcc $MYCFLAGS drivers/floppy.c -c 38 | # Processor driver 39 | gcc $MYCFLAGS drivers/processor.c -c 40 | # Keyboard handler 41 | gcc $MYCFLAGS drivers/keyboard.c -c 42 | # Memory driver 43 | gcc $MYCFLAGS drivers/memory.c -c 44 | # Programmable Interval Timer driver 45 | gcc $MYCFLAGS drivers/timer.c -c 46 | 47 | # Minimalistic libc 48 | gcc $MYCFLAGS klibc.c -c 49 | 50 | # Kernel by itself, contains cmain() which calls main() 51 | gcc $MYCFLAGS kernel.c -c 52 | 53 | # Link everything but bootsector, kernel.o MUST be at the very end 54 | ld --oformat binary -Ttext 1000 stage2.o gdt.o pic.o int.o idt.o interruptions.o keyboard.o memory.o timer.o floppy.o processor.o klibc.o kernel.o ../caca/.libs/libcaca.a -Map kernel.map -o kern.bin 55 | 56 | ls -ail kern.bin 57 | cd .. 58 | 59 | # Copy bootsector at the very beginning of the floppy (first sector/512 bytes of the image), then kernel right after 60 | cat kernel/bootsect.bin kernel/kern.bin /dev/zero | dd of=cacademo.img bs=512 count=2500 61 | 62 | -------------------------------------------------------------------------------- /build/build-win32: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | ## Win32 cross-compilation for libcaca -- Sam Hocevar 4 | 5 | set -x 6 | set -e 7 | 8 | # Clean up our working directory 9 | SRCDIR="`pwd`" 10 | DIRNAME="libcaca-win32-`sed -ne 's/^AC_INIT(.*, \(.*\)).*/\1/p' configure.ac`" 11 | INSTALLDIR="`pwd`/${DIRNAME}" 12 | BUILDDIR="${INSTALLDIR}/build" 13 | rm -Rf "${INSTALLDIR}" 14 | rm -f "${INSTALLDIR}.zip" 15 | mkdir "${INSTALLDIR}" 16 | mkdir "${BUILDDIR}" 17 | 18 | make distclean || true 19 | 20 | cd "${BUILDDIR}" 21 | # Build for win32 22 | "${SRCDIR}/configure" --host=i686-w64-mingw32 --build=none --prefix=/ --bindir=/bin --libdir=/lib --disable-imlib2 --disable-java --disable-doc "$@" 23 | make -j4 pkglibdir=/lib pkgdatadir=/data bindir=/bin 24 | # Install into our private directory 25 | make -j4 install DESTDIR="${INSTALLDIR}" pkglibdir=/lib/ pkgdatadir=/ bindir=/bin/ 26 | cd "${SRCDIR}" 27 | rm -Rf "${BUILDDIR}" 28 | 29 | mv "${INSTALLDIR}/bin/"* "${INSTALLDIR}/" 30 | rmdir "${INSTALLDIR}/bin" 31 | mv "${INSTALLDIR}/lib/"* "${INSTALLDIR}/" 32 | for f in caca caca++; do 33 | mv "${INSTALLDIR}/lib${f}.a" "${INSTALLDIR}/lib/${f}.lib" 34 | done 35 | rm -f "${INSTALLDIR}/caca-config.exe" # Just in case. *sigh*. 36 | i686-w64-mingw32-strip "${INSTALLDIR}/"*.exe || true 37 | i686-w64-mingw32-strip "${INSTALLDIR}/"*.dll || true 38 | 39 | mkdir "${INSTALLDIR}/doc" 40 | for f in COPYING COPYING.LGPL COPYING.GPL README AUTHORS NEWS NOTES THANKS; do 41 | sed -e 's/$/ /' < "${SRCDIR}/${f}" > "${INSTALLDIR}/doc/${f}.txt" 42 | done 43 | rm -Rf "${INSTALLDIR}/share" 44 | rm -Rf "${INSTALLDIR}/man" 45 | rm -Rf "${INSTALLDIR}/pkgconfig" 46 | rm -f "${INSTALLDIR}/caca-config" 47 | rm -f "${INSTALLDIR}/"*.a 48 | rm -f "${INSTALLDIR}/"*.la 49 | 50 | # Pack the directory 51 | zip "${DIRNAME}.zip" `find "${DIRNAME}"` 52 | rm -Rf "${INSTALLDIR}" 53 | 54 | -------------------------------------------------------------------------------- /build/build-win64: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | ## Win32 cross-compilation for libcaca -- Sam Hocevar 4 | 5 | set -x 6 | set -e 7 | 8 | # Clean up our working directory 9 | SRCDIR="`pwd`" 10 | DIRNAME="libcaca-win64-`sed -ne 's/^AC_INIT(.*, \(.*\)).*/\1/p' configure.ac`" 11 | INSTALLDIR="`pwd`/${DIRNAME}" 12 | BUILDDIR="${INSTALLDIR}/build" 13 | rm -Rf "${INSTALLDIR}" 14 | rm -f "${INSTALLDIR}.zip" 15 | mkdir "${INSTALLDIR}" 16 | mkdir "${BUILDDIR}" 17 | 18 | make distclean || true 19 | 20 | cd "${BUILDDIR}" 21 | # Build for win64 22 | "${SRCDIR}/configure" --host=x86_64-w64-mingw32 --build=none --prefix=/ --bindir=/bin --libdir=/lib --disable-imlib2 --disable-java --disable-doc "$@" 23 | make -j4 pkglibdir=/lib pkgdatadir=/data bindir=/bin 24 | # Install into our private directory 25 | make -j4 install DESTDIR="${INSTALLDIR}" pkglibdir=/lib/ pkgdatadir=/ bindir=/bin/ 26 | cd "${SRCDIR}" 27 | rm -Rf "${BUILDDIR}" 28 | 29 | mv "${INSTALLDIR}/bin/"* "${INSTALLDIR}/" 30 | rmdir "${INSTALLDIR}/bin" 31 | mv "${INSTALLDIR}/lib/"* "${INSTALLDIR}/" 32 | for f in caca caca++; do 33 | mv "${INSTALLDIR}/lib${f}.a" "${INSTALLDIR}/lib/${f}.lib" 34 | done 35 | rm -f "${INSTALLDIR}/caca-config.exe" # Just in case. *sigh*. 36 | x86_64-w64-mingw32-strip "${INSTALLDIR}/"*.exe || true 37 | x86_64-w64-mingw32-strip "${INSTALLDIR}/"*.dll || true 38 | 39 | mkdir "${INSTALLDIR}/doc" 40 | for f in COPYING COPYING.LGPL COPYING.GPL README AUTHORS NEWS NOTES THANKS; do 41 | sed -e 's/$/ /' < "${SRCDIR}/${f}" > "${INSTALLDIR}/doc/${f}.txt" 42 | done 43 | rm -Rf "${INSTALLDIR}/share" 44 | rm -Rf "${INSTALLDIR}/man" 45 | rm -Rf "${INSTALLDIR}/pkgconfig" 46 | rm -f "${INSTALLDIR}/caca-config" 47 | rm -f "${INSTALLDIR}/"*.a 48 | rm -f "${INSTALLDIR}/"*.la 49 | 50 | # Pack the directory 51 | zip "${DIRNAME}.zip" `find "${DIRNAME}"` 52 | rm -Rf "${INSTALLDIR}" 53 | 54 | -------------------------------------------------------------------------------- /caca-config.in: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | ## config script for libcaca -- Sam Hocevar 4 | 5 | prefix=@prefix@ 6 | exec_prefix=@exec_prefix@ 7 | 8 | lib_dir=@libdir@ 9 | include_dir=@includedir@ 10 | 11 | usage() 12 | { 13 | cat <&2 31 | fi 32 | 33 | while test $# -gt 0 34 | do 35 | case "$1" in 36 | -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; 37 | *) optarg= ;; 38 | esac 39 | 40 | case $1 in 41 | --prefix=*) 42 | prefix=$optarg 43 | local_prefix=yes 44 | ;; 45 | --prefix) 46 | echo_prefix=yes 47 | ;; 48 | --exec-prefix=*) 49 | exec_prefix=$optarg 50 | exec_prefix_set=yes 51 | local_prefix=yes 52 | ;; 53 | --exec-prefix) 54 | echo_exec_prefix=yes 55 | ;; 56 | --version) 57 | echo @VERSION@ 58 | exit 0 59 | ;; 60 | --cflags) 61 | echo_cflags=yes 62 | ;; 63 | --ldflags) 64 | echo_ldflags=yes 65 | ;; 66 | --libs | --plugin-libs) 67 | echo_libs=yes 68 | ;; 69 | caca) 70 | libs="$libs -lcaca" 71 | ;; 72 | *) 73 | usage 1 1>&2 74 | ;; 75 | esac 76 | shift 77 | done 78 | 79 | if test "$libs" = "" 80 | then 81 | libs="-lcaca" 82 | fi 83 | 84 | if test "$local_prefix" = "yes" 85 | then 86 | if test "$exec_prefix_set" != "yes" 87 | then 88 | exec_prefix=$prefix 89 | fi 90 | fi 91 | 92 | if test "$echo_prefix" = "yes" 93 | then 94 | echo $prefix 95 | fi 96 | 97 | if test "$echo_exec_prefix" = "yes" 98 | then 99 | echo $exec_prefix 100 | fi 101 | 102 | if test "$echo_cflags" = "yes" 103 | then 104 | cflags="-I$include_dir/" 105 | echo $cflags 106 | fi 107 | 108 | if test "$echo_ldflags" = "yes" 109 | then 110 | ldflags="-L$lib_dir" 111 | echo $ldflags 112 | fi 113 | 114 | if test "$echo_libs" = "yes" 115 | then 116 | echo -L@libdir@ $libs 117 | fi 118 | 119 | -------------------------------------------------------------------------------- /caca-php/config.m4: -------------------------------------------------------------------------------- 1 | PHP_ARG_ENABLE(caca, whether to enable Libcaca support, 2 | [ --enable-caca Enable Libcaca support]) 3 | 4 | if test "$PHP_CACA" = "yes"; then 5 | AC_CHECK_LIB(caca, caca_get_version, [ 6 | PHP_ADD_LIBRARY(caca,, CACA_SHARED_LIBADD) 7 | ], [ 8 | AC_MSG_ERROR(libcaca development files required !) 9 | ]) 10 | 11 | AC_CHECK_LIB(gd, gdImageSetPixel, [ 12 | dnl PHP_ADD_LIBRARY(gd,, CACA_SHARED_LIBADD) 13 | AC_DEFINE(HAVE_GD, 1, [Wheter you have development files of gd]) 14 | ]) 15 | 16 | PHP_NEW_EXTENSION(caca, php_caca.c, $ext_shared,,) 17 | PHP_SUBST(CACA_SHARED_LIBADD) 18 | fi 19 | -------------------------------------------------------------------------------- /caca-php/examples/cacainfo.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php5 2 | 6 | * 7 | * This program is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | 15 | //--- Just for fun ---// 16 | 17 | function just_for_fun() { 18 | 19 | $moo = << 5 ? CACA_LIGHTBLUE : CACA_WHITE), CACA_DEFAULT); 35 | $a = caca_get_attr($cv, -1, -1); 36 | caca_put_attr($cv, $i, $j, $a); 37 | caca_put_attr($cv, $i + 1, $j, $a); 38 | } 39 | } 40 | caca_set_canvas_size($cv, 18, 6); 41 | caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT); 42 | caca_put_str($cv, 14, 0, "Moo!"); 43 | caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_DEFAULT); 44 | caca_put_char($cv, 14, 1, hexdec("2765")); //U+2765 45 | caca_put_char($cv, 16, 1, hexdec("2764")); //U+2764 46 | echo caca_export_string($cv, "utf8"); 47 | } 48 | 49 | 50 | if (php_sapi_name() != "cli") { 51 | die("You have to run this program with php-cli!\n"); 52 | } 53 | 54 | just_for_fun(); 55 | 56 | //--- Show caca's information ---// 57 | 58 | echo "libcaca version: ".caca_get_version()."\n\n"; 59 | echo "Available drivers:\n"; 60 | $list = caca_get_display_driver_list(); 61 | foreach($list as $type => $name) 62 | echo "* $name ($type)\n"; 63 | echo "\n"; 64 | 65 | echo "Available import formats:\n"; 66 | $list = caca_get_import_list(); 67 | foreach($list as $format => $name) 68 | echo "* $name ($format)\n"; 69 | echo "\n"; 70 | 71 | echo "Available export formats:\n"; 72 | $list = caca_get_export_list(); 73 | foreach($list as $format => $name) 74 | echo "* $name ($format)\n"; 75 | echo "\n"; 76 | 77 | echo "Available caca fonts:\n"; 78 | $list = caca_get_font_list(); 79 | foreach($list as $name) 80 | echo "* $name\n"; 81 | echo "\n"; 82 | 83 | ?> 84 | -------------------------------------------------------------------------------- /caca-php/examples/colors.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php5 2 | 6 | * 7 | * This file is a Php port of "examples/colors.c" 8 | * Copyright (c) 2003-2004 Sam Hocevar 9 | * All Rights Reserved 10 | * 11 | * This program is free software. It comes without any warranty, to 12 | * the extent permitted by applicable law. You can redistribute it 13 | * and/or modify it under the terms of the Do What the Fuck You Want 14 | * to Public License, Version 2, as published by Sam Hocevar. See 15 | * http://www.wtfpl.net/ for more details. 16 | */ 17 | 18 | if (php_sapi_name() != "cli") { 19 | die("You have to run this program with php-cli!\n"); 20 | } 21 | 22 | $cv = caca_create_canvas(80, 24); 23 | if(!$cv) 24 | { 25 | die("Failed to create canvas\n"); 26 | } 27 | 28 | $dp = caca_create_display($cv); 29 | if(!$dp) 30 | { 31 | die("Failed to create display\n"); 32 | } 33 | 34 | caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK); 35 | caca_clear_canvas($cv); 36 | for($i = 0; $i < 16; $i++) 37 | { 38 | caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK); 39 | caca_put_str($cv, 3, $i + ($i >= 8 ? 3 : 2), "ANSI " . $i); 40 | for($j = 0; $j < 16; $j++) 41 | { 42 | caca_set_color_ansi($cv, $i, $j); 43 | caca_put_str($cv, ($j >= 8 ? 13 : 12) + $j * 4, $i + ($i >= 8 ? 3 : 2), 44 | "Aaホ"); 45 | } 46 | } 47 | 48 | caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK); 49 | caca_put_str($cv, 3, 20, "This is bold This is blink This is italics This is underline"); 50 | caca_set_attr($cv, CACA_BOLD); 51 | caca_put_str($cv, 3 + 8, 20, "bold"); 52 | caca_set_attr($cv, CACA_BLINK); 53 | caca_put_str($cv, 3 + 24, 20, "blink"); 54 | caca_set_attr($cv, CACA_ITALICS); 55 | caca_put_str($cv, 3 + 41, 20, "italics"); 56 | caca_set_attr($cv, CACA_UNDERLINE); 57 | caca_put_str($cv, 3 + 60, 20, "underline"); 58 | 59 | caca_refresh_display($dp); 60 | caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1); 61 | 62 | ?> 63 | -------------------------------------------------------------------------------- /caca-php/examples/dithering.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php5 2 | 6 | * 7 | * This program is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | if (php_sapi_name() != "cli") { 15 | die("You have to run this program with php-cli!\n"); 16 | } 17 | 18 | $img = imagecreatefrompng(dirname(__FILE__)."/logo-caca.png"); 19 | if (!$img) { 20 | die("Can not open image.\n"); 21 | } 22 | 23 | $dither = caca_create_dither($img); 24 | if (!$dither) { 25 | die("Can not create dither. Maybe you compiled caca-php without gd support.\n"); 26 | } 27 | 28 | $canvas = caca_create_canvas(0, 0); 29 | $display = caca_create_display($canvas); 30 | if (!$display) { 31 | die("Can not create display.\n"); 32 | } 33 | 34 | caca_dither_bitmap($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img); 35 | caca_refresh_display($display); 36 | 37 | caca_get_event($display, CACA_EVENT_KEY_PRESS, -1); 38 | 39 | ?> 40 | -------------------------------------------------------------------------------- /caca-php/examples/figfont.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php5 2 | 6 | * 7 | * This program is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | function unistr_to_ords($str, $encoding = 'UTF-8'){ 15 | $str = mb_convert_encoding($str, "UCS-4BE", $encoding); 16 | $result = array(); 17 | 18 | for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){ 19 | $c = mb_substr($str, $i, 1, "UCS-4BE"); 20 | $val = unpack("N", $c); 21 | $result[] = $val[1]; 22 | } 23 | return $result; 24 | } 25 | 26 | if (php_sapi_name() != "cli") { 27 | die("You have to run this program with php-cli!\n"); 28 | } 29 | 30 | if ($argc < 3) { 31 | die("Too few arguments.\nUsage: cmd \n"); 32 | } 33 | 34 | $cv = caca_create_canvas(0, 0); 35 | 36 | if (!caca_canvas_set_figfont($cv, $argv[1])) { 37 | die("Could not open font\n"); 38 | } 39 | 40 | $chars = unistr_to_ords($argv[2]); 41 | $color = 0; 42 | foreach ($chars as $c) { 43 | caca_set_color_ansi($cv, 1 + (($color += 4) % 15), CACA_TRANSPARENT); 44 | caca_put_figchar($cv, $c); 45 | } 46 | 47 | echo caca_export_string($cv, "utf8"); 48 | 49 | ?> 50 | -------------------------------------------------------------------------------- /caca-php/examples/fullwidth.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php5 2 | 6 | * 7 | * This file is a Php port of "examples/fullwidth.c" 8 | * which is: 9 | * Copyright (c) 2006 Sam Hocevar 10 | * All Rights Reserved 11 | * 12 | * This program 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 | if (php_sapi_name() != "cli") { 20 | die("You have to run this program with php-cli!\n"); 21 | } 22 | 23 | define('CACA', "쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊"); 24 | 25 | $cv = caca_create_canvas(0, 0); 26 | if(! $cv) 27 | { 28 | die("Can't created canvas\n"); 29 | } 30 | $dp = caca_create_display($cv); 31 | if(! $dp) 32 | { 33 | die("Can't create display\n"); 34 | } 35 | 36 | $caca = caca_create_canvas(6, 10); 37 | $line = caca_create_canvas(2, 1); 38 | 39 | /* Line of x's */ 40 | for($i = 0; $i < 10; $i++) 41 | { 42 | caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE); 43 | caca_put_str($caca, 0, $i, CACA); 44 | caca_set_color_ansi($caca, CACA_WHITE, CACA_RED); 45 | caca_put_char($caca, $i - 2, $i, ord('x')); 46 | } 47 | 48 | caca_blit($cv, 1, 1, $caca); 49 | 50 | /* Line of ホ's */ 51 | for($i = 0; $i < 10; $i++) 52 | { 53 | caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE); 54 | caca_put_str($caca, 0, $i, CACA); 55 | caca_set_color_ansi($caca, CACA_WHITE, CACA_GREEN); 56 | caca_put_str($caca, $i - 2, $i, "ホ"); 57 | } 58 | 59 | caca_blit($cv, 15, 1, $caca); 60 | 61 | /* Line of canvas */ 62 | caca_set_color_ansi($line, CACA_WHITE, CACA_MAGENTA); 63 | caca_put_str($line, 0, 0, "ほ"); 64 | for($i = 0; $i < 10; $i++) 65 | { 66 | caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE); 67 | caca_put_str($caca, 0, $i, CACA); 68 | caca_blit($caca, $i - 2, $i, $line); 69 | } 70 | 71 | caca_blit($cv, 29, 1, $caca); 72 | 73 | caca_refresh_display($dp); 74 | 75 | caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1); 76 | 77 | ?> 78 | -------------------------------------------------------------------------------- /caca-php/examples/import.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php5 2 | 6 | * 7 | * This file is a Php port of "examples/import.c" 8 | * which is: 9 | * Copyright (c) 2006 Jean-Yves Lamoureux 10 | * All Rights Reserved 11 | * 12 | * This program 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 | if (php_sapi_name() != "cli") { 20 | die("You have to run this program with php-cli!\n"); 21 | } 22 | 23 | $imports = caca_get_import_list(); 24 | 25 | if($argc < 2 || $argc > 3) 26 | { 27 | $msg = ($argv[0] . ": wrong argument count\n" . 28 | "usage: " . $argv[0] . " file []\n" . 29 | "where is one of:\n"); 30 | foreach($imports as $format => $name) 31 | $msg .= " \"" . $name . "\" (" . $format . ")\n"; 32 | die($msg); 33 | } 34 | 35 | $cv = caca_create_canvas(0, 0); 36 | if(! $cv) 37 | { 38 | die("Can't create canvas\n"); 39 | } 40 | 41 | if(caca_import_file($cv, $argv[1], $argc >= 3 ? $argv[2] : "") < 0) 42 | { 43 | die($argv[0] . ": could not open `" . $argv[1] . "'.\n"); 44 | } 45 | 46 | $dp = caca_create_display($cv); 47 | if(! $dp) 48 | { 49 | die("Can't create display\n"); 50 | } 51 | 52 | caca_refresh_display($dp); 53 | 54 | caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1); 55 | 56 | ?> 57 | -------------------------------------------------------------------------------- /caca-php/examples/logo-caca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cacalabs/libcaca/f42aa68fc798db63b7b2a789ae8cf5b90b57b752/caca-php/examples/logo-caca.png -------------------------------------------------------------------------------- /caca-php/examples/polyline.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php5 2 | 6 | * 7 | * This program is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | function transform($tbl, $tx, $ty, $sx, $sy) { 15 | $result = array(); 16 | foreach($tbl as $pt) 17 | $result[] = array($pt[0] * $sx + $tx, $pt[1] * $sy + $ty); 18 | return $result; 19 | } 20 | 21 | if (php_sapi_name() != "cli") { 22 | die("You have to run this program with php-cli!\n"); 23 | } 24 | 25 | $canvas = caca_create_canvas(0, 0); 26 | $display = caca_create_display($canvas); 27 | if (!$display) { 28 | die("Error while attaching canvas to display\n"); 29 | } 30 | 31 | $tbl = array( 32 | array(5, 2), 33 | array(15, 2), 34 | array(20, 4), 35 | array(25, 2), 36 | array(34, 2), 37 | array(37, 4), 38 | array(36, 9), 39 | array(20, 16), 40 | array(3, 9), 41 | array(2, 4), 42 | array(5, 2) 43 | ); 44 | 45 | for ($i = 0; $i < 10; $i++) { 46 | caca_set_color_ansi($canvas, 1 + (($color += 4) % 15), CACA_TRANSPARENT); 47 | $scale = caca_rand(4, 10) / 10; 48 | $translate = array(caca_rand(-5, 55), caca_rand(-2, 25)); 49 | $pts = transform($tbl, $translate[0], $translate[1], $scale, $scale); 50 | caca_draw_thin_polyline($canvas, $pts); 51 | } 52 | 53 | caca_put_str($canvas, 1, 1, "Caca forever..."); 54 | caca_refresh_display($display); 55 | caca_get_event($display, CACA_EVENT_KEY_PRESS, 5000000); 56 | 57 | ?> 58 | -------------------------------------------------------------------------------- /caca-php/examples/render.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php5 2 | 45 | -------------------------------------------------------------------------------- /caca-php/examples/text.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php5 2 | 6 | * 7 | * This file is a Php port of the official libcaca's sample program "demo.c" 8 | * which is: 9 | * Copyright (c) 2003 Sam Hocevar 10 | * 11 | * This program is free software. It comes without any warranty, to 12 | * the extent permitted by applicable law. You can redistribute it 13 | * and/or modify it under the terms of the Do What the Fuck You Want 14 | * to Public License, Version 2, as published by Sam Hocevar. See 15 | * http://www.wtfpl.net/ for more details. 16 | */ 17 | 18 | if (php_sapi_name() != "cli") { 19 | die("You have to run this program with php-cli!\n"); 20 | } 21 | 22 | $string = << 66 | -------------------------------------------------------------------------------- /caca-php/examples/truecolor.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php5 2 | 6 | * 7 | * This file is a Php port of "examples/truecolor.c" 8 | * which is: 9 | * Copyright (c) 2006 Sam Hocevar 10 | * All Rights Reserved 11 | * 12 | * This program 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 | if (php_sapi_name() != "cli") { 20 | die("You have to run this program with php-cli!\n"); 21 | } 22 | 23 | $cv = caca_create_canvas(32, 16); 24 | if(!$cv) { 25 | die("Failed to create canvas\n"); 26 | } 27 | 28 | $dp = caca_create_display($cv); 29 | if(!$dp) { 30 | die("Failed to create display\n"); 31 | } 32 | 33 | for($y = 0; $y < 16; $y++) 34 | for($x = 0; $x < 16; $x++) 35 | { 36 | $bgcolor = 0xff00 | ($y << 4) | $x; 37 | $fgcolor = 0xf000 | ((15 - $y) << 4) | ((15 - $x) << 8); 38 | 39 | caca_set_color_argb($cv, $fgcolor, $bgcolor); 40 | caca_put_str($cv, $x * 2, $y, "CA"); 41 | } 42 | 43 | caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE); 44 | caca_put_str($cv, 2, 1, " truecolor libcaca "); 45 | 46 | caca_refresh_display($dp); 47 | 48 | caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1); 49 | 50 | ?> 51 | -------------------------------------------------------------------------------- /caca-php/examples/www/colors.php: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | 8 | 12 | * 13 | * This file is a Php port of "examples/colors.c" 14 | * Copyright (c) 2003-2004 Sam Hocevar 15 | * All Rights Reserved 16 | * 17 | * This program is free software. It comes without any warranty, to 18 | * the extent permitted by applicable law. You can redistribute it 19 | * and/or modify it under the terms of the Do What the Fuck You Want 20 | * to Public License, Version 2, as published by Sam Hocevar. See 21 | * http://www.wtfpl.net/ for more details. 22 | */ 23 | ?> 24 | 25 | display all possible libcaca colour pairs 26 | 27 | 28 | 29 | = 8 ? 3 : 2), "ANSI " . $i); 43 | for($j = 0; $j < 16; $j++) 44 | { 45 | caca_set_color_ansi($cv, $i, $j); 46 | caca_put_str($cv, ($j >= 8 ? 13 : 12) + $j * 4, $i + ($i >= 8 ? 3 : 2), 47 | "Aaホ"); 48 | } 49 | } 50 | 51 | caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK); 52 | caca_put_str($cv, 3, 20, "This is bold This is blink This is italics This is underline"); 53 | caca_set_attr($cv, CACA_BOLD); 54 | caca_put_str($cv, 3 + 8, 20, "bold"); 55 | caca_set_attr($cv, CACA_BLINK); 56 | caca_put_str($cv, 3 + 24, 20, "blink"); 57 | caca_set_attr($cv, CACA_ITALICS); 58 | caca_put_str($cv, 3 + 41, 20, "italics"); 59 | caca_set_attr($cv, CACA_UNDERLINE); 60 | caca_put_str($cv, 3 + 60, 20, "underline"); 61 | 62 | echo caca_export_string($cv, "html3"); 63 | 64 | ?> 65 | 66 | 67 | -------------------------------------------------------------------------------- /caca-php/examples/www/dithering.php: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | 8 | 9 | Caca power! 10 | 11 | 12 | 13 | 17 | * 18 | * This program is free software. It comes without any warranty, to 19 | * the extent permitted by applicable law. You can redistribute it 20 | * and/or modify it under the terms of the Do What the Fuck You Want 21 | * to Public License, Version 2, as published by Sam Hocevar. See 22 | * http://www.wtfpl.net/ for more details. 23 | */ 24 | 25 | $src = "logo-caca.png"; 26 | $img = imagecreatefrompng(dirname(__FILE__)."/".$src); 27 | if (!$img) { 28 | die("Can not open image.\n"); 29 | } 30 | 31 | $dither = caca_create_dither($img); 32 | if (!$dither) { 33 | die("Can not create dither. Maybe you compiled caca-php without gd support.\n"); 34 | } 35 | 36 | $canvas = caca_create_canvas(100, 40); 37 | 38 | caca_dither_bitmap($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img); 39 | 40 | echo caca_export_string($canvas, "html3"); 41 | echo "\"\""; 42 | 43 | ?> 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /caca-php/examples/www/figlet.php: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | 8 | Caca power! 9 | 10 | 11 | 12 |
" />
13 | 17 | * 18 | * This program is free software. It comes without any warranty, to 19 | * the extent permitted by applicable law. You can redistribute it 20 | * and/or modify it under the terms of the Do What the Fuck You Want 21 | * to Public License, Version 2, as published by Sam Hocevar. See 22 | * http://www.wtfpl.net/ for more details. 23 | */ 24 | 25 | function unistr_to_ords($str, $encoding = 'UTF-8'){ 26 | $str = mb_convert_encoding($str, "UCS-4BE", $encoding); 27 | $result = array(); 28 | 29 | for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){ 30 | $c = mb_substr($str, $i, 1, "UCS-4BE"); 31 | $val = unpack("N", $c); 32 | $result[] = $val[1]; 33 | } 34 | return $result; 35 | } 36 | 37 | function show_figlet($str, $font) { 38 | $cv = caca_create_canvas(0, 0); 39 | 40 | if (!caca_canvas_set_figfont($cv, $font)) { 41 | return false; 42 | } 43 | 44 | $chars = unistr_to_ords($str); 45 | $color = 0; 46 | foreach ($chars as $c) { 47 | caca_set_color_ansi($cv, 1 + (($color += 1) % 13), CACA_WHITE); 48 | caca_put_figchar($cv, $c); 49 | } 50 | 51 | echo caca_export_string($cv, "html3"); 52 | } 53 | 54 | $path = "/usr/share/figlet/"; 55 | if (!is_dir($path)) { 56 | die("can not open directory $path.\n"); 57 | } 58 | 59 | $dir = opendir($path); 60 | while (($it = readdir($dir)) != false) { 61 | if (is_file($path.$it) and ereg("\.[tf]lf$", $it)) { 62 | echo "font : $it\n"; 63 | show_figlet(isset($_GET["str"]) ? $_GET["str"] : "Libcaca", $path.$it); 64 | } 65 | } 66 | ?> 67 | 68 | 69 | -------------------------------------------------------------------------------- /caca-php/examples/www/fullwidth.php: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | 8 | 12 | * 13 | * This file is a Php port of "examples/fullwidth.c" 14 | * which is: 15 | * Copyright (c) 2006 Sam Hocevar 16 | * All Rights Reserved 17 | * 18 | * This program is free software. It comes without any warranty, to 19 | * the extent permitted by applicable law. You can redistribute it 20 | * and/or modify it under the terms of the Do What the Fuck You Want 21 | * to Public License, Version 2, as published by Sam Hocevar. See 22 | * http://www.wtfpl.net/ for more details. 23 | */ 24 | ?> 25 | 26 | sample program for libcaca php binding 27 | 28 | 29 | 30 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /caca-php/examples/www/logo-caca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cacalabs/libcaca/f42aa68fc798db63b7b2a789ae8cf5b90b57b752/caca-php/examples/www/logo-caca.png -------------------------------------------------------------------------------- /caca-php/examples/www/render.php: -------------------------------------------------------------------------------- 1 | 52 | 53 | 54 | 55 | Я люблю Либкаку 56 | 57 | 58 | 59 | 60 |

Text mode:

61 | 62 | 63 |

Generated image:

64 | [PNG] 66 | 67 | 68 | 69 | 73 | -------------------------------------------------------------------------------- /caca-php/examples/www/text.php: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | 8 | 12 | * 13 | * This file is a Php port of the official libcaca's sample program "demo.c" 14 | * which is: 15 | * Copyright (c) 2003 Sam Hocevar 16 | * 17 | * This program is free software. It comes without any warranty, to 18 | * the extent permitted by applicable law. You can redistribute it 19 | * and/or modify it under the terms of the Do What the Fuck You Want 20 | * to Public License, Version 2, as published by Sam Hocevar. See 21 | * http://www.wtfpl.net/ for more details. 22 | */ 23 | ?> 24 | 25 | demo for libcaca php binding 26 | 27 | 28 | 29 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /caca-php/examples/www/truecolor.php: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | 8 | 12 | * 13 | * This file is a Php port of "examples/truecolor.c" 14 | * which is: 15 | * Copyright (c) 2006 Sam Hocevar 16 | * All Rights Reserved 17 | * 18 | * This program is free software. It comes without any warranty, to 19 | * the extent permitted by applicable law. You can redistribute it 20 | * and/or modify it under the terms of the Do What the Fuck You Want 21 | * to Public License, Version 2, as published by Sam Hocevar. See 22 | * http://www.wtfpl.net/ for more details. 23 | */ 24 | ?> 25 | 26 | truecolor canvas features 27 | 28 | 29 | 30 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /caca-php/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | caca 5 | PHP binding for libcaca 6 | This extension allows PHP scripts to use libcaca. 7 | 8 | 9 | 10 | zMoo 11 | Nicolas Vion 12 | nico@yojik.eu 13 | lead 14 | 15 | 16 | 17 | 0.0 18 | 2008-10-15 19 | WTFPL 20 | alpha 21 | See included ChangeLog for details... 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /caca-sharp/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * AssemblyInfo .NET bindings for libcaca 3 | * Copyright (c) 2006 Jean-Yves Lamoureux 4 | * All Rights Reserved 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | 14 | using System.Reflection; 15 | using System.Runtime.CompilerServices; 16 | 17 | [assembly: AssemblyTitle("Caca")] 18 | [assembly: AssemblyDescription("libcaca .NET bindings")] 19 | [assembly: AssemblyCopyright("(c) 2006 Jean-Yves Lamoureux 4 | * 2007 Sam Hocevar 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | using System; 15 | using System.Runtime.InteropServices; 16 | using System.Security; 17 | using System.Drawing; 18 | 19 | namespace Caca 20 | { 21 | public class Attr 22 | { 23 | private uint _attr; 24 | 25 | public Attr(uint attr) 26 | { 27 | _attr = attr; 28 | } 29 | 30 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 31 | SuppressUnmanagedCodeSecurity] 32 | private static extern byte caca_attr_to_ansi(uint a); 33 | public byte toAnsi() 34 | { 35 | return caca_attr_to_ansi(_attr); 36 | } 37 | 38 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 39 | SuppressUnmanagedCodeSecurity] 40 | private static extern byte caca_attr_to_ansi_fg(uint a); 41 | public byte toAnsiFg() 42 | { 43 | return caca_attr_to_ansi_fg(_attr); 44 | } 45 | 46 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 47 | SuppressUnmanagedCodeSecurity] 48 | private static extern byte caca_attr_to_ansi_bg(uint a); 49 | public byte toAnsiBg() 50 | { 51 | return caca_attr_to_ansi_bg(_attr); 52 | } 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /caca-sharp/Caca.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca .NET bindings for libcaca 3 | * Copyright (c) 2006 Jean-Yves Lamoureux 4 | * 2007 Sam Hocevar 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | using System; 15 | using System.Runtime.InteropServices; 16 | using System.Security; 17 | using System.Drawing; 18 | 19 | namespace Caca 20 | { 21 | /* Static libcaca stuff that does not fit in any object */ 22 | public static class Libcaca 23 | { 24 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 25 | SuppressUnmanagedCodeSecurity] 26 | private static extern int caca_rand(int min, int max); 27 | public static int Rand(int min, int max) 28 | { 29 | return caca_rand(min, max); 30 | } 31 | 32 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), 33 | SuppressUnmanagedCodeSecurity] 34 | private static extern IntPtr caca_get_version(); 35 | public static string getVersion() 36 | { 37 | return Marshal.PtrToStringAnsi(caca_get_version()); 38 | } 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /caca-sharp/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | # We need to install the .config file ourselves because of a gacutil 5 | # bug (https://bugzilla.novell.com/show_bug.cgi?id=363341) 6 | monodir = $(libdir)/mono/caca-sharp-0.0 7 | if USE_CSHARP 8 | noinst_DATA = caca-sharp.dll caca-sharp.dll.config test.exe 9 | endif 10 | 11 | caca_sources = \ 12 | $(srcdir)/AssemblyInfo.cs \ 13 | $(srcdir)/Caca.cs \ 14 | $(srcdir)/Attr.cs \ 15 | $(srcdir)/Canvas.cs \ 16 | $(srcdir)/Display.cs \ 17 | $(srcdir)/Dither.cs \ 18 | $(srcdir)/Event.cs \ 19 | $(srcdir)/Font.cs 20 | 21 | test_sources = \ 22 | $(srcdir)/test.cs 23 | 24 | EXTRA_DIST = $(caca_sources) $(test_sources) \ 25 | caca-sharp.snk caca-sharp.pc.in caca-sharp.dll.config.in \ 26 | caca-sharp.csproj test-csharp.csproj 27 | 28 | caca-sharp.dll: $(caca_sources) 29 | $(CSC) -debug -unsafe $(caca_sources) -out:$@ -target:library \ 30 | -keyfile:$(srcdir)/caca-sharp.snk -r:System.Drawing.dll 31 | 32 | test.exe: $(test_sources) caca-sharp.dll 33 | $(CSC) -debug $(test_sources) -out:$@ -lib:./ \ 34 | -r:System.Drawing.dll -r:./caca-sharp.dll 35 | 36 | if USE_CSHARP 37 | install-data-local: 38 | MONO_SHARED_DIR=$$HOME $(GACUTIL) -i caca-sharp.dll \ 39 | -package caca-sharp-0.0 -f -root $(DESTDIR)$(libdir) 40 | $(mkinstalldirs) $(DESTDIR)$(monodir) 41 | sed -e 's@target="[^"]*/@target="@' < caca-sharp.dll.config > $(DESTDIR)$(monodir)/caca-sharp.dll.config 42 | 43 | uninstall-local: 44 | MONO_SHARED_DIR=$$HOME $(GACUTIL) -u caca-sharp.dll, Version=0.0 \ 45 | -package caca-sharp-0.0 || true 46 | rm -f $(DESTDIR)$(monodir)/caca-sharp.dll.config 47 | rmdir $(DESTDIR)$(monodir) 2>/dev/null || true 48 | endif 49 | 50 | clean-local: 51 | rm -f *.exe *.dll *.mdb 52 | 53 | -------------------------------------------------------------------------------- /caca-sharp/caca-sharp.dll.config.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /caca-sharp/caca-sharp.pc.in: -------------------------------------------------------------------------------- 1 | Name: caca-sharp 2 | Description: caca-sharp 3 | Version: @PACKAGE_VERSION@ 4 | 5 | Requires: 6 | Libs: -r:@expanded_libdir@/@PACKAGE@/caca-sharp.dll 7 | -------------------------------------------------------------------------------- /caca-sharp/caca-sharp.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cacalabs/libcaca/f42aa68fc798db63b7b2a789ae8cf5b90b57b752/caca-sharp/caca-sharp.snk -------------------------------------------------------------------------------- /caca/caca.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: caca 7 | Description: Colour ASCII-Art library 8 | Version: @VERSION@ 9 | Requires: 10 | Conflicts: 11 | Libs: -L${libdir} -lcaca 12 | Libs.private: @ZLIB_LIBS@ 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /caca/caca_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | /* 14 | * This file contains debugging functions. 15 | */ 16 | 17 | #ifndef __CACA_DEBUG_H__ 18 | #define __CACA_DEBUG_H__ 19 | 20 | /* debug messages */ 21 | #if defined DEBUG && !defined __KERNEL__ 22 | # include 23 | # include 24 | static inline void debug(const char *format, ...) 25 | { 26 | int saved_errno = geterrno(); 27 | va_list args; 28 | va_start(args, format); 29 | fprintf(stderr, "** libcaca debug ** "); 30 | vfprintf(stderr, format, args); 31 | fprintf(stderr, "\n"); 32 | va_end(args); 33 | seterrno(saved_errno); 34 | } 35 | #else 36 | # define debug(format, ...) do {} while(0) 37 | #endif 38 | 39 | #endif /* __CACA_DEBUG_H__ */ 40 | 41 | -------------------------------------------------------------------------------- /caca/caca_prof.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2009-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | /* 14 | * This file contains profiling functions. 15 | */ 16 | 17 | #ifndef __CACA_PROF_H__ 18 | #define __CACA_PROF_H__ 19 | 20 | #if defined PROF && !defined __KERNEL__ 21 | # define PROFILING_VARS 22 | 23 | # define STAT_IADD(_s, _n) \ 24 | do \ 25 | { \ 26 | struct caca_stat *s = _s; \ 27 | int i, n = _n; \ 28 | for (i = STAT_VALUES - 1; i > 0; i--) \ 29 | s->itable[i] = s->itable[i - 1]; \ 30 | s->itable[0] = n; \ 31 | s->imean = (s->imean * 63 + (int64_t)n * 64 + 32) / 64; \ 32 | } \ 33 | while(0) 34 | 35 | # define START_PROF(obj, fn) 36 | # define STOP_PROF(obj, fn) 37 | 38 | #else 39 | # define PROFILING_VARS 40 | # define STAT_IADD(_s, _n) do { } while(0) 41 | # define START_PROF(obj, fn) do { } while(0) 42 | # define STOP_PROF(obj, fn) do { } while(0) 43 | #endif 44 | 45 | #endif /* __CACA_PROF_H__ */ 46 | 47 | -------------------------------------------------------------------------------- /caca/caca_stubs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | /* 14 | * This file contains replacements for commonly found object types and 15 | * function prototypes that are sometimes missing. 16 | */ 17 | 18 | #ifndef __CACA_STUBS_H__ 19 | #define __CACA_STUBS_H__ 20 | 21 | /* errno handling */ 22 | #if defined HAVE_ERRNO_H && !defined __KERNEL__ 23 | # include 24 | static inline void seterrno(int e) { errno = e; } 25 | static inline int geterrno(void) { return errno; } 26 | #else 27 | # define seterrno(x) do { (void)(x); } while(0) 28 | # define geterrno(x) 0 29 | #endif 30 | 31 | /* hton16() and hton32() */ 32 | #if defined HAVE_HTONS && !defined __KERNEL__ 33 | # if defined HAVE_ARPA_INET_H 34 | # include 35 | # elif defined HAVE_NETINET_IN_H 36 | # include 37 | # endif 38 | # define hton16 htons 39 | # define hton32 htonl 40 | #else 41 | # if defined __KERNEL__ 42 | /* Nothing to do */ 43 | # elif defined HAVE_ENDIAN_H 44 | # include 45 | # endif 46 | static inline uint16_t hton16(uint16_t x) 47 | { 48 | /* This is compile-time optimised with at least -O1 or -Os */ 49 | #if defined HAVE_ENDIAN_H 50 | if(__BYTE_ORDER == __BIG_ENDIAN) 51 | #else 52 | uint32_t const dummy = 0x12345678; 53 | if(*(uint8_t const *)&dummy == 0x12) 54 | #endif 55 | return x; 56 | else 57 | return (x >> 8) | (x << 8); 58 | } 59 | 60 | static inline uint32_t hton32(uint32_t x) 61 | { 62 | /* This is compile-time optimised with at least -O1 or -Os */ 63 | #if defined HAVE_ENDIAN_H 64 | if(__BYTE_ORDER == __BIG_ENDIAN) 65 | #else 66 | uint32_t const dummy = 0x12345678; 67 | if(*(uint8_t const *)&dummy == 0x12) 68 | #endif 69 | return x; 70 | else 71 | return (x >> 24) | ((x >> 8) & 0x0000ff00) 72 | | ((x << 8) & 0x00ff0000) | (x << 24); 73 | } 74 | #endif 75 | 76 | #endif /* __CACA_STUBS_H__ */ 77 | 78 | -------------------------------------------------------------------------------- /caca/codec/codec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2002-2014 Sam Hocevar 4 | * 2006 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | ssize_t _import_text(caca_canvas_t *, void const *, size_t); 15 | ssize_t _import_ansi(caca_canvas_t *, void const *, size_t, int); 16 | ssize_t _import_bin(caca_canvas_t *, void const *, size_t); 17 | 18 | void *_export_ansi(caca_canvas_t const *, size_t *); 19 | void *_export_utf8(caca_canvas_t const *, size_t *, int); 20 | void *_export_irc(caca_canvas_t const *, size_t *); 21 | 22 | -------------------------------------------------------------------------------- /caca/driver/null.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2002-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | /* 14 | * This file contains a null libcaca input and output driver 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #if !defined(__KERNEL__) 20 | 21 | #include 22 | 23 | #include "caca.h" 24 | #include "caca_internals.h" 25 | 26 | static int null_init_graphics(caca_display_t *dp) 27 | { 28 | return 0; 29 | } 30 | 31 | static int null_end_graphics(caca_display_t *dp) 32 | { 33 | return 0; 34 | } 35 | 36 | static int null_set_display_title(caca_display_t *dp, char const *title) 37 | { 38 | return -1; 39 | } 40 | 41 | static int null_get_display_width(caca_display_t const *dp) 42 | { 43 | return 0; 44 | } 45 | 46 | static int null_get_display_height(caca_display_t const *dp) 47 | { 48 | return 0; 49 | } 50 | 51 | static void null_display(caca_display_t *dp) 52 | { 53 | ; 54 | } 55 | 56 | static void null_handle_resize(caca_display_t *dp) 57 | { 58 | ; 59 | } 60 | 61 | static int null_get_event(caca_display_t *dp, caca_privevent_t *ev) 62 | { 63 | ev->type = CACA_EVENT_NONE; 64 | return 0; 65 | } 66 | 67 | /* 68 | * Driver initialisation 69 | */ 70 | 71 | int null_install(caca_display_t *dp) 72 | { 73 | dp->drv.id = CACA_DRIVER_NULL; 74 | dp->drv.driver = "null"; 75 | 76 | dp->drv.init_graphics = null_init_graphics; 77 | dp->drv.end_graphics = null_end_graphics; 78 | dp->drv.set_display_title = null_set_display_title; 79 | dp->drv.get_display_width = null_get_display_width; 80 | dp->drv.get_display_height = null_get_display_height; 81 | dp->drv.display = null_display; 82 | dp->drv.handle_resize = null_handle_resize; 83 | dp->drv.get_event = null_get_event; 84 | dp->drv.set_mouse = NULL; 85 | dp->drv.set_cursor = NULL; 86 | 87 | return 0; 88 | } 89 | 90 | #endif /* !__KERNEL__ */ 91 | -------------------------------------------------------------------------------- /caca/libcaca.def: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cacalabs/libcaca/f42aa68fc798db63b7b2a789ae8cf5b90b57b752/caca/libcaca.def -------------------------------------------------------------------------------- /caca/t/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | if USE_CPPUNIT 5 | cppunit_tests = caca-test 6 | endif 7 | if BUILD_DOCUMENTATION 8 | doxygen_tests = check-doxygen 9 | endif 10 | 11 | EXTRA_DIST = check-copyright check-doxygen check-source check-win32 12 | 13 | noinst_PROGRAMS = simple bench bug-setlocale $(cppunit_tests) 14 | 15 | TESTS = simple check-copyright check-source check-win32 \ 16 | $(doxygen_tests) $(cppunit_tests) 17 | 18 | simple_SOURCES = simple.c 19 | simple_LDADD = ../libcaca.la 20 | 21 | bench_SOURCES = bench.c 22 | bench_LDADD = ../libcaca.la 23 | 24 | bug_setlocale_SOURCES = bug-setlocale.c 25 | bug_setlocale_LDADD = ../libcaca.la 26 | 27 | caca_test_SOURCES = caca-test.cpp canvas.cpp dirty.cpp driver.cpp export.cpp 28 | caca_test_CXXFLAGS = $(CPPUNIT_CFLAGS) 29 | caca_test_LDADD = ../libcaca.la $(CPPUNIT_LIBS) 30 | 31 | -------------------------------------------------------------------------------- /caca/t/bench.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca benchmark program 3 | * Copyright (c) 2009 Pascal Terjan 4 | * 2009 Sam Hocevar 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #include 16 | 17 | #include "caca.h" 18 | 19 | #define BLIT_LOOPS 1000000 20 | #define PUTCHAR_LOOPS 50000000 21 | 22 | #define TIME(desc, code) \ 23 | { \ 24 | caca_display_t *dummy = caca_create_display_with_driver(NULL, "null"); \ 25 | printf("%-25s: ", desc);\ 26 | caca_refresh_display(dummy); \ 27 | code; \ 28 | caca_refresh_display(dummy); \ 29 | printf("%5dms\n", caca_get_display_time(dummy) / 1000); \ 30 | caca_free_display(dummy); \ 31 | } 32 | 33 | static void blit(int mask, int clear) 34 | { 35 | caca_canvas_t *cv, *cv2; 36 | int i; 37 | cv = caca_create_canvas(40, 40); 38 | cv2 = caca_create_canvas(16, 16); 39 | caca_fill_box(cv2, 0, 0, 16, 16, 'x'); 40 | for (i = 0; i < BLIT_LOOPS; i++) 41 | { 42 | if(clear) 43 | caca_clear_canvas(cv); 44 | caca_blit(cv, 1, 1, cv2, mask ? cv2 : NULL); 45 | } 46 | caca_free_canvas(cv); 47 | caca_free_canvas(cv2); 48 | } 49 | 50 | static void putchars(int optim) 51 | { 52 | caca_canvas_t *cv; 53 | int i; 54 | cv = caca_create_canvas(40, 40); 55 | if(optim) 56 | caca_disable_dirty_rect(cv); 57 | for (i = 0; i < PUTCHAR_LOOPS; i++) 58 | { 59 | caca_put_char(cv, 1, 1, 'x'); 60 | caca_put_char(cv, 1, 1, 'o'); 61 | } 62 | if(optim) 63 | { 64 | caca_enable_dirty_rect(cv); 65 | caca_add_dirty_rect(cv, 1, 1, 1, 1); 66 | } 67 | caca_free_canvas(cv); 68 | } 69 | 70 | int main(int argc, char *argv[]) 71 | { 72 | TIME("blit no mask, no clear", blit(0, 0)); 73 | TIME("blit no mask, clear", blit(0, 1)); 74 | TIME("blit mask, no clear", blit(1, 0)); 75 | TIME("blit mask, clear", blit(1, 1)); 76 | TIME("putchars, no optim", putchars(0)); 77 | TIME("putchars, optim", putchars(1)); 78 | return 0; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /caca/t/bug-setlocale.c: -------------------------------------------------------------------------------- 1 | /* 2 | * bug-setlocale: unit test for wrong setlocale() calls 3 | * Copyright © 2016 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | # include 18 | # include 19 | #endif 20 | 21 | #include "caca.h" 22 | 23 | #define TEST(x) \ 24 | do \ 25 | { \ 26 | tests++; \ 27 | if((x)) \ 28 | passed++; \ 29 | else \ 30 | fprintf(stderr, "test #%i failed: %s\n", (tests), #x); \ 31 | } \ 32 | while(0) 33 | 34 | int main(int argc, char *argv[]) 35 | { 36 | char buf[10]; 37 | char const * const * list; 38 | 39 | list = caca_get_display_driver_list(); 40 | 41 | int i, tests = 0, passed = 0; 42 | 43 | snprintf(buf, 10, "%.1f", 0.0f); 44 | TEST(buf[1] == '.'); 45 | 46 | for (i = 0; list[i]; i += 2) 47 | { 48 | if (!strcmp(list[i], "x11") || !strcmp(list[i], "ncurses")) 49 | { 50 | caca_display_t *dp = caca_create_display_with_driver(NULL, list[i]); 51 | 52 | snprintf(buf, 10, "%.1f", 0.0f); 53 | TEST(buf[1] == '.'); 54 | 55 | caca_free_display(dp); 56 | } 57 | } 58 | 59 | fprintf(stderr, "%i tests, %i errors\n", tests, tests - passed); 60 | 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /caca/t/caca-test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * caca-test testsuite program for libcaca 3 | * Copyright (c) 2008 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #include 16 | #include 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | CppUnit::TextTestRunner runner; 21 | runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); 22 | 23 | return !runner.run(); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /caca/t/check-copyright: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export MAKEFLAGS="" 4 | top_srcdir="$(make -s echo-topdir)" 5 | 6 | # 7 | # Check that the copyright information is valid 8 | # 9 | nfails=0 10 | nfiles=0 11 | for dir in $(make -s echo-dirs -C "${top_srcdir}"); do 12 | if [ ! -d "${top_srcdir}/${dir}" ]; then continue; fi 13 | for x in $(make -s echo-sources -C "${top_srcdir}/${dir}"); do 14 | case "$x" in 15 | *.c|*.cpp|*.h|*.m|*.php|*.cs|*.java|.py|.pl) 16 | nfiles=$(($nfiles + 1)) ;; 17 | *) 18 | continue ;; 19 | esac 20 | if ! grep 'Copyright *\((c)\|(C)\|©\)' "${top_srcdir}/${dir}/$x" >/dev/null 2>&1; then 21 | echo "error: ${dir}/$x lacks proper copyright information" 22 | nfails=$(($nfails + 1)) 23 | elif [ -d "${top_srcdir}/.git" ]; then 24 | Y="$(git log "${top_srcdir}/${dir}/$x" | head -n 3 | sed -ne 's/^Date.* \([0-9][0-9][0-9][0-9]\) .*/\1/p')" 25 | if [ "$Y" != "" ]; then 26 | if ! grep "$Y.*@" "${top_srcdir}/${dir}/$x" >/dev/null 2>&1; then 27 | echo "error: ${top_srcdir}/${dir}/$x last modified in $Y, which is not in copyright" 28 | git log "${top_srcdir}/${dir}/$x" | head -n 3 | sed 's/^/info: /' 29 | nfails=$(($nfails + 1)) 30 | fi 31 | fi 32 | fi 33 | done 34 | done 35 | 36 | echo "$nfiles files, $nfails errors in copyright information" 37 | 38 | if test "$nfails" -gt "10"; then 39 | echo "That’s too many errors, deliberately failing test" 40 | exit 1 41 | fi 42 | 43 | exit 0 44 | 45 | -------------------------------------------------------------------------------- /caca/t/check-doxygen: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export MAKEFLAGS="" 4 | top_srcdir="$(make -s echo-topdir 2>/dev/null)" 5 | 6 | # 7 | # Check for Doxygen warnings 8 | # 9 | nfiles="$(grep -c "Parsing file" < "${top_srcdir}/doc/doxygen.log")" 10 | if nfails="$(grep -c Warning: "${top_srcdir}/doc/doxygen.log" 2>/dev/null)"; then 11 | grep Warning: "${top_srcdir}/doc/doxygen.log" | sed 's/\(.\{75\}\)...*/\1 .../' 12 | fi 13 | 14 | echo "$nfiles files, $nfails visible errors in documentation" 15 | 16 | # Make errors non-fatal on Darwin, because Travis-CI always 17 | # has outdated software. 18 | if test "$(uname -s)" = "Darwin"; then 19 | exit 0 20 | fi 21 | 22 | if test "$nfails" != "0"; then 23 | exit 1 24 | fi 25 | 26 | exit 0 27 | 28 | -------------------------------------------------------------------------------- /caca/t/check-source: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export MAKEFLAGS="" 4 | top_srcdir="$(make -s echo-topdir)" 5 | 6 | # 7 | # Check that we have no tabs or trailing spaces in the source code 8 | # 9 | nfails=0 10 | nfiles=0 11 | nlines=0 12 | for dir in $(make -s echo-dirs -C "${top_srcdir}"); do 13 | if [ ! -d "${top_srcdir}/${dir}" ]; then continue; fi 14 | for x in $(make -s echo-sources -C "${top_srcdir}/${dir}"); do 15 | case "$x" in 16 | *.c|*.cpp|*.h|*.m|*.php|*.cs|*.java|*.py|*.pl) 17 | nfiles=$(($nfiles + 1)); 18 | nlines=$(($nlines + `grep -c . "${top_srcdir}/${dir}/$x"`)) ;; 19 | *) 20 | continue ;; 21 | esac 22 | if grep '[[:space:]]$' "${top_srcdir}/${dir}/$x" >/dev/null 2>&1; then 23 | echo "error: ${dir}/$x contains trailing spaces" 24 | nfails=$(($nfails + 1)) 25 | fi 26 | if grep ' ' "${top_srcdir}/${dir}/$x" >/dev/null 2>&1; then 27 | echo "error: ${dir}/$x contains tabs" 28 | nfails=$(($nfails + 1)) 29 | fi 30 | done 31 | done 32 | 33 | echo "$nfiles files, $nlines lines, $nfails errors in source code" 34 | 35 | if test "$nfails" != "0"; then 36 | exit 1 37 | fi 38 | 39 | exit 0 40 | 41 | -------------------------------------------------------------------------------- /caca/t/check-win32: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export MAKEFLAGS="" 4 | top_srcdir="$(make -s echo-topdir)" 5 | 6 | # 7 | # Check that the Win32 config.h is in sync with config.h.in 8 | # 9 | 10 | config_h_in="${top_srcdir}/config.h.in" 11 | win32_config_h="${top_srcdir}/build/win32/config.h" 12 | 13 | nfails=0 14 | ntokens=0 15 | for key in $(sed -ne 's/.*#undef *\([A-Za-z0-9_]*\).*/\1/p' "$config_h_in"); 16 | do 17 | ntokens=$(($ntokens + 1)) 18 | if ! grep '[ef] \<'"$key"'\>' "$win32_config_h" >/dev/null 2>&1; then 19 | echo "error: $key missing from build/win32/config.h" 20 | nfails=$(($nfails + 1)) 21 | fi 22 | done 23 | 24 | echo "$ntokens tokens, $nfails errors in Win32 config.h" 25 | 26 | if test "$nfails" != "0"; then 27 | exit 1 28 | fi 29 | 30 | exit 0 31 | 32 | -------------------------------------------------------------------------------- /caca/t/driver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * caca-test testsuite program for libcaca 3 | * Copyright (c) 2008 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "caca.h" 21 | 22 | class DriverTest : public CppUnit::TestCase 23 | { 24 | CPPUNIT_TEST_SUITE(DriverTest); 25 | CPPUNIT_TEST(test_list); 26 | CPPUNIT_TEST_SUITE_END(); 27 | 28 | public: 29 | DriverTest() : CppUnit::TestCase("Driver Test") {} 30 | 31 | void setUp() {} 32 | 33 | void tearDown() {} 34 | 35 | void test_list() 36 | { 37 | char const * const * list; 38 | 39 | list = caca_get_display_driver_list(); 40 | CPPUNIT_ASSERT(list != NULL); 41 | CPPUNIT_ASSERT(list[0] != NULL); 42 | } 43 | }; 44 | 45 | CPPUNIT_TEST_SUITE_REGISTRATION(DriverTest); 46 | 47 | -------------------------------------------------------------------------------- /caca/t/export.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * caca-test testsuite program for libcaca 3 | * Copyright (c) 2009 Pascal Terjan 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "caca.h" 21 | 22 | class ExportTest : public CppUnit::TestCase 23 | { 24 | CPPUNIT_TEST_SUITE(ExportTest); 25 | CPPUNIT_TEST(test_export_area_caca); 26 | CPPUNIT_TEST_SUITE_END(); 27 | 28 | public: 29 | ExportTest() : CppUnit::TestCase("Export/Import Test") {} 30 | 31 | void setUp() {} 32 | 33 | void tearDown() {} 34 | 35 | void test_export_area_caca() 36 | { 37 | caca_canvas_t *cv; 38 | size_t bytes, l; 39 | void *buf; 40 | 41 | cv = caca_create_canvas(WIDTH, HEIGHT); 42 | caca_put_char(cv, 7, 3, 'a'); 43 | caca_put_char(cv, 10, 3, 'b'); 44 | caca_put_char(cv, 5, 5, 'c'); 45 | buf = caca_export_area_to_memory (cv, 0, 0, 10, 5, "caca", &bytes); 46 | CPPUNIT_ASSERT(buf != NULL); 47 | CPPUNIT_ASSERT(bytes > 0); 48 | 49 | caca_clear_canvas(cv); 50 | l = caca_import_area_from_memory(cv, 0, 0, buf, bytes, "caca"); 51 | CPPUNIT_ASSERT(l == bytes); 52 | CPPUNIT_ASSERT(caca_get_char(cv, 7, 3) == 'a'); 53 | CPPUNIT_ASSERT(caca_get_char(cv, 10, 3) == ' '); 54 | CPPUNIT_ASSERT(caca_get_char(cv, 5, 5) == ' '); 55 | 56 | caca_put_char(cv, 10, 3, 'b'); 57 | caca_put_char(cv, 5, 5, 'c'); 58 | l = caca_import_area_from_memory(cv, 0, 0, buf, bytes, "caca"); 59 | CPPUNIT_ASSERT(l == bytes); 60 | CPPUNIT_ASSERT(caca_get_char(cv, 7, 3) == 'a'); 61 | CPPUNIT_ASSERT(caca_get_char(cv, 10, 3) == 'b'); 62 | CPPUNIT_ASSERT(caca_get_char(cv, 5, 5) == 'c'); 63 | 64 | caca_free_canvas(cv); 65 | } 66 | 67 | private: 68 | static int const WIDTH = 80, HEIGHT = 50; 69 | }; 70 | 71 | CPPUNIT_TEST_SUITE_REGISTRATION(ExportTest); 72 | 73 | -------------------------------------------------------------------------------- /caca/t/simple.c: -------------------------------------------------------------------------------- 1 | /* 2 | * simple simple testsuite program 3 | * Copyright © 2007—2016 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | # include 18 | #endif 19 | 20 | #include "caca.h" 21 | 22 | #define TEST(x) \ 23 | do \ 24 | { \ 25 | tests++; \ 26 | if((x)) \ 27 | passed++; \ 28 | else \ 29 | fprintf(stderr, "test #%i failed: %s\n", (tests), #x); \ 30 | } \ 31 | while(0) 32 | 33 | int main(int argc, char *argv[]) 34 | { 35 | caca_canvas_t *cv; 36 | int tests = 0, passed = 0; 37 | 38 | cv = caca_create_canvas(0, 0); 39 | caca_put_char(cv, 0, 0, 'x'); 40 | TEST(caca_get_char(cv, 0, 0) != 'x'); 41 | 42 | caca_rotate_180(cv); 43 | 44 | caca_set_canvas_size(cv, 1, 1); 45 | TEST(caca_get_char(cv, 0, 0) != 'x'); 46 | TEST(caca_get_char(cv, 0, 0) == ' '); 47 | 48 | caca_put_char(cv, 0, 0, 'y'); 49 | TEST(caca_get_char(cv, 0, 0) == 'y'); 50 | 51 | caca_set_canvas_size(cv, 1000, 1000); 52 | TEST(caca_get_canvas_width(cv) == 1000); 53 | 54 | caca_put_char(cv, 999, 999, 'z'); 55 | TEST(caca_get_char(cv, 999, 999) == 'z'); 56 | 57 | caca_free_canvas(cv); 58 | 59 | fprintf(stderr, "%i tests, %i errors\n", tests, tests - passed); 60 | 61 | return 0; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /cxx/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | EXTRA_DIST = libcaca++.vcxproj libcaca++.def test-cxx.vcxproj 5 | if USE_CXX 6 | pkgconfig_DATA = caca++.pc 7 | pkgconfigdir = $(libdir)/pkgconfig 8 | 9 | include_HEADERS = caca++.h 10 | lib_LTLIBRARIES = libcaca++.la 11 | endif 12 | 13 | libcaca___la_SOURCES = caca++.cpp caca++.h 14 | libcaca___la_LDFLAGS = -no-undefined -version-number @LT_VERSION@ 15 | libcaca___la_LIBADD = ../caca/libcaca.la 16 | 17 | if USE_CXX 18 | noinst_PROGRAMS = cxxtest 19 | endif 20 | 21 | cxxtest_SOURCES = cxxtest.cpp 22 | cxxtest_LDADD = libcaca++.la ../caca/libcaca.la 23 | 24 | uninstall-local: 25 | . ./libcaca++.la || exit 1; \ 26 | rmdir $(DESTDIR)$(libdir) 2>/dev/null || true 27 | rmdir $(DESTDIR)$(pkgconfigdir) 2>/dev/null || true 28 | 29 | -------------------------------------------------------------------------------- /cxx/caca++.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: caca++ 7 | Description: Colour ASCII-Art library C++ bindings 8 | Version: @VERSION@ 9 | Requires: 10 | Conflicts: 11 | Libs: -L${libdir} -lcaca++ 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /cxx/libcaca++.def: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cacalabs/libcaca/f42aa68fc798db63b7b2a789ae8cf5b90b57b752/cxx/libcaca++.def -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | EXTRA_DIST = doxygen.cfg.in doxygen.css footer.html header.html \ 5 | $(man_MANS) $(doxygen_DOX) 6 | CLEANFILES = doxygen.log stamp-latex stamp-doxygen 7 | 8 | doxygen_DOX = libcaca.dox user.dox migrating.dox tutorial.dox canvas.dox font.dox style.dox 9 | man_MANS = caca-config.1 cacafire.1 cacaview.1 cacaserver.1 img2txt.1 cacaplay.1 10 | 11 | if BUILD_DOCUMENTATION 12 | htmldoc_DATA = html/doxygen.css 13 | htmldocdir = $(datadir)/doc/libcaca-dev/html 14 | if USE_LATEX 15 | pdfdoc_DATA = latex/libcaca.pdf 16 | pdfdocdir = $(datadir)/doc/libcaca-dev/pdf 17 | endif 18 | endif 19 | 20 | html/doxygen.css html/doxygen.png: stamp-doxygen 21 | latex/libcaca.pdf: stamp-latex 22 | 23 | stamp-doxygen: $(doxygen_DOX) 24 | if BUILD_DOCUMENTATION 25 | doxygen doxygen.cfg 2>&1 | tee doxygen.log 26 | touch stamp-doxygen 27 | endif 28 | 29 | stamp-latex: stamp-doxygen 30 | if BUILD_DOCUMENTATION 31 | if USE_LATEX 32 | rm -f latex/libcaca.pdf 33 | cd latex && $(MAKE) $(AM_CFLAGS) refman.pdf || (cat refman.log; exit 1) 34 | mv latex/refman.pdf latex/libcaca.pdf 35 | touch stamp-latex 36 | endif 37 | endif 38 | 39 | clean-local: 40 | -rm -Rf html latex man 41 | 42 | install-data-local: 43 | if BUILD_DOCUMENTATION 44 | mkdir -p $(DESTDIR)$(datadir)/doc 45 | $(mkinstalldirs) $(DESTDIR)$(datadir)/doc/libcaca-dev/html 46 | cp `find html -name '*.html' -o -name '*.gif' -o -name '*.png'` \ 47 | $(DESTDIR)$(datadir)/doc/libcaca-dev/html 48 | $(mkinstalldirs) $(DESTDIR)$(mandir)/man3 49 | for man in $$(find man -name '*.3caca'); do \ 50 | sed -e 's/man3caca/man3/g' -e "s/fC'\([a-zA-Z0-9]*\)'/fC\"\1\"/g" \ 51 | $$man >$(DESTDIR)$(mandir)/man3/$${man##*/}; \ 52 | done 53 | endif 54 | $(mkinstalldirs) $(DESTDIR)$(mandir)/man1 55 | rm -f $(DESTDIR)$(mandir)/man1/cacademo.1 56 | ln -sf cacafire.1 $(DESTDIR)$(mandir)/man1/cacademo.1 57 | 58 | uninstall-local: 59 | rmdir $(DESTDIR)$(datadir)/doc 2>/dev/null || true 60 | 61 | -------------------------------------------------------------------------------- /doc/caca-config.1: -------------------------------------------------------------------------------- 1 | .TH caca-config 1 "2003-11-22" "libcaca" 2 | .SH NAME 3 | caca-config \- script to get information about the installed version of libcaca 4 | .SH SYNOPSIS 5 | .B caca-config 6 | [ --prefix= 7 | .IR DIR ] 8 | [ --exec-prefix= 9 | .IR DIR ] 10 | [ --version ] [ --libs ] [ --cflags ] 11 | .SH DESCRIPTION 12 | .B caca-config 13 | is a tool that is used to configure and determine the compiler and linker 14 | flags that should be used to compile and link progams, libraries, and 15 | plugins that use libcaca. 16 | 17 | The use of 18 | .B caca-config 19 | is deprecated. The more generic tool 20 | .B pkg-config 21 | should be used instead. 22 | .SH OPTIONS 23 | .TP 24 | .B --cflags 25 | Print the compiler flags that are necessary to compile a program or library 26 | that uses libcaca. 27 | .TP 28 | .BI --exec-prefix= DIR 29 | If specified, use 30 | .I DIR 31 | instead of the installation exec prefix that libcaca was build with when 32 | computing the output for the --cflags and --libs options. 33 | This option must be specified before any of the --cflags and --libs options. 34 | .TP 35 | .B --libs 36 | Print the linker flags that are necessary to link a program or library 37 | that uses libcaca. 38 | .TP 39 | .BI --prefix= DIR 40 | If specified, use PREFIX instead of the installation prefix that libcaca 41 | was built with when computing the output for the --cflags and --libs 42 | options. This option is also used for the exec prefix if --exec-prefix 43 | was not specified. This option must be specified before any of the --cflags 44 | and --libs options. 45 | .TP 46 | .B --version 47 | Prints the currently installed version of libcaca on standard output. 48 | .SH EXAMPLES 49 | .TP 50 | gcc -o main.o $(caca-config --cflags) -c main.c 51 | is how you might use 52 | .B caca-config 53 | to compile a C source file for an executable program. 54 | .TP 55 | gcc -o my_app $(caca-config --libs) main.o util.o 56 | is how you might use 57 | .B caca-config 58 | to link compiled objects into an executable program. 59 | .SH SEE ALSO 60 | pkg-config(1) 61 | .SH AUTHOR 62 | The libcaca library was written by Sam Hocevar . 63 | .PP 64 | This manual page was written for sdl-config by Branden Robinson, originally 65 | for Progeny Linux Systems, Inc., and the Debian Project. It was adapted to 66 | libcaca by Sam Hocevar. 67 | -------------------------------------------------------------------------------- /doc/cacafire.1: -------------------------------------------------------------------------------- 1 | .TH libcaca 1 "2006-9-23" "libcaca" 2 | .SH NAME 3 | cacademo, cacafire \- libcaca's demonstration applications 4 | .SH SYNOPSIS 5 | cacademo 6 | .PP 7 | cacafire 8 | .RI 9 | .SH DESCRIPTION 10 | This manual page documents briefly the cacademo and cacafire programs. 11 | .PP 12 | .B cacademo 13 | displays ASCII art effects with animated transitions: metaballs, moire pattern 14 | of concentric circles, old school plasma, Matrix-like scrolling. 15 | .PP 16 | .B cacafire 17 | displays burning ASCII art flames. 18 | .SH KEYS 19 | .TP 20 | .B Enter 21 | forces an effect transition to happen 22 | .TP 23 | .B Space 24 | pauses and resumes the program 25 | .TP 26 | .B Esc 27 | exits the program 28 | .SH BUGS 29 | Please report any bugs you find to . 30 | .SH LICENSE 31 | cacademo is covered by the Do What the Fuck You Want to Public License 32 | (WTFPL). cacafire is covered by the GNU Lesser General Public License (LGPL). 33 | .SH AUTHORS 34 | .B cacademo's 35 | moire and matrix effects and this manual page were written by Sam Hocevar 36 | . 37 | .PP 38 | .B cacademo's 39 | metaball effect was written by Jean-Yves Lamoureux , 40 | .B cacafire 41 | is a port of AAlib's 42 | .B aafire 43 | written by Jan Hubicka and 44 | .B cacademo's 45 | plasma effect is a port of an SDL plasma effect written and put in the 46 | public domain by Michele Bini . 47 | .SH SEE ALSO 48 | cacaview(1), aafire(1) 49 | -------------------------------------------------------------------------------- /doc/cacaplay.1: -------------------------------------------------------------------------------- 1 | .TH cacaplay 1 "2006-11-10" "libcaca" 2 | .SH NAME 3 | cacaplay \- play libcaca files 4 | .SH SYNOPSIS 5 | .B cacaplay [FILE] 6 | .RI 7 | .SH DESCRIPTION 8 | .B cacaplay 9 | plays libcaca animation files. These files can be created by any libcaca 10 | program by setting the 11 | .B CACA_DRIVER 12 | environment variable to 13 | .B "raw" 14 | and storing the program's standard output. 15 | 16 | If no file argument is provided or '\-' is used, 17 | .B cacaplay 18 | will read its data from the standard input. 19 | .SH EXAMPLES 20 | cacaplay file.caca 21 | 22 | CACA_DRIVER=raw CACA_GEOMETRY=80x32 cacademo | cacaplay 23 | .SH SEE ALSO 24 | cacaserver(1) 25 | .SH AUTHOR 26 | This manual page was written by Sam Hocevar . 27 | -------------------------------------------------------------------------------- /doc/cacaserver.1: -------------------------------------------------------------------------------- 1 | .TH cacaserver 1 "2006-11-10" "libcaca" 2 | .SH NAME 3 | cacaserver \- telnet server for libcaca 4 | .SH SYNOPSIS 5 | .B cacaserver 6 | .RI 7 | .SH DESCRIPTION 8 | .B cacaserver 9 | reads libcaca animation files in its standard input and serves them as ANSI 10 | art on network port 51914. These animations can be created by any libcaca 11 | program by setting the 12 | .B CACA_DRIVER 13 | environment variable to 14 | .B "raw" 15 | and piping the program's standard output to 16 | .B cacaserver. 17 | 18 | Clients can then connect to port 51914 using 19 | .B telnet 20 | or 21 | .B netcat 22 | to see the output. 23 | .SH EXAMPLE 24 | CACA_DRIVER=raw cacademo | cacaserver 25 | 26 | telnet localhost 51914 27 | .SH SEE ALSO 28 | cacaplay(1) 29 | .SH AUTHOR 30 | This manual page was written by Sam Hocevar . 31 | -------------------------------------------------------------------------------- /doc/cacaview.1: -------------------------------------------------------------------------------- 1 | .TH cacaview 1 "2003-11-30" "libcaca" 2 | .SH NAME 3 | cacaview \- ASCII image browser 4 | .SH SYNOPSIS 5 | .B cacaview [FILE...] 6 | .RI 7 | .SH DESCRIPTION 8 | .B cacaview 9 | is a lightweight text mode image viewer. It renders images using colour 10 | ASCII characters. It is a powerful add-on to famous console programs such 11 | as the mutt email client, the slrn newsreader and the links or w3m web 12 | browsers. 13 | .PP 14 | .B cacaview 15 | can load the most widespread image formats: PNG, JPEG, GIF, PNG, BMP etc. 16 | .PP 17 | You can zoom and scroll the image around for more details, and choose four 18 | different dithering modes. All commands are accessible through a single 19 | key press. 20 | .SH KEYS 21 | .TP 22 | .B ? 23 | show the help screen 24 | .TP 25 | .B n, p 26 | switch to next image, previous image 27 | .TP 28 | .B Left, Right, Up, Down or h, l, k, j 29 | scroll the image around 30 | .TP 31 | .B +, - 32 | zoom in and out 33 | .TP 34 | .B z 35 | reset the zoom level to normal 36 | .TP 37 | .B f 38 | switch fullscreen mode (hide/show menu and status bars) 39 | .TP 40 | .B d 41 | toggle the dithering mode (no dithering, 4x4 ordered dithering, 8x8 ordered 42 | dithering and random dithering) 43 | .TP 44 | .B q 45 | exit the program 46 | .SH EXAMPLE 47 | cacaview /usr/share/pixmaps/*.* 48 | .SH BUGS 49 | There is no support for aspect ratio yet. Also, since there is no way 50 | yet to load an image from 51 | .B cacaview 52 | it is completely useless when run without an argument. 53 | .SH SEE ALSO 54 | img2txt(1) 55 | .SH AUTHOR 56 | This manual page was written by Sam Hocevar . 57 | -------------------------------------------------------------------------------- /doc/canvas.dox: -------------------------------------------------------------------------------- 1 | /** \page libcaca-canvas The libcaca canvas format (version 1) 2 | 3 | All types are big endian. 4 | 5 | \code 6 | struct 7 | { 8 | magic: 9 | uint8_t caca_header[2]; // "\xCA\xCA" 10 | uint8_t caca_file_type[2]; // "CV" 11 | 12 | canvas_header: 13 | uint32_t control_size; // Control size (canvas_data - canvas_header) 14 | uint32_t data_size; // Data size (EOF - canvas_data) 15 | 16 | uint16_t version; // Canvas format version 17 | // bit 0: set to 1 if canvas is compatible 18 | // with version 1 of the format 19 | // bits 1-15: unused yet, must be 0 20 | 21 | uint32_t frames; // Frame count 22 | 23 | uint16_t flags; // Feature flags 24 | // bits 0-15: unused yet, must be 0 25 | 26 | frame_info: 27 | struct 28 | { 29 | uint32_t width; // Frame width 30 | uint32_t height; // Frame height 31 | uint32_t duration; // Frame duration in milliseconds, 0 to 32 | // not specify a duration 33 | uint32_t attr; // Graphics context attribute 34 | int32_t cursor_x; // Cursor X coordinate 35 | int32_t cursor_y; // Cursor Y coordinate 36 | int32_t handle_x; // Handle X coordinate 37 | int32_t handle_y; // Handle Y coordinate 38 | } 39 | frame_list[frames]; 40 | 41 | control_extension_1: 42 | control_extension_2: 43 | ... 44 | control_extension_N: 45 | ... // reserved for future use 46 | 47 | canvas_data: 48 | uint8_t data[data_size]; // canvas data 49 | 50 | data_extension_1: 51 | data_extension_2: 52 | ... 53 | data_extension_N: 54 | ... // reserved for future use 55 | }; 56 | \endcode 57 | 58 | */ 59 | -------------------------------------------------------------------------------- /doc/doxygen.css: -------------------------------------------------------------------------------- 1 | .fragment { 2 | font-family: monospace, fixed; 3 | font-size: 95%; 4 | } 5 | pre.fragment { 6 | border: 1px solid #CCCCCC; 7 | background-color: #f5f5f5; 8 | margin-top: 4px; 9 | margin-bottom: 4px; 10 | margin-left: 2px; 11 | margin-right: 8px; 12 | padding-left: 6px; 13 | padding-right: 6px; 14 | padding-top: 4px; 15 | padding-bottom: 4px; 16 | } 17 | 18 | span.keyword { color: #008000 } 19 | span.keywordtype { color: #604020 } 20 | span.keywordflow { color: #e08000 } 21 | span.comment { color: #800000 } 22 | span.preprocessor { color: #806020 } 23 | span.stringliteral { color: #002080 } 24 | span.charliteral { color: #008080 } 25 | 26 | /* Style for detailed member documentation */ 27 | .memtemplate { 28 | font-size: 80%; 29 | color: #606060; 30 | font-weight: normal; 31 | } 32 | .memnav { 33 | background-color: #e8eef2; 34 | border: 1px solid #84b0c7; 35 | text-align: center; 36 | margin: 2px; 37 | margin-right: 15px; 38 | padding: 2px; 39 | } 40 | .memitem { 41 | padding: 4px; 42 | /*background-color: #eef3f5;*/ 43 | /*border-width: 1px;*/ 44 | /*border-style: solid;*/ 45 | /*border-color: #dedeee;*/ 46 | /*-moz-border-radius: 8px 8px 8px 8px;*/ 47 | } 48 | .memname { 49 | white-space: nowrap; 50 | font-weight: bold; 51 | } 52 | .memdoc{ 53 | padding-left: 10px; 54 | } 55 | .memproto { 56 | background-color: #d5e1e8; 57 | width: 100%; 58 | border-width: 1px; 59 | border-style: solid; 60 | border-color: #84b0c7; 61 | font-weight: bold; 62 | -moz-border-radius: 8px 8px 8px 8px; 63 | } 64 | .paramkey { 65 | text-align: right; 66 | } 67 | .paramtype { 68 | white-space: nowrap; 69 | } 70 | .paramname { 71 | color: #602020; 72 | font-style: italic; 73 | } 74 | /* End Styling for detailed member documentation */ 75 | 76 | /* Remove those ugly
s */ 77 | hr { 78 | display: none; 79 | } 80 | 81 | -------------------------------------------------------------------------------- /doc/font.dox: -------------------------------------------------------------------------------- 1 | /** \page libcaca-font The libcaca font format (version 1) 2 | 3 | All types are big endian. 4 | 5 | \code 6 | struct 7 | { 8 | magic: 9 | uint8_t caca_header[2]; // "\xCA\xCA" 10 | uint8_t caca_file_type[2]; // "FT" 11 | 12 | font_header: 13 | uint32_t control_size; // Control size (font_data - font_header) 14 | uint32_t data_size; // Data size (EOF - font_data) 15 | 16 | uint16_t version; // Font format version 17 | // bit 0: set to 1 if font is compatible 18 | // with version 1 of the format 19 | // bits 1-15: unused yet, must be 0 20 | 21 | uint16_t blocks; // Number of blocks in the font 22 | uint32_t glyphs; // Total number of glyphs in the font 23 | 24 | uint16_t bpp; // Bits per pixel for glyph data (valid 25 | // Values are 1, 2, 4 and 8) 26 | uint16_t width; // Standard glyph width 27 | uint16_t height; // Standard glyph height 28 | uint16_t maxwidth; // Maximum glyph width 29 | uint16_t maxheight; // Maximum glyph height 30 | 31 | uint16_t flags; // Feature flags 32 | // bit 0: set to 1 if font is fixed width 33 | // bits 1-15: unused yet, must be 0 34 | 35 | block_info: 36 | struct 37 | { 38 | uint32_t start; // Unicode index of the first glyph 39 | uint32_t stop; // Unicode index of the last glyph + 1 40 | uint32_t index; // Glyph info index of the first glyph 41 | } 42 | block_list[blocks]; 43 | 44 | glyph_info: 45 | struct 46 | { 47 | uint16_t width; // Glyph width in pixels 48 | uint16_t height; // Glyph height in pixels 49 | uint32_t data_offset; // Offset (starting from data) to the data 50 | // for the first character 51 | } 52 | glyph_list[glyphs]; 53 | 54 | control_extension_1: 55 | control_extension_2: 56 | ... 57 | control_extension_N: 58 | ... // reserved for future use 59 | 60 | font_data: 61 | uint8_t data[data_size]; // glyph data 62 | 63 | data_extension_1: 64 | data_extension_2: 65 | ... 66 | data_extension_N: 67 | ... // reserved for future use 68 | }; 69 | \endcode 70 | 71 | */ 72 | -------------------------------------------------------------------------------- /doc/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /doc/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | libcaca documentation 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /doc/libcaca.dox: -------------------------------------------------------------------------------- 1 | /** \mainpage libcaca Documentation 2 | 3 | \section intro Introduction 4 | 5 | \e libcaca is a graphics library that outputs text instead of pixels, 6 | so that it can work on older video cards or text terminals. It is not 7 | unlike the famous AAlib library. \e libcaca can use almost any virtual 8 | terminal to work, thus it should work on all Unix systems (including 9 | Mac OS X) using either the S-Lang library or the ncurses library, on DOS 10 | using the conio library, and on Windows systems using the native Win32 11 | console, the conio library, or using S-Lang or ncurses (through Cygwin 12 | emulation). There is also a native X11 driver, and an OpenGL driver 13 | (through freeglut) that does not require a text terminal. For machines 14 | without a screen, the raw driver can be used to send the output to another 15 | machine, using for instance cacaserver. 16 | 17 | \e libcaca is free software, released under the Do What the Fuck You 18 | Want to Public License. This ensures that no one, not even the \e libcaca 19 | developers, will ever have anything to say about what you do with the 20 | software. It used to be licensed under the GNU Lesser General Public 21 | License, but that was not free enough. 22 | 23 | \section devel Developer's documentation 24 | 25 | The complete \e libcaca programming interface is 26 | available from the following header: 27 | 28 | - caca.h 29 | 30 | There is language-specific documentation for the various bindings: 31 | 32 | - \subpage libcaca-ruby 33 | 34 | Some other topics are covered by specific sections: 35 | 36 | - \subpage libcaca-tutorial 37 | - \subpage libcaca-migrating 38 | 39 | There is also information specially targeted at \e libcaca developers: 40 | 41 | - \subpage libcaca-font 42 | - \subpage libcaca-canvas 43 | - \subpage libcaca-style 44 | 45 | \section user User's documentation 46 | 47 | - \subpage libcaca-env 48 | 49 | \section misc Misc 50 | 51 | - \subpage libcaca-news 52 | - \subpage libcaca-authors 53 | - \subpage libcaca-thanks 54 | 55 | \section license License 56 | 57 | Permission is granted to copy, distribute and/or modify this document 58 | under the terms of the Do What the Fuck You Want to Public License, version 59 | 2 as published by Sam Hocevar. For details see http://www.wtfpl.net/ . 60 | 61 | */ 62 | -------------------------------------------------------------------------------- /doc/tutorial.dox: -------------------------------------------------------------------------------- 1 | /** \page libcaca-tutorial A libcaca tutorial 2 | 3 | First, a very simple working program, to check for basic libcaca 4 | functionalities. 5 | 6 | \code 7 | 8 | #include 9 | 10 | int main(void) 11 | { 12 | caca_canvas_t *cv; caca_display_t *dp; caca_event_t ev; 13 | 14 | dp = caca_create_display(NULL); 15 | if(!dp) return 1; 16 | cv = caca_get_canvas(dp); 17 | 18 | caca_set_display_title(dp, "Hello!"); 19 | caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE); 20 | caca_put_str(cv, 0, 0, "This is a message"); 21 | caca_refresh_display(dp); 22 | caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); 23 | caca_free_display(dp); 24 | 25 | return 0; 26 | } 27 | 28 | \endcode 29 | 30 | What does it do? 31 | - Create a display. Physically, the display is either a window or a context 32 | in a terminal (ncurses, slang) or even the whole screen (VGA). 33 | - Get the display's associated canvas. A canvas is the surface where 34 | everything happens: writing characters, sprites, strings, images... It is 35 | unavoidable. Here the size of the canvas is set by the display. 36 | - Set the display's window name (only available in windowed displays, does 37 | nothing otherwise). 38 | - Set the current canvas colours to black background and white foreground. 39 | - Write the string \c "This is a message" onto the canvas, using the current 40 | colour pair. 41 | - Refresh the display, causing the text to be effectively displayed. 42 | - Wait for an event of type \c CACA_EVENT_KEY_PRESS. 43 | - Free the display (release memory). Since it was created together with the 44 | display, the canvas will be automatically freed as well. 45 | 46 | You can then compile this code on an UNIX-like system using the following 47 | commans (requiring \c pkg-config and \c gcc): 48 | \code 49 | gcc `pkg-config --libs --cflags caca` example.c -o example 50 | \endcode 51 | 52 | */ 53 | -------------------------------------------------------------------------------- /doc/user.dox: -------------------------------------------------------------------------------- 1 | /** \page libcaca-env Libcaca environment variables 2 | 3 | Some environment variables can be used to change the behaviour of 4 | \e libcaca without having to modify the program which uses it. These 5 | variables are: 6 | 7 | \li \b CACA_DRIVER: set the backend video driver. In order of preference: 8 | - \c conio uses the DOS conio.h interface. 9 | - \c ncurses uses the ncurses library. 10 | - \c slang uses the S-Lang library. 11 | - \c x11 uses the native X11 driver. 12 | - \c gl uses freeglut and opengl libraries. 13 | - \c raw outputs to the standard output instead of rendering the 14 | canvas. This is can be used together with cacaserver. 15 | 16 | \li \b CACA_GEOMETRY: set the video display size. The format of this 17 | variable must be \c XxY, with \c X and \c Y being integer values. This 18 | option currently works with the raw, X11 and GL drivers. 19 | 20 | \li \b CACA_FONT: set the rendered font. The format of this variable is 21 | implementation dependent, but since it currently only works with the 22 | X11 driver, an X11 font name such as \c fixed or \c 5x7 is expected. 23 | 24 | */ 25 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | noinst_PROGRAMS = trifiller blit canvas colors conio $(conio_snake) demo demo0 dithering driver event export figfont font font2tga frames fullwidth gamma hsv input spritedit swallow text transform truecolor unicode import mouse 5 | 6 | if USE_CXX 7 | conio_snake = conio-snake 8 | endif 9 | 10 | trifiller_SOURCES = trifiller.c 11 | trifiller_CFLAGS = $(IMLIB2_CFLAGS) 12 | trifiller_LDFLAGS = $(IMLIB2_LIBS) 13 | trifiller_LDADD = ../caca/libcaca.la -lm 14 | 15 | blit_SOURCES = blit.c 16 | blit_LDADD = ../caca/libcaca.la 17 | 18 | canvas_SOURCES = canvas.c 19 | canvas_LDADD = ../caca/libcaca.la 20 | 21 | colors_SOURCES = colors.c 22 | colors_LDADD = ../caca/libcaca.la 23 | 24 | conio_SOURCES = conio.c 25 | conio_LDADD = ../caca/libcaca.la 26 | 27 | conio_snake_SOURCES = conio-snake.cpp 28 | conio_snake_LDADD = ../caca/libcaca.la 29 | 30 | demo_SOURCES = demo.c 31 | demo_LDADD = ../caca/libcaca.la 32 | demo_LDFLAGS = @MATH_LIBS@ 33 | 34 | demo0_SOURCES = demo0.c 35 | demo0_LDADD = ../caca/libcaca.la 36 | demo0_LDFLAGS = @MATH_LIBS@ 37 | 38 | dithering_SOURCES = dithering.c 39 | dithering_LDADD = ../caca/libcaca.la 40 | 41 | driver_SOURCES = driver.c 42 | driver_LDADD = ../caca/libcaca.la 43 | 44 | event_SOURCES = event.c 45 | event_LDADD = ../caca/libcaca.la 46 | 47 | export_SOURCES = export.c 48 | export_LDADD = ../caca/libcaca.la 49 | 50 | figfont_SOURCES = figfont.c 51 | figfont_LDADD = ../caca/libcaca.la 52 | 53 | font_SOURCES = font.c 54 | font_LDADD = ../caca/libcaca.la 55 | 56 | font2tga_SOURCES = font2tga.c 57 | font2tga_LDADD = ../caca/libcaca.la 58 | 59 | frames_SOURCES = frames.c 60 | frames_LDADD = ../caca/libcaca.la 61 | 62 | fullwidth_SOURCES = fullwidth.c 63 | fullwidth_LDADD = ../caca/libcaca.la 64 | 65 | gamma_SOURCES = gamma.c 66 | gamma_LDADD = ../caca/libcaca.la 67 | gamma_LDFLAGS = @MATH_LIBS@ 68 | 69 | hsv_SOURCES = hsv.c 70 | hsv_LDADD = ../caca/libcaca.la 71 | 72 | input_SOURCES = input.c 73 | input_LDADD = ../caca/libcaca.la 74 | 75 | spritedit_SOURCES = spritedit.c 76 | spritedit_LDADD = ../caca/libcaca.la 77 | 78 | swallow_SOURCES = swallow.c 79 | swallow_LDADD = ../caca/libcaca.la 80 | 81 | text_SOURCES = text.c 82 | text_LDADD = ../caca/libcaca.la 83 | 84 | transform_SOURCES = transform.c 85 | transform_LDADD = ../caca/libcaca.la 86 | 87 | truecolor_SOURCES = truecolor.c 88 | truecolor_LDADD = ../caca/libcaca.la 89 | 90 | unicode_SOURCES = unicode.c 91 | unicode_LDADD = ../caca/libcaca.la 92 | 93 | import_SOURCES = import.c 94 | import_LDADD = ../caca/libcaca.la 95 | 96 | mouse_SOURCES = mouse.c 97 | mouse_LDADD = ../caca/libcaca.la 98 | 99 | -------------------------------------------------------------------------------- /examples/blit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * blit libcaca blit test program 3 | * Copyright (c) 2006-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | # include 18 | #endif 19 | 20 | #include "caca.h" 21 | 22 | static char const pig[] = 23 | " ,__ __,\n" 24 | " \\)`\\_..._/`(/\n" 25 | " .' _ _ '.\n" 26 | " / o\\ /o \\\n" 27 | " | .-.-. | _\n" 28 | " | /() ()\\ | (,`)\n" 29 | " / \\ '-----' / \\ .'\n" 30 | "| '-..___..-' |\n" 31 | "| |\n" 32 | "| |\n" 33 | "; ;\n" 34 | " \\ / \\ /\n" 35 | " \\-..-/'-'\\-..-/\n" 36 | "jgs\\/\\/ \\/\\/\n"; 37 | 38 | int main(int argc, char *argv[]) 39 | { 40 | caca_canvas_t *cv, *sprite; 41 | caca_display_t *dp; 42 | 43 | cv = caca_create_canvas(80, 24); 44 | if(cv == NULL) 45 | { 46 | printf("Failed to create canvas\n"); 47 | return 1; 48 | } 49 | 50 | dp = caca_create_display(cv); 51 | if(dp == NULL) 52 | { 53 | printf("Failed to create display\n"); 54 | return 1; 55 | } 56 | 57 | sprite = caca_create_canvas(0, 0); 58 | caca_set_color_ansi(sprite, CACA_LIGHTRED, CACA_BLACK); 59 | caca_import_canvas_from_memory(sprite, pig, strlen(pig), "text"); 60 | caca_set_canvas_handle(sprite, caca_get_canvas_width(sprite) / 2, 61 | caca_get_canvas_height(sprite) / 2); 62 | 63 | caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE); 64 | caca_put_str(cv, 0, 0, "Centered sprite"); 65 | 66 | caca_blit(cv, caca_get_canvas_width(cv) / 2, 67 | caca_get_canvas_height(cv) / 2, sprite, NULL); 68 | 69 | caca_refresh_display(dp); 70 | 71 | caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); 72 | 73 | caca_free_display(dp); 74 | caca_free_canvas(sprite); 75 | caca_free_canvas(cv); 76 | 77 | return 0; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /examples/canvas.c: -------------------------------------------------------------------------------- 1 | /* 2 | * all full libcaca API test 3 | * Copyright (c) 2006-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | # include 18 | #endif 19 | 20 | #include "caca.h" 21 | 22 | #define ITER 128 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | caca_canvas_t *cv; 27 | unsigned int i, j, w, h; 28 | 29 | fprintf(stderr, "testing caca_create_canvas()\n"); 30 | for(i = 0; i < ITER; i++) 31 | { 32 | w = caca_rand(1, 1000); 33 | h = caca_rand(1, 1000); 34 | cv = caca_create_canvas(w, h); 35 | caca_put_char(cv, w - 1, h - 1, 'x'); 36 | if(caca_get_char(cv, w - 1, h - 1) != 'x') 37 | fprintf(stderr, " failed (%ux%u)\n", w, h); 38 | caca_free_canvas(cv); 39 | } 40 | 41 | fprintf(stderr, "testing caca_set_frame_name()\n"); 42 | cv = caca_create_canvas(1, 1); 43 | if(cv == NULL) 44 | { 45 | printf("Failed to create canvas\n"); 46 | return 1; 47 | } 48 | 49 | for(i = 0; i < ITER; i++) 50 | { 51 | caca_create_frame(cv, 0); 52 | for(j = 0; j < ITER; j++) 53 | { 54 | char buf[BUFSIZ]; 55 | w = caca_rand(1, BUFSIZ - 1); 56 | memset(buf, 'x', w); 57 | buf[w] = '\0'; 58 | caca_set_frame_name(cv, buf); 59 | } 60 | } 61 | caca_free_canvas(cv); 62 | 63 | fprintf(stderr, "all tests passed\n"); 64 | return 0; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /examples/colors.c: -------------------------------------------------------------------------------- 1 | /* 2 | * colors display all possible libcaca colour pairs 3 | * Copyright (c) 2003-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | #endif 18 | 19 | #include "caca.h" 20 | 21 | int main(int argc, char **argv) 22 | { 23 | caca_canvas_t *cv; 24 | caca_display_t *dp; 25 | int i, j; 26 | 27 | cv = caca_create_canvas(80, 24); 28 | if(cv == NULL) 29 | { 30 | printf("Failed to create canvas\n"); 31 | return 1; 32 | } 33 | 34 | dp = caca_create_display(cv); 35 | if(dp == NULL) 36 | { 37 | printf("Failed to create display\n"); 38 | return 1; 39 | } 40 | 41 | caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK); 42 | caca_clear_canvas(cv); 43 | for(i = 0; i < 16; i++) 44 | { 45 | caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK); 46 | caca_printf(cv, 3, i + (i >= 8 ? 3 : 2), "ANSI %i", i); 47 | for(j = 0; j < 16; j++) 48 | { 49 | caca_set_color_ansi(cv, i, j); 50 | caca_put_str(cv, (j >= 8 ? 13 : 12) + j * 4, i + (i >= 8 ? 3 : 2), 51 | "Aaホ"); 52 | } 53 | } 54 | 55 | caca_set_color_ansi(cv, CACA_LIGHTGRAY, CACA_BLACK); 56 | caca_put_str(cv, 3, 20, "This is bold This is blink This is italics This is underline"); 57 | caca_set_attr(cv, CACA_BOLD); 58 | caca_put_str(cv, 3 + 8, 20, "bold"); 59 | caca_set_attr(cv, CACA_BLINK); 60 | caca_put_str(cv, 3 + 24, 20, "blink"); 61 | caca_set_attr(cv, CACA_ITALICS); 62 | caca_put_str(cv, 3 + 41, 20, "italics"); 63 | caca_set_attr(cv, CACA_UNDERLINE); 64 | caca_put_str(cv, 3 + 60, 20, "underline"); 65 | 66 | caca_refresh_display(dp); 67 | caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); 68 | 69 | caca_free_display(dp); 70 | caca_free_canvas(cv); 71 | 72 | return 0; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /examples/driver.c: -------------------------------------------------------------------------------- 1 | /* 2 | * driver libcaca Unicode rendering test program 3 | * Copyright (c) 2007-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | # include 18 | #endif 19 | 20 | #include "caca.h" 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | char const * const *list; 25 | caca_display_t *dp; 26 | caca_canvas_t *cv; 27 | 28 | list = caca_get_display_driver_list(); 29 | 30 | dp = caca_create_display(NULL); 31 | if(dp == NULL) 32 | { 33 | printf("cannot create display\n"); 34 | return -1; 35 | } 36 | 37 | cv = caca_get_canvas(dp); 38 | caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK); 39 | 40 | while(1) 41 | { 42 | char const *driver; 43 | int i, cur = 0; 44 | 45 | caca_put_str(cv, 1, 0, "Available drivers:"); 46 | 47 | driver = caca_get_display_driver(dp); 48 | 49 | for(i = 0; list[i]; i += 2) 50 | { 51 | int match = !strcmp(list[i], driver); 52 | 53 | if(match) 54 | cur = i; 55 | caca_draw_line(cv, 0, i + 2, 9999, i + 2, ' '); 56 | caca_printf(cv, 2, i + 2, "%c %s (%s)", 57 | match ? '*' : ' ', list[i], list[i + 1]); 58 | } 59 | 60 | caca_put_str(cv, 1, i + 2, "Switching driver in 5 seconds"); 61 | 62 | caca_refresh_display(dp); 63 | 64 | if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 5000000)) 65 | break; 66 | 67 | do 68 | { 69 | cur += 2; 70 | if(list[cur] && !strcmp(list[cur], "raw")) 71 | cur += 2; 72 | if(!list[cur]) 73 | cur = 0; 74 | } 75 | while(caca_set_display_driver(dp, list[cur])); 76 | } 77 | 78 | caca_free_display(dp); 79 | 80 | return 0; 81 | } 82 | 83 | -------------------------------------------------------------------------------- /examples/figfont.c: -------------------------------------------------------------------------------- 1 | /* 2 | * figfont libcaca FIGfont test program 3 | * Copyright (c) 2007-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | # include 18 | #endif 19 | 20 | #include "caca.h" 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | caca_canvas_t *cv; 25 | void *buffer; 26 | size_t len; 27 | uint8_t color = 0; 28 | 29 | if(argc < 3) 30 | { 31 | fprintf(stderr, "Too few arguments\n"); 32 | return -1; 33 | } 34 | 35 | cv = caca_create_canvas(0, 0); 36 | if(caca_canvas_set_figfont(cv, argv[1])) 37 | { 38 | fprintf(stderr, "Could not open font\n"); 39 | return -1; 40 | } 41 | 42 | while(argv[2][0]) 43 | { 44 | caca_set_color_ansi(cv, 1 + ((color += 4) % 15), CACA_TRANSPARENT); 45 | caca_put_figchar(cv, argv[2]++[0]); 46 | } 47 | 48 | buffer = caca_export_canvas_to_memory(cv, "utf8", &len); 49 | fwrite(buffer, len, 1, stdout); 50 | free(buffer); 51 | 52 | caca_free_canvas(cv); 53 | 54 | return 0; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /examples/font2tga.c: -------------------------------------------------------------------------------- 1 | /* 2 | * font2tga libcaca font test program 3 | * Copyright (c) 2006-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | # include 18 | #endif 19 | 20 | #include "caca.h" 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | uint32_t const *blocks; 25 | caca_font_t *f; 26 | char const * const * fonts; 27 | caca_canvas_t *cv; 28 | void *buffer; 29 | size_t len; 30 | unsigned int i, j, x, y, cells, width; 31 | 32 | fonts = caca_get_font_list(); 33 | f = caca_load_font(fonts[0], 0); 34 | blocks = caca_get_font_blocks(f); 35 | 36 | for(i = 0, cells = 0; blocks[i + 1]; i += 2) 37 | { 38 | cells += blocks[i + 1] - blocks[i]; 39 | for(j = blocks[i]; j < blocks[i + 1]; j++) 40 | if(caca_utf32_is_fullwidth(j)) 41 | cells++; 42 | } 43 | 44 | for(width = 64; width * width < cells; width *= 2) 45 | ; 46 | 47 | /* Create a canvas */ 48 | cv = caca_create_canvas(width, (cells + width - 1) / (width - 1)); 49 | caca_set_color_ansi(cv, CACA_RED, CACA_RED); 50 | caca_clear_canvas(cv); 51 | caca_set_color_ansi(cv, CACA_BLACK, CACA_WHITE); 52 | 53 | /* Put all glyphs on the canvas */ 54 | x = y = 0; 55 | 56 | for(i = 0; blocks[i + 1]; i += 2) 57 | { 58 | for(j = blocks[i]; j < blocks[i + 1]; j++) 59 | { 60 | caca_put_char(cv, x, y, j); 61 | 62 | if(caca_utf32_is_fullwidth(j)) 63 | ++x; 64 | 65 | if(++x >= width - 1) 66 | { 67 | x = 0; 68 | y++; 69 | } 70 | } 71 | } 72 | 73 | caca_free_font(f); 74 | 75 | buffer = caca_export_canvas_to_memory(cv, "tga", &len); 76 | fwrite(buffer, len, 1, stdout); 77 | free(buffer); 78 | 79 | /* Free everything */ 80 | caca_free_canvas(cv); 81 | 82 | return 0; 83 | } 84 | 85 | -------------------------------------------------------------------------------- /examples/fullwidth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * fullwidth libcaca fullwidth Unicode characters test program 3 | * Copyright (c) 2006-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | #endif 18 | 19 | #include "caca.h" 20 | 21 | #define CACA "쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊" 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | caca_canvas_t *cv, *caca, *line; 26 | caca_display_t *dp; 27 | 28 | unsigned int i; 29 | 30 | cv = caca_create_canvas(0, 0); 31 | if(cv == NULL) 32 | { 33 | printf("Can't created canvas\n"); 34 | return -1; 35 | } 36 | dp = caca_create_display(cv); 37 | if(dp == NULL) 38 | { 39 | printf("Can't create display\n"); 40 | return -1; 41 | } 42 | 43 | caca = caca_create_canvas(6, 10); 44 | line = caca_create_canvas(2, 1); 45 | 46 | /* Line of x's */ 47 | for(i = 0; i < 10; i++) 48 | { 49 | caca_set_color_ansi(caca, CACA_WHITE, CACA_BLUE); 50 | caca_put_str(caca, 0, i, CACA); 51 | caca_set_color_ansi(caca, CACA_WHITE, CACA_RED); 52 | caca_put_char(caca, i - 2, i, 'x'); 53 | } 54 | 55 | caca_blit(cv, 1, 1, caca, NULL); 56 | 57 | /* Line of ホ's */ 58 | for(i = 0; i < 10; i++) 59 | { 60 | caca_set_color_ansi(caca, CACA_WHITE, CACA_BLUE); 61 | caca_put_str(caca, 0, i, CACA); 62 | caca_set_color_ansi(caca, CACA_WHITE, CACA_GREEN); 63 | caca_put_str(caca, i - 2, i, "ホ"); 64 | } 65 | 66 | caca_blit(cv, 15, 1, caca, NULL); 67 | 68 | /* Line of canvas */ 69 | caca_set_color_ansi(line, CACA_WHITE, CACA_MAGENTA); 70 | caca_put_str(line, 0, 0, "ほ"); 71 | for(i = 0; i < 10; i++) 72 | { 73 | caca_set_color_ansi(caca, CACA_WHITE, CACA_BLUE); 74 | caca_put_str(caca, 0, i, CACA); 75 | caca_blit(caca, i - 2, i, line, NULL); 76 | } 77 | 78 | caca_blit(cv, 29, 1, caca, NULL); 79 | 80 | caca_refresh_display(dp); 81 | 82 | caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); 83 | 84 | caca_free_display(dp); 85 | 86 | caca_free_canvas(line); 87 | caca_free_canvas(caca); 88 | caca_free_canvas(cv); 89 | 90 | return 0; 91 | } 92 | 93 | -------------------------------------------------------------------------------- /examples/hsv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * hsv libcaca HSV rendering test program 3 | * Copyright (c) 2003-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | #endif 18 | 19 | #include "caca.h" 20 | 21 | uint32_t buffer[256*256]; 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | caca_display_t *dp; 26 | caca_canvas_t *cv; 27 | 28 | caca_dither_t *dither; 29 | int x, y; 30 | 31 | dp = caca_create_display(NULL); 32 | if(dp == NULL) 33 | { 34 | printf("Can't create display\n"); 35 | return -1; 36 | } 37 | 38 | cv = caca_get_canvas(dp); 39 | 40 | for(y = 0; y < 256; y++) 41 | for(x = 0; x < 256; x++) 42 | { 43 | buffer[y * 256 + x] = ((y * x / 256) << 16) | ((y * x / 256) << 8) | (x<< 0); 44 | } 45 | 46 | dither = caca_create_dither(32, 256, 256, 4 * 256, 47 | 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 48 | caca_dither_bitmap(caca_get_canvas(dp), 0, 0, caca_get_canvas_width(cv), 49 | caca_get_canvas_height(cv), dither, buffer); 50 | caca_free_dither(dither); 51 | 52 | caca_refresh_display(dp); 53 | 54 | caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); 55 | 56 | caca_free_display(dp); 57 | 58 | return 0; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /examples/import.c: -------------------------------------------------------------------------------- 1 | /* 2 | * import libcaca importers test program 3 | * Copyright (c) 2006-2012 Jean-Yves Lamoureux 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | # include 18 | #endif 19 | 20 | #include "caca.h" 21 | 22 | int main(int argc, char *argv[]) 23 | { 24 | caca_canvas_t *cv; 25 | caca_display_t *dp; 26 | 27 | if(argc < 2) 28 | { 29 | fprintf(stderr, "%s: missing argument (filename).\n", argv[0]); 30 | fprintf(stderr, "usage: %s []\n", argv[0]); 31 | return 1; 32 | } 33 | 34 | cv = caca_create_canvas(0, 0); 35 | if(cv == NULL) 36 | { 37 | printf("Can't create canvas\n"); 38 | return -1; 39 | } 40 | 41 | if(caca_import_canvas_from_file(cv, argv[1], argc >= 3 ? argv[2] : "") < 0) 42 | { 43 | fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]); 44 | caca_free_canvas(cv); 45 | return 1; 46 | } 47 | 48 | dp = caca_create_display(cv); 49 | if(dp == NULL) 50 | { 51 | printf("Can't create display\n"); 52 | return -1; 53 | } 54 | 55 | caca_refresh_display(dp); 56 | 57 | caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); 58 | 59 | caca_free_display(dp); 60 | caca_free_canvas(cv); 61 | 62 | return 0; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /examples/spritedit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * spritedit sprite editor for libcaca 3 | * Copyright (c) 2003-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | # include 18 | # include 19 | #endif 20 | 21 | #include "caca.h" 22 | 23 | /* Courtesy of Zashi */ 24 | char *guy[] = { 25 | " O_,= \n" 26 | " | \n" 27 | " /\\ \n" 28 | " / / \n", 29 | 30 | " O_,= \n" 31 | " | \n" 32 | " /| \n" 33 | " / | \n", 34 | 35 | " O_,= \n" 36 | " | \n" 37 | " |\\ \n" 38 | " |/ \n", 39 | 40 | " O_,= \n" 41 | " | \n" 42 | " |\\ \n" 43 | " | \\ \n", 44 | }; 45 | 46 | int main(int argc, char **argv) 47 | { 48 | caca_canvas_t *sprite; 49 | size_t len; 50 | void *buffer; 51 | int i; 52 | 53 | /* Create a canvas with 4 frames */ 54 | sprite = caca_create_canvas(0, 0); 55 | for(i = 0; i < 3; i++) 56 | caca_create_frame(sprite, 0); 57 | 58 | /* Load stuff in all 4 frames */ 59 | for(i = 0; i < 4; i++) 60 | { 61 | caca_set_frame(sprite, i); 62 | caca_import_canvas_from_memory(sprite, guy[i], strlen(guy[i]), "utf8"); 63 | } 64 | 65 | /* Export our sprite in a memory buffer. We could save this to 66 | * disk afterwards. */ 67 | buffer = caca_export_canvas_to_memory(sprite, "caca", &len); 68 | 69 | /* Free our sprite and reload it from the memory buffer. We could 70 | * load this from disk, too. */ 71 | caca_free_canvas(sprite); 72 | sprite = caca_create_canvas(0, 0); 73 | caca_import_canvas_from_memory(sprite, buffer, len, "caca"); 74 | free(buffer); 75 | 76 | /* Print each sprite frame to stdout */ 77 | for(i = 0; i < 4; i++) 78 | { 79 | caca_set_frame(sprite, i); 80 | printf("Frame #%i\n", i); 81 | buffer = caca_export_canvas_to_memory(sprite, "utf8", &len); 82 | fwrite(buffer, len, 1, stdout); 83 | free(buffer); 84 | } 85 | 86 | /* Free our sprite */ 87 | caca_free_canvas(sprite); 88 | 89 | return 0; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /examples/truecolor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * truecolor truecolor canvas features 3 | * Copyright (c) 2006-2012 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include "config.h" 14 | 15 | #if !defined(__KERNEL__) 16 | # include 17 | #endif 18 | 19 | #include "caca.h" 20 | 21 | int main(int argc, char *argv[]) 22 | { 23 | caca_canvas_t *cv; 24 | caca_display_t *dp; 25 | 26 | int x, y; 27 | 28 | cv = caca_create_canvas(32, 16); 29 | if(cv == NULL) 30 | { 31 | printf("Failed to create canvas\n"); 32 | return 1; 33 | } 34 | 35 | dp = caca_create_display(cv); 36 | if(dp == NULL) 37 | { 38 | printf("Failed to create display\n"); 39 | return 1; 40 | } 41 | 42 | for(y = 0; y < 16; y++) 43 | for(x = 0; x < 16; x++) 44 | { 45 | uint16_t bgcolor = 0xff00 | (y << 4) | x; 46 | uint16_t fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8); 47 | 48 | caca_set_color_argb(cv, fgcolor, bgcolor); 49 | caca_put_str(cv, x * 2, y, "CA"); 50 | } 51 | 52 | caca_set_color_ansi(cv, CACA_WHITE, CACA_LIGHTBLUE); 53 | caca_put_str(cv, 2, 1, " truecolor libcaca "); 54 | 55 | caca_refresh_display(dp); 56 | 57 | caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, -1); 58 | 59 | caca_free_display(dp); 60 | caca_free_canvas(cv); 61 | 62 | return 0; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /java/.gitignore: -------------------------------------------------------------------------------- 1 | libjava.jar 2 | examples/*.class 3 | org_zoy_caca_*.h 4 | org/zoy/caca/*.class 5 | -------------------------------------------------------------------------------- /java/README: -------------------------------------------------------------------------------- 1 | 2 | Building the libcaca Java bindings 3 | 4 | o In the configure step, ensure the --enable-java flag is turned on. 5 | 6 | o `make install` will install: 7 | - libjava.so in ${libdir}/jni, 8 | - libjava.jar in ${datadir}/java. 9 | 10 | 11 | Using the libcaca Java bindings 12 | 13 | o Look into examples/ for source code examples. 14 | 15 | o Running an application which uses the libcaca Java bindings: 16 | 17 | java -Djava.library.path=${libdir}/jni \ 18 | -cp ${datadir}/java/libjava.jar: 19 | 20 | -------------------------------------------------------------------------------- /java/caca_java_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | #include "caca_java_common.h" 13 | 14 | jobjectArray caca_java_to_string_array(JNIEnv *env, const char *const *v) 15 | { 16 | jclass java_lang_string = (*env)->FindClass(env, "java/lang/String"); 17 | jsize size; 18 | jsize i; 19 | 20 | for (size = 0; v[size]; ++size); 21 | 22 | jobjectArray ret = (*env)->NewObjectArray(env, size, java_lang_string, NULL); 23 | for (i = 0; i < size; ++i) 24 | { 25 | (*env)->SetObjectArrayElement(env, ret, i, (*env)->NewStringUTF(env, v[i])); 26 | } 27 | return ret; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /java/caca_java_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | #ifndef __CACA_JAVA_COMMON_H__ 13 | #define __CACA_JAVA_COMMON_H__ 14 | 15 | #include 16 | 17 | #define THROW_EX(msg) (*env)->ThrowNew(env, (*env)->FindClass(env, "org/zoy/caca/CacaException"), msg) 18 | 19 | jobjectArray caca_java_to_string_array(JNIEnv *env, const char *const *v); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /java/examples/Driver: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | DIR="`dirname $0`" 4 | java -Djava.library.path="${DIR}/../.libs" \ 5 | -cp "${DIR}/../libjava.jar:${DIR}" Driver 6 | 7 | -------------------------------------------------------------------------------- /java/examples/Driver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | import org.zoy.caca.Canvas; 13 | import org.zoy.caca.Color; 14 | import org.zoy.caca.Display; 15 | import org.zoy.caca.Event; 16 | import org.zoy.caca.TimeoutException; 17 | 18 | public class Driver { 19 | 20 | public static void main(String[] args) { 21 | Canvas cv = new Canvas(32, 16); 22 | Display dp = new Display(cv); 23 | cv.setColor(Color.Ansi.WHITE, Color.Ansi.BLACK); 24 | Display.Driver driver; 25 | int i, cur = 0; 26 | while(true) { 27 | cv.put(1, 0, "Available drivers"); 28 | driver = dp.getDriver(); 29 | Display.Driver[] list = Display.getDriverList(); 30 | for (i = 0; i < list.length; i++) { 31 | if (driver.equals(list[i])) { 32 | cur = i; 33 | } 34 | cv.drawLine(0, 2*i+2, 9999, 2*i+2, ' '); 35 | cv.put(2, 2*i+2, (cur == i ? "* " : " ") + list[i].getCode() + " " + list[i].getDescription()); 36 | } 37 | cv.put(1, 2*i + 2, "Switching driver in 5 seconds"); 38 | dp.refresh(); 39 | try { 40 | dp.getEvent(Event.Type.KEY_PRESS, 5000000); 41 | break; 42 | } catch(TimeoutException e) { 43 | // Let's continue 44 | } 45 | cur++; 46 | if (list[cur].getCode().equals("raw")) cur++; 47 | if (cur >= list.length) cur = 0; 48 | dp.setDriver(list[cur]); 49 | } 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /java/examples/TrueColor: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | DIR="`dirname $0`" 4 | java -Djava.library.path="${DIR}/../.libs" \ 5 | -cp "${DIR}/../libjava.jar:${DIR}" TrueColor 6 | 7 | -------------------------------------------------------------------------------- /java/examples/TrueColor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | import org.zoy.caca.Canvas; 13 | import org.zoy.caca.Color; 14 | import org.zoy.caca.Display; 15 | import org.zoy.caca.Event; 16 | 17 | public class TrueColor { 18 | 19 | public static void main(String[] args) { 20 | Canvas cv = new Canvas(32, 16); 21 | Display dp = new Display(cv); 22 | for (int y = 0; y < 16; y++) { 23 | for (int x = 0; x < 16; x++) { 24 | int bgcolor = 0xff00 | (y << 4) | x; 25 | int fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8); 26 | cv.setColor(new Color.Argb(bgcolor), new Color.Argb(fgcolor)); 27 | cv.put(x*2, y, "CA"); 28 | } 29 | } 30 | cv.setColor(Color.Ansi.WHITE, Color.Ansi.LIGHTBLUE); 31 | cv.put(2, 1, "truecolor libcaca"); 32 | dp.refresh(); 33 | dp.getEvent(Event.Type.KEY_PRESS, -1); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /java/org/zoy/caca/Attribute.java: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | package org.zoy.caca; 13 | 14 | public class Attribute { 15 | 16 | static { 17 | Caca.load(); 18 | } 19 | 20 | private Attribute() {} 21 | 22 | private static final native byte attributeToAnsi(int attr); 23 | 24 | public static byte toAnsi(int attr) { 25 | return attributeToAnsi(attr); 26 | } 27 | 28 | private static native byte attributeToAnsiForeground(int attr); 29 | 30 | public byte toAnsiForeground(int attr) { 31 | return attributeToAnsiForeground(attr); 32 | } 33 | 34 | private static native byte attributeToAnsiBackground(int attr); 35 | 36 | public byte toAnsiBackground(int attr) { 37 | return attributeToAnsiBackground(attr); 38 | } 39 | 40 | private static native short attributeToRgb12Foreground(int attr); 41 | 42 | public static short toRgb12Foreground(int attr) { 43 | return attributeToRgb12Foreground(attr); 44 | } 45 | 46 | private static native short attributeToRgb12Background(int attr); 47 | 48 | public static short toRgb12Background(int attr) { 49 | return attributeToRgb12Background(attr); 50 | } 51 | 52 | private static native byte[] attributeToArgb64(int attr); 53 | 54 | public static byte[] toArgb64(int attr) { 55 | return attributeToArgb64(attr); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /java/org/zoy/caca/Caca.java: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | package org.zoy.caca; 13 | 14 | public class Caca { 15 | 16 | static { 17 | load(); 18 | } 19 | 20 | private static boolean alreadyLoaded = false; 21 | 22 | synchronized public static void load() { 23 | if (!alreadyLoaded) { 24 | System.loadLibrary("caca-java"); 25 | alreadyLoaded = true; 26 | } 27 | } 28 | 29 | public static native String getVersion(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /java/org/zoy/caca/CacaException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | package org.zoy.caca; 13 | 14 | public class CacaException extends RuntimeException { 15 | 16 | private static final long serialVersionUID = 0L; 17 | 18 | public CacaException(String msg) { 19 | super(msg); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /java/org/zoy/caca/CacaObject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | package org.zoy.caca; 13 | 14 | public abstract class CacaObject { 15 | 16 | protected String code; 17 | protected String description; 18 | public CacaObject(String code, String desc) { 19 | this.code = code; 20 | this.description = desc; 21 | } 22 | public String getCode() { 23 | return code; 24 | } 25 | public String getDescription() { 26 | return description; 27 | } 28 | @Override 29 | public boolean equals(Object o) { 30 | if (o == null) return false; 31 | if (this.getClass().equals(o.getClass())) { 32 | CacaObject other = (CacaObject)o; 33 | return this.code.equals(other.code); 34 | } 35 | return false; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /java/org/zoy/caca/Font.java: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | package org.zoy.caca; 13 | 14 | public class Font extends NativeObject { 15 | 16 | static { 17 | Caca.load(); 18 | } 19 | 20 | private static native long loadFont(String fontName); 21 | private static native long loadFont(byte[] fontBytes); 22 | 23 | public Font(String fontName) { 24 | ptr = loadFont(fontName); 25 | } 26 | 27 | public Font(byte[] fontBytes) { 28 | ptr = loadFont(fontBytes); 29 | } 30 | 31 | public static native String[] getFontNames(); 32 | 33 | private static native int getFontWidth(long fontPtr); 34 | 35 | public int getWidth() { 36 | return getFontWidth(ptr); 37 | } 38 | 39 | private static native int getFontHeight(long fontPtr); 40 | 41 | public int getHeight() { 42 | return getFontHeight(ptr); 43 | } 44 | 45 | private static native int[][] getFontBlocks(long fontPtr); 46 | 47 | public int[][] getBlocks() { 48 | return getFontBlocks(ptr); 49 | } 50 | 51 | private static native void freeFont(long fontPtr); 52 | 53 | @Override 54 | public void finalize() throws Throwable { 55 | freeFont(ptr); 56 | super.finalize(); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /java/org/zoy/caca/NativeObject.java: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | package org.zoy.caca; 13 | 14 | public abstract class NativeObject { 15 | 16 | protected long ptr; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /java/org/zoy/caca/TimeoutException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | package org.zoy.caca; 13 | 14 | public class TimeoutException extends RuntimeException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | public TimeoutException(String msg) { 19 | super(msg); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /java/org_zoy_caca_Attribute.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | #include "org_zoy_caca_Attribute.h" 13 | 14 | #include "caca.h" 15 | 16 | 17 | JNIEXPORT jbyte JNICALL 18 | Java_org_zoy_caca_Attribute_attributeToAnsi(JNIEnv *env, jclass cls, jint attr) 19 | { 20 | return caca_attr_to_ansi(attr); 21 | } 22 | 23 | JNIEXPORT jbyte JNICALL 24 | Java_org_zoy_caca_Attribute_attributeToAnsiForeground(JNIEnv *env, jclass cls, jint attr) 25 | { 26 | return caca_attr_to_ansi_fg(attr); 27 | } 28 | 29 | JNIEXPORT jbyte JNICALL 30 | Java_org_zoy_caca_Attribute_attributeToAnsiBackground(JNIEnv *env, jclass cls, jint attr) 31 | { 32 | return caca_attr_to_ansi_bg(attr); 33 | } 34 | 35 | JNIEXPORT jshort JNICALL 36 | Java_org_zoy_caca_Attribute_attributeToRgb12Foreground(JNIEnv *env, jclass cls, jint attr) 37 | { 38 | return caca_attr_to_rgb12_fg(attr); 39 | } 40 | 41 | JNIEXPORT jshort JNICALL 42 | Java_org_zoy_caca_Attribute_attributeToRgb12Background(JNIEnv *env, jclass cls, jint attr) 43 | { 44 | return caca_attr_to_rgb12_bg(attr); 45 | } 46 | 47 | JNIEXPORT jbyteArray JNICALL 48 | Java_org_zoy_caca_Attribute_attributeToArgb64(JNIEnv *env, jclass cls, jint attr) 49 | { 50 | jbyteArray ret; 51 | jbyte *elems; 52 | 53 | ret = (*env)->NewByteArray(env, 8); 54 | elems = (*env)->GetByteArrayElements(env, ret, 0); 55 | caca_attr_to_argb64(attr, elems); 56 | (*env)->ReleaseByteArrayElements(env, ret, elems, 0); 57 | 58 | return ret; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /java/org_zoy_caca_Caca.c: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | #include "org_zoy_caca_Caca.h" 13 | 14 | #include "caca.h" 15 | 16 | 17 | JNIEXPORT jstring JNICALL 18 | Java_org_zoy_caca_Caca_getVersion(JNIEnv *env, jclass cls) 19 | { 20 | const char *version = caca_get_version(); 21 | return (*env)->NewStringUTF(env, version); 22 | } 23 | -------------------------------------------------------------------------------- /java/org_zoy_caca_Event.c: -------------------------------------------------------------------------------- 1 | /** 2 | * libcaca Java bindings for libcaca 3 | * Copyright (c) 2009 Adrien Grand 4 | * 5 | * This library is free software. It comes without any warranty, to 6 | * the extent permitted by applicable law. You can redistribute it 7 | * and/or modify it under the terms of the Do What the Fuck You Want 8 | * to Public License, Version 2, as published by Sam Hocevar. See 9 | * http://www.wtfpl.net/ for more details. 10 | */ 11 | 12 | #include "org_zoy_caca_Event.h" 13 | 14 | #include 15 | #include "caca.h" 16 | 17 | JNIEXPORT jint JNICALL 18 | Java_org_zoy_caca_Event_getEventType(JNIEnv *env, jclass cls, jlong ptr) 19 | { 20 | return (jint)caca_get_event_type((caca_event_t *)ptr); 21 | } 22 | 23 | JNIEXPORT jint JNICALL 24 | Java_org_zoy_caca_Event_getEventKeyCh(JNIEnv *env, jclass cls, jlong ptr) 25 | { 26 | return caca_get_event_key_ch((caca_event_t *)ptr); 27 | } 28 | 29 | JNIEXPORT jint JNICALL 30 | Java_org_zoy_caca_Event_getEventKeyUtf32(JNIEnv *env, jclass cls, jlong ptr) 31 | { 32 | return caca_get_event_key_utf32((caca_event_t *)ptr); 33 | } 34 | 35 | JNIEXPORT jstring JNICALL 36 | Java_org_zoy_caca_Event_getEventKeyUtf8(JNIEnv *env, jclass cls, jlong ptr) 37 | { 38 | char *str = malloc(8 * sizeof(char)); 39 | caca_get_event_key_utf8((caca_event_t *)ptr, str); 40 | return (*env)->NewStringUTF(env, str); 41 | } 42 | 43 | JNIEXPORT jint JNICALL 44 | Java_org_zoy_caca_Event_getEventMouseButton(JNIEnv *env, jclass cls, jlong ptr) 45 | { 46 | return caca_get_event_mouse_button((caca_event_t *)ptr); 47 | } 48 | 49 | JNIEXPORT jint JNICALL 50 | Java_org_zoy_caca_Event_getEventMouseX(JNIEnv *env, jclass cls, jlong ptr) 51 | { 52 | return caca_get_event_mouse_x((caca_event_t *)ptr); 53 | } 54 | 55 | JNIEXPORT jint JNICALL 56 | Java_org_zoy_caca_Event_getEventMouseY(JNIEnv *env, jclass cls, jlong ptr) 57 | { 58 | return caca_get_event_mouse_y((caca_event_t *)ptr); 59 | } 60 | 61 | JNIEXPORT jint JNICALL 62 | Java_org_zoy_caca_Event_getEventResizeWidth(JNIEnv *env, jclass cls, jlong ptr) 63 | { 64 | return caca_get_event_resize_width((caca_event_t *)ptr); 65 | } 66 | 67 | JNIEXPORT jint JNICALL 68 | Java_org_zoy_caca_Event_getEventResizeHeight(JNIEnv *env, jclass cls, jlong ptr) 69 | { 70 | return caca_get_event_resize_height((caca_event_t *)ptr); 71 | } 72 | 73 | JNIEXPORT void JNICALL 74 | Java_org_zoy_caca_Event_freeEvent(JNIEnv *env, jclass cls, jlong ptr) 75 | { 76 | caca_event_t *ev = (caca_event_t *)ptr; 77 | free(ev); 78 | } 79 | -------------------------------------------------------------------------------- /kernel/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | EXTRA_DIST = bootsect.S 5 | 6 | lib_LTLIBRARIES = $(libkernel_la) 7 | 8 | if USE_KERNEL 9 | libkernel_la = libkernel.la 10 | endif 11 | 12 | libkernel_la_SOURCES = \ 13 | kernel.c \ 14 | kernel.h \ 15 | multiboot.h \ 16 | $(NULL) 17 | libkernel_la_LDFLAGS = -no-undefined 18 | 19 | clean: clean-local 20 | clean-local: 21 | rm -f bootsect.bin kern.bin kernel.map 22 | 23 | -------------------------------------------------------------------------------- /kernel/boot/pic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006 Sam Hocevar 4 | * 2009 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | 15 | #include "klibc.h" 16 | 17 | #define PIC_MASTER_ICW1 0x20 18 | #define PIC_MASTER_ICW2 0x21 19 | 20 | #define PIC_SLAVE_ICW1 0xA0 21 | #define PIC_SLAVE_ICW2 0xA1 22 | 23 | 24 | void init_pic(void) 25 | { 26 | /* MASTER */ 27 | outbp(PIC_MASTER_ICW1, 0x11); // Init 8259A-1 28 | /* ICW2 - start vector = 32 */ 29 | outbp(PIC_MASTER_ICW2, 0x20); // IRQ 0-7 mapped to 0x20-0x27 30 | /* IICW3 */ 31 | outbp(PIC_MASTER_ICW2, 0x04); // 8259A-1 has slave 32 | /* ICW4 */ 33 | outbp(PIC_MASTER_ICW2, 0x01); 34 | /* Int mask */ 35 | outbp(PIC_MASTER_ICW2, 0xFF); 36 | 37 | /* SLAVE */ 38 | outbp(PIC_SLAVE_ICW1, 0x11); 39 | /* ICW2 - start vector = 96 */ 40 | outbp(PIC_SLAVE_ICW2, 0x70); 41 | /* ICW3 */ 42 | outbp(PIC_SLAVE_ICW2, 0x02); 43 | /* ICW4 */ 44 | outbp(PIC_SLAVE_ICW2, 0x01); 45 | /* Int Mask */ 46 | outbp(PIC_SLAVE_ICW2, 0xFF); 47 | 48 | 49 | /* Unmask irqs */ 50 | outbp(0x21, 0xFD); 51 | 52 | } 53 | 54 | static unsigned int cached_irq_mask = 0xffff; 55 | 56 | #define __byte(x,y) (((unsigned char *)&(y))[x]) 57 | #define cached_21 (__byte(0,cached_irq_mask)) 58 | #define cached_A1 (__byte(1,cached_irq_mask)) 59 | 60 | void disable_interrupt(char irq) 61 | { 62 | unsigned int mask = 1 << irq; 63 | 64 | cached_irq_mask |= mask; 65 | if (irq & 8) 66 | { 67 | outb(0xA1, cached_A1); 68 | } 69 | else 70 | { 71 | outb(0x21, cached_21); 72 | } 73 | } 74 | 75 | void enable_interrupt(char irq) 76 | { 77 | unsigned int mask = ~(1 << irq); 78 | 79 | cached_irq_mask &= mask; 80 | if (irq & 8) 81 | { 82 | outb(0xA1, cached_A1); 83 | } 84 | else 85 | { 86 | outb(0x21, cached_21); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /kernel/boot/stage2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006 Sam Hocevar 4 | * 2009 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | #include "kernel.h" 15 | #include "klibc.h" 16 | 17 | extern int kmain(void); 18 | 19 | 20 | /* Entry point bootsect.asm loaded this file at 0x0100:0x0, which is mapped 21 | at 0x8:0x1000 (selector+8bytes, offset 1000 (0x100 + 0x0) */ 22 | 23 | /* 0x1000 */ 24 | void _start(void) 25 | { 26 | clearscreen(); 27 | 28 | init_gdt(); 29 | print("Loading IDT\n"); 30 | init_idt(); 31 | print("Loading PIC\n"); 32 | init_pic(); 33 | print("Running kmain()\n"); 34 | sti; 35 | 36 | kmain(); /* Call kernel's kmain() */ 37 | 38 | while (1) 39 | { /* Never return */ 40 | print("hlt;\n"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /kernel/boot/stage2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006 Sam Hocevar 4 | * 2009 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | 15 | 16 | extern int _start(void); 17 | -------------------------------------------------------------------------------- /kernel/bootsect.S: -------------------------------------------------------------------------------- 1 | /* 2 | * bootsect.S Copyright (C) 1991, 1992 Linus Torvalds 3 | * 4 | * modified by Drew Eckhardt 5 | * modified by Bruce Evans (bde) 6 | * modified by Chris Noe (May 1999) (as86 -> gas) 7 | * gutted by H. Peter Anvin (Jan 2003) 8 | * 9 | * BIG FAT NOTE: We're in real mode using 64k segments. Therefore segment 10 | * addresses must be multiplied by 16 to obtain their respective linear 11 | * addresses. To avoid confusion, linear addresses are written using leading 12 | * hex while segment addresses are written as segment:offset. 13 | * 14 | */ 15 | 16 | #include 17 | 18 | SETUPSECTS = 4 /* default nr of setup-sectors */ 19 | BOOTSEG = 0x07C0 /* original address of boot-sector */ 20 | INITSEG = DEF_INITSEG /* we move boot here - out of the way */ 21 | SETUPSEG = DEF_SETUPSEG /* setup starts here */ 22 | SYSSEG = DEF_SYSSEG /* system loaded at 0x10000 (65536) */ 23 | SYSSIZE = DEF_SYSSIZE /* system size: # of 16-byte clicks */ 24 | /* to be loaded */ 25 | ROOT_DEV = 0 /* ROOT_DEV is now written by "build" */ 26 | SWAP_DEV = 0 /* SWAP_DEV is now written by "build" */ 27 | 28 | #ifndef SVGA_MODE 29 | #define SVGA_MODE ASK_VGA 30 | #endif 31 | 32 | #ifndef RAMDISK 33 | #define RAMDISK 0 34 | #endif 35 | 36 | #ifndef ROOT_RDONLY 37 | #define ROOT_RDONLY 1 38 | #endif 39 | 40 | .code16 41 | .text 42 | 43 | .global _start 44 | _start: 45 | 46 | # Normalize the start address 47 | jmpl $BOOTSEG, $start2 48 | 49 | start2: 50 | movw %cs, %ax 51 | movw %ax, %ds 52 | movw %ax, %es 53 | movw %ax, %ss 54 | movw $0x7c00, %sp 55 | sti 56 | cld 57 | 58 | movw $bugger_off_msg, %si 59 | 60 | msg_loop: 61 | lodsb 62 | andb %al, %al 63 | jz die 64 | movb $0xe, %ah 65 | movw $7, %bx 66 | int $0x10 67 | jmp msg_loop 68 | 69 | die: 70 | # Allow the user to press a key, then reboot 71 | xorw %ax, %ax 72 | int $0x16 73 | int $0x19 74 | 75 | # int 0x19 should never return. In case it does anyway, 76 | # invoke the BIOS reset code... 77 | ljmp $0xf000,$0xfff0 78 | 79 | 80 | bugger_off_msg: 81 | .ascii "Direct booting from floppy is no longer supported.\r\n" 82 | .ascii "Please use a boot loader program instead.\r\n" 83 | .ascii "\n" 84 | .ascii "Remove disk and press any key to reboot . . .\r\n" 85 | .byte 0 86 | 87 | 88 | # Kernel attributes; used by setup 89 | 90 | .org 497 91 | setup_sects: .byte SETUPSECTS 92 | root_flags: .word ROOT_RDONLY 93 | syssize: .word SYSSIZE 94 | swap_dev: .word SWAP_DEV 95 | ram_size: .word RAMDISK 96 | vid_mode: .word SVGA_MODE 97 | root_dev: .word ROOT_DEV 98 | boot_flag: .word 0xAA55 99 | -------------------------------------------------------------------------------- /kernel/drivers/floppy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006 Sam Hocevar 4 | * 2009 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | #include "kernel.h" 15 | #include "klibc.h" 16 | #include "floppy.h" 17 | 18 | 19 | int floppy_get_info(struct floppy_info *floppy_info) 20 | { 21 | outb(0x70, 0x10); 22 | unsigned char c = inb(0x71); 23 | int a = c >> 4; 24 | int b = c & 0xF; 25 | 26 | char *drive_type[6] = { 27 | "none", 28 | "360kb 5.25in", 29 | "1.2mb 5.25in", 30 | "720kb 3.5in", 31 | "1.44mb 3.5in", 32 | "2.88mb 3.5in" 33 | }; 34 | 35 | 36 | memcpy(floppy_info->drive[0].type, drive_type[a], 37 | strlen(drive_type[a]) + 1); 38 | memcpy(floppy_info->drive[1].type, drive_type[b], 39 | strlen(drive_type[b]) + 1); 40 | 41 | floppy_info->count = 0; 42 | if (a != 0) 43 | floppy_info->count++; 44 | if (b != 0) 45 | floppy_info->count++; 46 | 47 | return 0; 48 | } 49 | 50 | void floppy_print_info(struct floppy_info *floppy_info) 51 | { 52 | printf("%d floppy drive(s)\n", floppy_info->count); 53 | if (floppy_info->count) 54 | { 55 | printf("Floppy %d type %s\n", 0, floppy_info->drive[0].type); 56 | if (floppy_info->count == 2) 57 | { 58 | printf("Floppy %d type %s\n", 1, floppy_info->drive[1].type); 59 | } 60 | } 61 | 62 | } 63 | 64 | int floppy_get_status(void) 65 | { 66 | unsigned char c = inb(0x1F7); 67 | return c; 68 | } 69 | -------------------------------------------------------------------------------- /kernel/drivers/floppy.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006 Sam Hocevar 4 | * 2009 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | struct floppy_drive 15 | { 16 | char type[16]; 17 | u8 status; 18 | }; 19 | 20 | struct floppy_info 21 | { 22 | int count; 23 | struct floppy_drive drive[2]; 24 | }; 25 | 26 | int floppy_get_info(struct floppy_info *floppy_info); 27 | void floppy_print_info(struct floppy_info *floppy_info); 28 | 29 | int floppy_get_status(void); 30 | -------------------------------------------------------------------------------- /kernel/drivers/memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006 Sam Hocevar 4 | * 2009 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | #include "kernel.h" 15 | #include "klibc.h" 16 | #include "memory.h" 17 | -------------------------------------------------------------------------------- /kernel/drivers/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006 Sam Hocevar 4 | * 2009 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | -------------------------------------------------------------------------------- /kernel/drivers/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006 Sam Hocevar 4 | * 2009 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | #include "kernel.h" 15 | #include "klibc.h" 16 | #include "timer.h" 17 | 18 | u32 ticks = 0; 19 | 20 | void timer_phase(int hz) 21 | { 22 | unsigned int divisor = 1193180 / hz; /* Calculate our divisor */ 23 | /* 24 | 0x43 is the Mode/Command register 25 | 26 | From http://wiki.osdev.org/Programmable_Interval_Timer#Read_Back_Status_Byte : 27 | Bits Usage 28 | 6 and 7 Select channel : 29 | 0 0 = Channel 0 30 | 0 1 = Channel 1 31 | 1 0 = Channel 2 32 | 1 1 = Read-back command (8254 only) 33 | 4 and 5 Access mode : 34 | 0 0 = Latch count value command 35 | 0 1 = Access mode: lobyte only 36 | 1 0 = Access mode: hibyte only 37 | 1 1 = Access mode: lobyte/hibyte 38 | 1 to 3 Operating mode : 39 | 0 0 0 = Mode 0 (interrupt on terminal count) 40 | 0 0 1 = Mode 1 (hardware re-triggerable one-shot) 41 | 0 1 0 = Mode 2 (rate generator) 42 | 0 1 1 = Mode 3 (square wave generator) 43 | 1 0 0 = Mode 4 (software triggered strobe) 44 | 1 0 1 = Mode 5 (hardware triggered strobe) 45 | 1 1 0 = Mode 2 (rate generator, same as 010b) 46 | 1 1 1 = Mode 3 (square wave generator, same as 011b) 47 | 0 BCD/Binary mode: 0 = 16-bit binary, 1 = four-digit BCD 48 | 49 | */ 50 | unsigned short command = 0b00110110; 51 | outb(0x43, command); 52 | outb(0x40, divisor & 0xFF); /* Set low byte of divisor */ 53 | outb(0x40, divisor >> 8); /* Set high byte of divisor */ 54 | } 55 | -------------------------------------------------------------------------------- /kernel/drivers/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006 Sam Hocevar 4 | * 2009 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | extern u32 ticks; 15 | void timer_phase(int hz); 16 | -------------------------------------------------------------------------------- /kernel/kernel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Colour ASCII-Art library 3 | * Copyright (c) 2006-2012 Sam Hocevar 4 | * 2009-2010 Jean-Yves Lamoureux 5 | * All Rights Reserved 6 | * 7 | * This library is free software. It comes without any warranty, to 8 | * the extent permitted by applicable law. You can redistribute it 9 | * and/or modify it under the terms of the Do What the Fuck You Want 10 | * to Public License, Version 2, as published by Sam Hocevar. See 11 | * http://www.wtfpl.net/ for more details. 12 | */ 13 | 14 | #include "config.h" 15 | #include "caca_types.h" 16 | 17 | #ifdef __KERNEL__ 18 | 19 | #include "klibc.h" 20 | #include "boot/stage2.h" 21 | #include "kernel.h" 22 | #include "drivers/processor.h" 23 | #include "drivers/floppy.h" 24 | #include "drivers/timer.h" 25 | 26 | extern char const * const * caca_get_display_driver_list(void); 27 | extern char end[]; 28 | 29 | /* C entry point, called from stage2 */ 30 | int kmain(void) 31 | { 32 | struct processor_info processor_info; 33 | struct floppy_info floppy_info; 34 | 35 | printf("_start at 0x%x\n", _start); 36 | printf("kmain() at 0x%x\n", kmain); 37 | printf("Types : char[%d] short[%d] int[%d] unsigned long long[%d]\n", sizeof(char), sizeof(short), sizeof(int), sizeof(unsigned long long)); 38 | 39 | enable_interrupt(1); // Enable Keyboard Interrupt (IRQ1) 40 | enable_interrupt(0); // Enable IRQ0 (timer) 41 | enable_interrupt(13); 42 | timer_phase(100); // Fire IRQ0 each 1/100s 43 | 44 | 45 | processor_get_info(&processor_info); 46 | processor_print_info(&processor_info); 47 | 48 | floppy_get_info(&floppy_info); 49 | floppy_print_info(&floppy_info); 50 | 51 | /* Caca is delicious */ 52 | printf("Filling memory with 0xCACA, starting from 0x%x\n", end); 53 | 54 | char *ptr = end; 55 | while (1) 56 | { 57 | *ptr = 0xCA; 58 | *ptr++; 59 | } 60 | } 61 | 62 | char end[]; 63 | 64 | #endif /* __KERNEL__ */ 65 | -------------------------------------------------------------------------------- /kernel/kernel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca 3 | * libcaca Colour ASCII-Art library 4 | * Copyright (c) 2006-2012 Sam Hocevar 5 | * 2009-2010 Jean-Yves Lamoureux 6 | * All Rights Reserved 7 | * 8 | * This library is free software. It comes without any warranty, to 9 | * the extent permitted by applicable law. You can redistribute it 10 | * and/or modify it under the terms of the Do What the Fuck You Want 11 | * to Public License, Version 2, as published by Sam Hocevar. See 12 | * http://www.wtfpl.net/ for more details. 13 | */ 14 | 15 | 16 | 17 | 18 | extern void init_gdt(void); 19 | void init_pic(void); 20 | void init_idt(void); 21 | void putcar(unsigned char c); 22 | void dump_gdt(void); 23 | 24 | void disable_interrupt(char i); 25 | void enable_interrupt(char i); 26 | 27 | #define cli __asm__("cli" : : ) 28 | #define sti __asm__("sti" : : ) 29 | 30 | #define rdtsc(low, high) \ 31 | __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)) 32 | 33 | /* The application's entry point */ 34 | int main(int argc, char *argv[]); 35 | 36 | -------------------------------------------------------------------------------- /perl/Build.PL: -------------------------------------------------------------------------------- 1 | use Module::Build; 2 | 3 | my $builder = Module::Build->new ( 4 | module_name => 'Term::Caca', 5 | license => 'wtfpl', 6 | 7 | requires => { 8 | }, 9 | 10 | build_requires => { 11 | 'Test::More' => 0, 12 | }, 13 | 14 | script_files => [ 15 | ], 16 | 17 | extra_compiler_flags => scalar `caca-config --cflags`, 18 | extra_linker_flags => scalar `caca-config --libs`, 19 | create_makefile_pl => 'passthrough', 20 | ); 21 | 22 | $builder->create_build_script(); 23 | -------------------------------------------------------------------------------- /perl/MANIFEST: -------------------------------------------------------------------------------- 1 | .cvsignore 2 | Build.PL 3 | lib/Term/Caca.pm 4 | lib/Term/Caca.xs 5 | lib/Term/Caca/Bitmap.pm 6 | lib/Term/Caca/Constants.pm 7 | lib/Term/Caca/Sprite.pm 8 | lib/Term/Kaka.pm 9 | lib/Term/Kaka/Bitmap.pm 10 | lib/Term/Kaka/Constants.pm 11 | lib/Term/Kaka/Sprite.pm 12 | Makefile.PL 13 | MANIFEST This list of files 14 | MANIFEST.SKIP 15 | META.yml 16 | README 17 | t/data/caca.txt 18 | -------------------------------------------------------------------------------- /perl/MANIFEST.SKIP: -------------------------------------------------------------------------------- 1 | \bCVS\b 2 | ^MANIFEST\.bak$ 3 | ^Makefile$ 4 | \..*\.swp$ 5 | ~$ 6 | \bblib\b 7 | \b\.xvpics\b 8 | \b_build\b 9 | ^Build$ 10 | ^Linux-Input.*gz$ 11 | ^x.pl$ 12 | -------------------------------------------------------------------------------- /perl/META.yml: -------------------------------------------------------------------------------- 1 | --- #YAML:1.0 2 | name: Term-Caca 3 | version: 0.9_1 4 | author: ~ 5 | abstract: |- 6 | perl interface for libcaca (Colour AsCii Art library) 7 | license: wtfpl 8 | build_requires: 9 | Test::More: 0 10 | provides: 11 | Term::Caca: 12 | file: lib/Term/Caca.pm 13 | version: 0.9_1 14 | Term::Caca::Bitmap: 15 | file: lib/Term/Caca/Bitmap.pm 16 | Term::Caca::Constants: 17 | file: lib/Term/Caca/Constants.pm 18 | version: 0.9 19 | Term::Caca::Sprite: 20 | file: lib/Term/Caca/Sprite.pm 21 | Term::Kaka: 22 | file: lib/Term/Kaka.pm 23 | Term::Kaka::Bitmap: 24 | file: lib/Term/Kaka/Bitmap.pm 25 | Term::Kaka::Constants: 26 | file: lib/Term/Kaka/Constants.pm 27 | Term::Kaka::Sprite: 28 | file: lib/Term/Kaka/Sprite.pm 29 | generated_by: Module::Build version 0.26 30 | -------------------------------------------------------------------------------- /perl/Makefile.PL: -------------------------------------------------------------------------------- 1 | # Note: this file was auto-generated by Module::Build::Compat version 0.03 2 | 3 | unless (eval "use Module::Build::Compat 0.02; 1" ) { 4 | print "This module requires Module::Build to install itself.\n"; 5 | 6 | require ExtUtils::MakeMaker; 7 | my $yn = ExtUtils::MakeMaker::prompt 8 | (' Install Module::Build now from CPAN?', 'y'); 9 | 10 | unless ($yn =~ /^y/i) { 11 | die " *** Cannot install without Module::Build. Exiting ...\n"; 12 | } 13 | 14 | require Cwd; 15 | require File::Spec; 16 | require CPAN; 17 | 18 | # Save this 'cause CPAN will chdir all over the place. 19 | my $cwd = Cwd::cwd(); 20 | my $makefile = File::Spec->rel2abs($0); 21 | 22 | CPAN::Shell->install('Module::Build::Compat') 23 | or die " *** Cannot install without Module::Build. Exiting ...\n"; 24 | 25 | chdir $cwd or die "Cannot chdir() back to $cwd: $!"; 26 | } 27 | eval "use Module::Build::Compat 0.02; 1" or die $@; 28 | use lib '_build/lib'; 29 | Module::Build::Compat->run_build_pl(args => \@ARGV); 30 | require Module::Build; 31 | Module::Build::Compat->write_makefile(build_class => 'Module::Build'); 32 | -------------------------------------------------------------------------------- /perl/README: -------------------------------------------------------------------------------- 1 | ___________ _________ 2 | \__ ___/__________ _____ /\ /\ \_ ___ \_____ ____ _____ 3 | | |_/ __ \_ __ \/ \ \/ \/ / \ \/\__ \ _/ ___\\__ \ 4 | | |\ ___/| | \/ Y Y \ /\ /\ \ \____/ __ \\ \___ / __ \_ 5 | |____| \___ >__| |__|_| / \/ \/ \______ (____ /\___ >____ / 6 | \/ \/ \/ \/ \/ \/ 7 | 8 | --]- a perl wrapper around libcaca (Colour AsCii Art library) 9 | ^ ^ ^ ^ 10 | http://sam.zoy.org/projects/libcaca/ 11 | 12 | 13 | --]- a note about versioning, 14 | 15 | Term-Caca-x.y_z.tar.gz 16 | | | ^--------- sub-version of this perl wrapper 17 | | | 18 | `-`----------- version of libcaca c library 19 | this wrapper is based on. 20 | 21 | 22 | -------------------------------------------------------------------------------- /perl/lib/Term/Caca/Bitmap.pm: -------------------------------------------------------------------------------- 1 | package Term::Caca::Bitmap; 2 | 3 | 4 | 1; 5 | 6 | -------------------------------------------------------------------------------- /perl/lib/Term/Caca/Sprite.pm: -------------------------------------------------------------------------------- 1 | package Term::Caca::Sprite; 2 | 3 | 4 | 1; 5 | 6 | -------------------------------------------------------------------------------- /perl/lib/Term/Kaka/Bitmap.pm: -------------------------------------------------------------------------------- 1 | package Term::Kaka::Bitmap; 2 | 3 | use base 'Term::Caca::Bitmap'; 4 | 5 | 1; 6 | -------------------------------------------------------------------------------- /perl/lib/Term/Kaka/Constants.pm: -------------------------------------------------------------------------------- 1 | package Term::Kaka::Constants; 2 | 3 | use Term::Caca::Constants qw(:all); 4 | push @ISA, 'Term::Caca::Constants'; 5 | 6 | *Term::Kaka::Constants::EXPORT_OK = *Term::Caca::Constants::EXPORT_OK; 7 | *Term::Kaka::Constants::EXPORT_TAGS = *Term::Caca::Constants::EXPORT_TAGS; 8 | 9 | 1; 10 | -------------------------------------------------------------------------------- /perl/lib/Term/Kaka/Sprite.pm: -------------------------------------------------------------------------------- 1 | package Term::Kaka::Sprite; 2 | 3 | use base 'Term::Caca::Sprite'; 4 | 5 | 1; 6 | -------------------------------------------------------------------------------- /perl/t/data/caca.txt: -------------------------------------------------------------------------------- 1 | 12 6 6 3 2 | , 3 | ` ,_ , 4 | ` _( )_ 5 | _( ` )_ 6 | ( `-. ' ) 7 | `-.____,-' 8 | h 9 | h gg h 10 | h gggggg 11 | gggggggggg 12 | gggggggggggg 13 | gggggggggg 14 | 12 6 6 3 15 | . , 16 | ` ,_ 17 | _( )_ ' 18 | _( ` )_ 19 | ( `-. ' ) 20 | `-.____,-' 21 | h h 22 | h gg 23 | gggggg h 24 | gggggggggg 25 | gggggggggggg 26 | gggggggggg 27 | -------------------------------------------------------------------------------- /python/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | if USE_PYTHON 5 | cacadir = $(pythondir)/caca 6 | caca_PYTHON = \ 7 | caca/__init__.py \ 8 | caca/canvas.py \ 9 | caca/common.py \ 10 | caca/display.py \ 11 | caca/dither.py \ 12 | caca/font.py 13 | EXTRA_CHECKS = $(caca_PYTHON) 14 | endif 15 | 16 | EXTRA_DIST = \ 17 | setup.py \ 18 | examples/blit.py \ 19 | examples/cacainfo.py \ 20 | examples/colors.py \ 21 | examples/drawing.py \ 22 | examples/driver.py \ 23 | examples/event.py \ 24 | examples/figfont.py \ 25 | examples/frames.py \ 26 | examples/img2txt.py \ 27 | examples/gol.py \ 28 | examples/text.py 29 | 30 | -------------------------------------------------------------------------------- /python/caca/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # libcaca Colour ASCII-Art library 4 | # Python language bindings 5 | # Copyright (c) 2010 Alex Foulon 6 | # All Rights Reserved 7 | # 8 | # This library is free software. It comes without any warranty, to 9 | # the extent permitted by applicable law. You can redistribute it 10 | # and/or modify it under the terms of the Do What the Fuck You Want 11 | # to Public License, Version 2, as published by Sam Hocevar. See 12 | # http://www.wtfpl.net/ for more details. 13 | # 14 | 15 | """ Libcaca Python bindings """ 16 | 17 | #standard modules 18 | import locale 19 | import sys 20 | import ctypes 21 | from ctypes.util import find_library 22 | 23 | if find_library('caca') is not None: 24 | _lib = ctypes.cdll.LoadLibrary(find_library('caca')) 25 | else: 26 | raise ImportError( 27 | "Can't find shared library, you need to install libcaca in your path !") 28 | 29 | #functions to handle string/bytes in python3+ 30 | if sys.version_info[0:2] >= (3, 0): 31 | _PYTHON3 = True 32 | else: 33 | _PYTHON3 = False 34 | 35 | def _str_to_bytes(the_string): 36 | """ Translate string to bytes type for python 3. 37 | """ 38 | return bytes(the_string, locale.getlocale()[1]) 39 | 40 | def _bytes_to_str(the_bytes): 41 | """ Translate bytes to string type for python 3. 42 | """ 43 | return the_bytes.decode(locale.getlocale()[1]) 44 | 45 | from .common import * 46 | 47 | -------------------------------------------------------------------------------- /python/examples/blit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # figfont libcaca blit test program 5 | # Copyright (c) 2010 Alex Foulon 6 | # 7 | # This file is a Python port of "examples/blit.c" 8 | # which is: 9 | # Copyright (c) 2006-2010 Sam Hocevar 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, NullCanvas 23 | from caca.display import Display, DisplayError, Event 24 | 25 | THE_PIG="""\ 26 | ,__ __, 27 | \\)`\\_..._/`(/ 28 | .' _ _ '. 29 | / o\\ /o \\ 30 | | .-.-. | _ 31 | | /() ()\\ | (,`) 32 | / \\ '-----' / \\ .' 33 | | '-..___..-' | 34 | | | 35 | | | 36 | ; ; 37 | \\ / \\ / 38 | \\-..-/'-'\\-..-/ 39 | jgs\\/\\/ \\/\\/""" 40 | 41 | def main(): 42 | """ Main function. """ 43 | try: 44 | cv = Canvas(0, 0) 45 | dp = Display(cv) 46 | except (CanvasError, DisplayError) as err: 47 | sys.stderr.write("%s\n" % err) 48 | sys.exit(2) 49 | 50 | sprite = Canvas(0, 0) 51 | sprite.set_color_ansi(caca.COLOR_LIGHTRED, caca.COLOR_BLACK) 52 | sprite.import_from_memory(THE_PIG, "text") 53 | sprite.set_handle(sprite.get_width()//2, sprite.get_height()//2) 54 | 55 | cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE) 56 | cv.put_str(0, 0, "Centered sprite") 57 | cv.blit(cv.get_width()//2, cv.get_height()//2, sprite, NullCanvas()) 58 | 59 | dp.refresh() 60 | dp.get_event(caca.EVENT_KEY_PRESS, Event(), -1) 61 | 62 | sys.exit(0) 63 | 64 | if __name__ == "__main__": 65 | main() 66 | 67 | -------------------------------------------------------------------------------- /python/examples/cacainfo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # libcaca Colour ASCII-Art library 5 | # Python language bindings 6 | # Copyright (c) 2010 Alex Foulon 7 | # All Rights Reserved 8 | # 9 | # This library is free software. It comes without any warranty, to 10 | # the extent permitted by applicable law. You can redistribute it 11 | # and/or modify it under the terms of the Do What the Fuck You Want 12 | # to Public License, Version 2, as published by Sam Hocevar. See 13 | # http://www.wtfpl.net/ for more details. 14 | # 15 | 16 | """ Libcaca Python bindings """ 17 | 18 | import caca 19 | 20 | if __name__ == '__main__': 21 | print("libcaca version %s" % caca.get_version()) 22 | print("") 23 | print("Available drivers:") 24 | for drv, desc in caca.get_display_driver_list(): 25 | print(" - %s: %s" % (drv, desc)) 26 | print("") 27 | print("Available fonts:") 28 | for font in caca.get_font_list(): 29 | print(" - %s" % font) 30 | print("") 31 | print("Export formats:") 32 | for fmt, desc in caca.get_export_list(): 33 | print(" - %s: %s" % (fmt, desc)) 34 | print("") 35 | print("Import formats:") 36 | for fmt, desc in caca.get_import_list(): 37 | print(" - %s: %s" % (fmt, desc)) 38 | -------------------------------------------------------------------------------- /python/examples/colors.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # colors display all possible libcaca colour pairs 5 | # Copyright (c) 2010 Alex Foulon 6 | # 7 | # This file is a Python port of "examples/colors.c" 8 | # which is: 9 | # Copyright (c) 2003-2010 Sam Hocevar 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 | 77 | -------------------------------------------------------------------------------- /python/examples/driver.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # driver libcaca test drivers program 5 | # Copyright (c) 2010 Alex Foulon 6 | # 7 | # This file is a Python port of "examples/driver.c" 8 | # which is: 9 | # Copyright (c) 2006-2010 Sam Hocevar 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 | lst = caca.get_display_driver_list() 29 | cur = 0 30 | 31 | try: 32 | cv = Canvas(0, 0) 33 | dp = Display(cv) 34 | except (CanvasError, DisplayError) as err: 35 | sys.stderr.write("%s\n" % err) 36 | sys.exit(127) 37 | 38 | cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLACK) 39 | 40 | while True: 41 | cv.put_str(1, 0, "Available drivers:") 42 | cur_driver = dp.get_driver() 43 | n = 0 44 | for driver, desc in lst: 45 | if driver == cur_driver: 46 | cv.put_str(2, n + 2, "%s %s (%s)" % ('*', driver, desc)) 47 | else: 48 | cv.put_str(2, n + 2, "%s %s (%s)" % (' ', driver, desc)) 49 | n += 1 50 | 51 | cv.put_str(2, n + 3, "Switching driver in 5 seconds") 52 | dp.refresh() 53 | 54 | if dp.get_event(caca.EVENT_KEY_PRESS, Event(), 5000000): 55 | break 56 | 57 | cur += 1 58 | if cur < len(lst) and lst[cur][0] == "raw": 59 | cur += 1 60 | if cur >= len(lst): 61 | cur = 0 62 | 63 | dp.set_driver(lst[cur][0]) 64 | 65 | if __name__ == "__main__": 66 | main() 67 | 68 | -------------------------------------------------------------------------------- /python/examples/figfont.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # figfont libcaca FIGfont test program 5 | # Copyright (c) 2010 Alex Foulon 6 | # 7 | # This file is a Python port of "examples/figfont.c" 8 | # which is: 9 | # Copyright (c) 2007-2010 Sam Hocevar 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 codecs 20 | import os 21 | import sys 22 | 23 | import caca 24 | from caca.canvas import Canvas, CanvasError 25 | 26 | def main(): 27 | """ Main function. """ 28 | 29 | 30 | if len(sys.argv) < 3: 31 | sys.stderr.write("Usage: %s \n" \ 32 | % os.path.basename(sys.argv[0])) 33 | sys.exit(2) 34 | 35 | try: 36 | cv = Canvas(0, 0) 37 | except CanvasError as err: 38 | sys.stderr.write("%s\n" % err) 39 | sys.exit(2) 40 | 41 | if cv.set_figfont(sys.argv[1]): 42 | sys.stderr.write("Could not open font...\n") 43 | sys.exit(2) 44 | 45 | if sys.version_info[0:2] >= (3,0): 46 | word = sys.argv[2] 47 | else: 48 | word = codecs.decode(sys.argv[2], "utf8") 49 | for c in word: 50 | cv.put_figchar(c) 51 | 52 | sys.stderr.write(cv.export_to_memory("utf8")) 53 | 54 | if __name__ == "__main__": 55 | main() 56 | 57 | -------------------------------------------------------------------------------- /python/examples/frames.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # frames canvas frame switching features 5 | # Copyright (c) 2010 Alex Foulon 6 | # 7 | # This file is a Python port of "examples/frames.c" 8 | # which is: 9 | # Copyright (c) 2006-2010 Sam Hocevar 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(0, 0) 30 | except CanvasError as err: 31 | sys.stderr.write("%s\n" % err) 32 | sys.exit(2) 33 | 34 | for idx in range(1, 200): 35 | cv.create_frame(idx) 36 | 37 | sys.stderr.write("canvas created, size is %dx%d\n" \ 38 | % (cv.get_width(), cv.get_height())) 39 | 40 | cv.set_size(150, 80) 41 | sys.stderr.write("canvas expanded, size is %dx%d\n" \ 42 | % (cv.get_width(), cv.get_height())) 43 | 44 | for idx in range(0, 16): 45 | cv.set_frame(idx) 46 | cv.set_color_ansi(caca.COLOR_WHITE, idx) 47 | cv.fill_box(0, 0, 40, 15, ':') 48 | cv.set_color_ansi(caca.COLOR_WHITE, caca.COLOR_BLUE) 49 | cv.put_str((idx * 5) // 2, idx, "カカ") 50 | cv.set_color_ansi(caca.COLOR_DEFAULT, caca.COLOR_TRANSPARENT) 51 | 52 | cv.set_size(41, 16) 53 | sys.stderr.write("canvas shrinked, size is %dx%d\n" \ 54 | % (cv.get_width(), cv.get_height())) 55 | 56 | try: 57 | dp = Display(cv) 58 | except DisplayError as err: 59 | sys.stderr.write("%s\n" % err) 60 | sys.exit(2) 61 | 62 | dp.set_time(50000) 63 | sys.stderr.write("display attached, size is %dx%d\n" \ 64 | % (cv.get_width(), cv.get_height())) 65 | 66 | n = 0 67 | while not dp.get_event(caca.EVENT_KEY_PRESS, Event(), 0): 68 | cv.set_frame(n % 16) 69 | dp.refresh() 70 | n += 1 71 | 72 | if __name__ == "__main__": 73 | main() 74 | 75 | -------------------------------------------------------------------------------- /python/examples/text.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # text canvas text import/export 5 | # Copyright (c) 2010 Alex Foulon 6 | # 7 | # This file is a Python port of "examples/text.c" 8 | # which is: 9 | # Copyright (c) 2006-2010 Sam Hocevar 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, NullCanvas 23 | from caca.display import Display, DisplayError, Event 24 | 25 | STRING="""\ 26 | |_| 27 | _,----._ | | 28 | (/ @ @ \\) __ 29 | | OO | |_ 30 | \\ `--' / |__ 31 | `----' 32 | |_| 33 | Hello world! | 34 | 35 | """ 36 | 37 | def main(): 38 | """ Main function. """ 39 | 40 | try: 41 | pig = Canvas(0, 0) 42 | pig.import_from_memory(STRING, "text") 43 | cv = Canvas(pig.get_width() * 2, pig.get_height() * 2) 44 | except CanvasError as err: 45 | sys.stderr.write("%s\n" % err) 46 | sys.exit(2) 47 | 48 | cv.blit(0, 0, pig, NullCanvas()) 49 | pig.flip() 50 | cv.blit(pig.get_width(), 0, pig, NullCanvas()) 51 | pig.flip() 52 | pig.flop() 53 | cv.blit(0, pig.get_height(), pig, NullCanvas()) 54 | pig.flop() 55 | pig.rotate_180() 56 | cv.blit(pig.get_width(), pig.get_height(), pig, NullCanvas()) 57 | 58 | for j in range(0, cv.get_height()): 59 | for i in range(0, cv.get_width(), 2): 60 | cv.set_color_ansi(caca.COLOR_LIGHTBLUE + (i + j) % 6, 61 | caca.COLOR_DEFAULT) 62 | 63 | a = cv.get_attr(-1, -1) 64 | cv.put_attr(i, j, a) 65 | cv.put_attr(i+1, j, a) 66 | 67 | print("%s" % cv.export_to_memory('utf8')) 68 | cv.rotate_left() 69 | print("%s" % cv.export_to_memory('utf8')) 70 | 71 | if __name__ == "__main__": 72 | main() 73 | 74 | -------------------------------------------------------------------------------- /python/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Minimal setup.py script 4 | # 5 | 6 | import sys 7 | from setuptools import setup 8 | 9 | try: 10 | import caca 11 | except ImportError as err: 12 | sys.stderr.write("FATAL: %s\n" % str(err)) 13 | sys.exit(127) 14 | 15 | version_string=caca.get_version() 16 | 17 | setup( 18 | name='caca', 19 | author='Alex Foulon', 20 | author_email='alxf@lavabit.com', 21 | version=version_string, 22 | packages=['caca'], 23 | package_dir={ 24 | 'caca': 'caca', 25 | }, 26 | test_suite='test.alltests', 27 | ) 28 | 29 | -------------------------------------------------------------------------------- /ruby/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | rubylibdir = $(RUBY_SITEARCHDIR) 5 | rubysitedir = $(RUBY_SITELIBDIR) 6 | 7 | if USE_RUBY 8 | rubylib_LTLIBRARIES = caca.la 9 | rubysite_DATA = lib/caca.rb 10 | if USE_RUBY_MINITEST 11 | TESTS = test 12 | endif 13 | endif 14 | 15 | CFLAGS += -Wno-strict-prototypes -Wno-missing-prototypes 16 | 17 | caca_la_CPPFLAGS = -I$(top_srcdir)/caca -I../caca $(RUBY_CFLAGS) 18 | caca_la_SOURCES = caca.c \ 19 | common.h \ 20 | caca-canvas.c \ 21 | caca-canvas.h \ 22 | caca-dither.c \ 23 | caca-dither.h \ 24 | caca-font.c \ 25 | caca-font.h \ 26 | caca-display.c \ 27 | caca-display.h \ 28 | caca-event.c \ 29 | caca-event.h \ 30 | $(NULL) 31 | caca_la_LDFLAGS = -module -avoid-version -shared $(RUBY_LIBS) 32 | caca_la_LIBADD = ../caca/libcaca.la 33 | 34 | EXTRA_DIST = ruby.dox \ 35 | ruby-caca.dox \ 36 | lib/caca.rb \ 37 | test \ 38 | t/tc_canvas.rb \ 39 | t/tc_dither.rb \ 40 | t/tc_font.rb \ 41 | t/tc_frame.rb \ 42 | README \ 43 | $(NULL) 44 | 45 | -------------------------------------------------------------------------------- /ruby/README: -------------------------------------------------------------------------------- 1 | This a Ruby binding for libcaca. 2 | 3 | You can play with it by doing require 'caca' and looking at 4 | the Caca module, or maybe read the documentation :) 5 | -------------------------------------------------------------------------------- /ruby/caca-canvas.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Ruby bindings 3 | * Copyright (c) 2007-2010 Pascal Terjan 4 | * 2012 Sam Hocevar 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #ifndef __CACA_CANVAS_H__ 14 | #define __CACA_CANVAS_H__ 15 | 16 | #include 17 | 18 | extern VALUE cCanvas; 19 | extern void Init_caca_canvas(VALUE); 20 | extern VALUE canvas_create(caca_canvas_t *canvas); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /ruby/caca-display.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Ruby bindings 3 | * Copyright (c) 2007-2010 Pascal Terjan 4 | * 2012 Sam Hocevar 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #ifndef __CACA_DISPLAY_H__ 14 | #define __CACA_DISPLAY_H__ 15 | 16 | #include 17 | 18 | extern VALUE cDisplay; 19 | extern void Init_caca_display(VALUE); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /ruby/caca-dither.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Ruby bindings 3 | * Copyright (c) 2007-2010 Pascal Terjan 4 | * 2012 Sam Hocevar 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #ifndef __CACA_DITHER_H__ 14 | #define __CACA_DITHER_H__ 15 | 16 | #include 17 | 18 | extern VALUE cDither; 19 | extern void Init_caca_dither(VALUE); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /ruby/caca-event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Ruby bindings 3 | * Copyright (c) 2007-2010 Pascal Terjan 4 | * 2012 Sam Hocevar 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #ifndef __CACA_EVENT_H__ 14 | #define __CACA_EVENT_H__ 15 | 16 | #include 17 | 18 | extern VALUE cEvent; 19 | extern VALUE cEventKeyPress; 20 | extern VALUE cEventKeyRelease; 21 | extern VALUE cEventMouse; 22 | extern VALUE cEventMousePress; 23 | extern VALUE cEventMouseRelease; 24 | extern VALUE cEventMouseMotion; 25 | extern VALUE cEventResize; 26 | extern VALUE cEventQuit; 27 | extern void Init_caca_event(VALUE); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /ruby/caca-font.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Ruby bindings 3 | * Copyright (c) 2007-2010 Pascal Terjan 4 | * 2012 Sam Hocevar 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #ifndef __CACA_FONT_H__ 14 | #define __CACA_FONT_H__ 15 | 16 | #include 17 | 18 | extern VALUE cFont; 19 | extern void Init_caca_font(VALUE); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /ruby/caca.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libcaca Ruby bindings 3 | * Copyright (c) 2007-2010 Pascal Terjan 4 | * 2012 Sam Hocevar 5 | * 6 | * This library is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by Sam Hocevar. See 10 | * http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #include "caca-canvas.h" 17 | #include "caca-dither.h" 18 | #include "caca-font.h" 19 | #include "caca-display.h" 20 | #include "caca-event.h" 21 | 22 | static VALUE get_version(VALUE self) 23 | { 24 | return rb_str_new2(caca_get_version()); 25 | } 26 | 27 | void Init_caca() 28 | { 29 | VALUE mCaca = rb_define_module("Caca"); 30 | 31 | rb_define_singleton_method(mCaca, "version", get_version, 0); 32 | 33 | rb_define_const(mCaca, "BLACK", INT2FIX(CACA_BLACK)); 34 | rb_define_const(mCaca, "BLUE", INT2FIX(CACA_BLUE)); 35 | rb_define_const(mCaca, "GREEN", INT2FIX(CACA_GREEN)); 36 | rb_define_const(mCaca, "CYAN", INT2FIX(CACA_CYAN)); 37 | rb_define_const(mCaca, "RED", INT2FIX(CACA_RED)); 38 | rb_define_const(mCaca, "MAGENTA", INT2FIX(CACA_MAGENTA)); 39 | rb_define_const(mCaca, "BROWN", INT2FIX(CACA_BROWN)); 40 | rb_define_const(mCaca, "LIGHTGRAY", INT2FIX(CACA_LIGHTGRAY)); 41 | rb_define_const(mCaca, "DARKGRAY", INT2FIX(CACA_DARKGRAY)); 42 | rb_define_const(mCaca, "LIGHTBLUE", INT2FIX(CACA_LIGHTBLUE)); 43 | rb_define_const(mCaca, "LIGHTGREEN", INT2FIX(CACA_LIGHTGREEN)); 44 | rb_define_const(mCaca, "LIGHTCYAN", INT2FIX(CACA_LIGHTCYAN)); 45 | rb_define_const(mCaca, "LIGHTRED", INT2FIX(CACA_LIGHTRED)); 46 | rb_define_const(mCaca, "LIGHTMAGENTA", INT2FIX(CACA_LIGHTMAGENTA)); 47 | rb_define_const(mCaca, "YELLOW", INT2FIX(CACA_YELLOW)); 48 | rb_define_const(mCaca, "WHITE", INT2FIX(CACA_WHITE)); 49 | rb_define_const(mCaca, "DEFAULT", INT2FIX(CACA_DEFAULT)); 50 | rb_define_const(mCaca, "TRANSPARENT", INT2FIX(CACA_TRANSPARENT)); 51 | 52 | rb_define_const(mCaca, "BOLD", INT2FIX(CACA_BOLD)); 53 | rb_define_const(mCaca, "ITALICS", INT2FIX(CACA_ITALICS)); 54 | rb_define_const(mCaca, "UNDERLINE", INT2FIX(CACA_UNDERLINE)); 55 | rb_define_const(mCaca, "BLINK", INT2FIX(CACA_BLINK)); 56 | 57 | Init_caca_canvas(mCaca); 58 | Init_caca_dither(mCaca); 59 | Init_caca_font(mCaca); 60 | Init_caca_display(mCaca); 61 | Init_caca_event(mCaca); 62 | } 63 | -------------------------------------------------------------------------------- /ruby/lib/caca.rb: -------------------------------------------------------------------------------- 1 | require 'caca' 2 | 3 | module Caca 4 | class Display 5 | attr_reader :canvas 6 | end 7 | class Event 8 | def Event.to_i 9 | const_get("TYPE") 10 | end 11 | def Event.|(i) 12 | i = i.to_i 13 | const_get("TYPE")|i 14 | end 15 | def quit? 16 | false 17 | end 18 | class Key 19 | attr_reader :ch, :utf32, :utf8 20 | def initialize(ch, utf32, utf8) 21 | @ch, @utf32, @utf8 = ch, utf32, utf8 22 | end 23 | end 24 | class Mouse 25 | attr_reader :x, :y, :button 26 | def initialize(x, y, button) 27 | @x, @y, @button = x, y, button 28 | end 29 | end 30 | class Resize 31 | attr_reader :w, :h 32 | def initialize(w, h) 33 | @w, @h = w, h 34 | end 35 | end 36 | class Quit 37 | def quit? 38 | true 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /ruby/ruby.dox: -------------------------------------------------------------------------------- 1 | /** \page libcaca-ruby Libcaca ruby bindings 2 | 3 | There is no real documentation yet for the Ruby binding but \c methods on any object should help you :) 4 | 5 | I tried to follow Ruby spirit meaning that : 6 | - most of the methods return self 7 | - the methods set_foo with only an argument are also available as foo= 8 | (returning the value instead of self) 9 | - the methods originally named get_foo are available only as foo 10 | 11 | For the list of methods and some sample code, read: 12 | 13 | \subpage libcaca-ruby-api 14 | 15 | */ 16 | -------------------------------------------------------------------------------- /ruby/t/tc_canvas.rb: -------------------------------------------------------------------------------- 1 | require 'caca' 2 | 3 | class TC_Canvas < MiniTest::Test 4 | def setup 5 | @c = Caca::Canvas.new(3, 3) 6 | end 7 | def test_create 8 | c = Caca::Canvas.new(3, 3) 9 | refute_nil(c, 'Canvas creation failed') 10 | assert(c.width == 3 && c.height == 3, 'Wrong size for new canvas') 11 | end 12 | def test_width 13 | @c.width = 42 14 | assert_equal(42, @c.width, 'Failed to set width with =') 15 | @c.set_width(24) 16 | assert_equal(24, @c.width, 'Failed to set width') 17 | end 18 | def test_height 19 | @c.height = 42 20 | assert_equal(42, @c.height, 'Failed to set height with =') 21 | @c.set_height(24) 22 | assert_equal(24, @c.height, 'Failed to set height') 23 | end 24 | def test_size 25 | @c.set_size(100,100) 26 | assert(@c.width == 100 && @c.height == 100, 'Failed to set size') 27 | end 28 | def test_import 29 | @c.import_from_memory("foo", "") 30 | assert_equal("foo\r\n", @c.export_to_memory("irc"), "Import/Export failed") 31 | @c.import_area_from_memory(0, 0, "p", "") 32 | assert_equal("poo\r\n", @c.export_area_to_memory(0, 0, 3, 1, "irc"), "Import/Export of area failed") 33 | end 34 | def test_cursor 35 | @c.gotoxy(1,1) 36 | assert_equal(1, @c.wherex) 37 | assert_equal(1, @c.wherey) 38 | end 39 | def test_clear 40 | @c.put_char(1, 1, 64) 41 | @c.clear 42 | assert_equal("", @c.export_to_memory("irc").strip, "Failed to clear canvas") 43 | end 44 | def test_char 45 | @c.put_char(1, 1, 42) 46 | assert_equal(42, @c.get_char(1,1)) 47 | end 48 | def test_render 49 | c = Caca::Canvas.new(4,4) 50 | c.put_str(0,0,"plop") 51 | f = Caca::Font.new(Caca::Font.list[0]) 52 | refute_nil(c.render(f, c.width*f.width, c.height*f.height, c.width*f.width*4)) 53 | end 54 | def test_fail_render 55 | c = Caca::Canvas.new(4,4) 56 | assert_raises(ArgumentError) { 57 | c.render(nil, c.width, c.height, c.width*4) 58 | } 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /ruby/t/tc_display.rb: -------------------------------------------------------------------------------- 1 | require 'caca' 2 | 3 | class TC_Canvas < MiniTest::Test 4 | def test_create 5 | d = Caca::Display.new() 6 | refute_nil(d, 'Display creation failed') 7 | end 8 | def test_create_with_driver 9 | d = Caca::Display.new(Caca::Display.driver_list[0]) 10 | refute_nil(d, 'Display creation failed') 11 | end 12 | def test_create_wrong_args 13 | c = Caca::Canvas.new(3, 3) 14 | assert_raises(RuntimeError){Caca::Display.new("plop")} 15 | assert_raises(RuntimeError){Caca::Display.new(c, "plop")} 16 | assert_raises(ArgumentError){Caca::Display.new("plop", "plop")} 17 | assert_raises(ArgumentError){Caca::Display.new(c, c)} 18 | end 19 | def test_create_from_canvas 20 | c = Caca::Canvas.new(3, 3) 21 | d = Caca::Display.new(c) 22 | refute_nil(d, 'Display creation failed') 23 | assert_equal(d.canvas, c, 'Wrong canvas') 24 | end 25 | def test_set_title 26 | c = Caca::Canvas.new(3, 3) 27 | d = Caca::Display.new(c) 28 | d.title = "Test !" 29 | end 30 | def test_set_cursor 31 | d = Caca::Display.new() 32 | d.cursor = 1 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /ruby/t/tc_dither.rb: -------------------------------------------------------------------------------- 1 | require 'caca' 2 | 3 | class TC_Canvas < MiniTest::Test 4 | def test_create 5 | d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 6 | end 7 | def test_fail_create 8 | assert_raises(RuntimeError) { 9 | d = Caca::Dither.new(-1, 32, 32, 32, 0, 0, 0, 0) 10 | } 11 | end 12 | def test_set_palette 13 | d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 14 | d.palette = [[0xfff, 0xfff, 0xfff, 0xfff]] * 256 15 | end 16 | def test_fail_set_palette 17 | assert_raises(ArgumentError) { 18 | d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 19 | d.palette = [] 20 | } 21 | end 22 | def test_fail_set_palette2 23 | assert_raises(RuntimeError) { 24 | d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 25 | d.palette = [[0xffff, 0, 0, 0]] * 256 26 | } 27 | end 28 | def test_set_brightness 29 | d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 30 | d.brightness = 0.5 31 | end 32 | def test_set_gamma 33 | d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 34 | d.gamma = 0.5 35 | end 36 | def test_set_contrast 37 | d = Caca::Dither.new(8, 32, 32, 32, 0, 0, 0, 0) 38 | d.contrast = 0.5 39 | end 40 | end 41 | 42 | -------------------------------------------------------------------------------- /ruby/t/tc_font.rb: -------------------------------------------------------------------------------- 1 | require 'caca' 2 | 3 | class TC_Canvas < MiniTest::Test 4 | def test_list 5 | refute_nil(Caca::Font.list) 6 | end 7 | def test_load 8 | Caca::Font.list.each{|f| 9 | font = Caca::Font.new(f) 10 | refute_nil(font) 11 | refute_nil(font.width) 12 | refute_nil(font.height) 13 | refute_nil(font.blocks) 14 | } 15 | end 16 | def test_fail_load 17 | assert_raises(RuntimeError) { 18 | Caca::Font.new("This font should not exist") 19 | } 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /ruby/t/tc_frame.rb: -------------------------------------------------------------------------------- 1 | require 'caca' 2 | 3 | class TC_Frame < MiniTest::Test 4 | def setup 5 | @c = Caca::Canvas.new(3, 3) 6 | end 7 | def test_create 8 | f = @c.create_frame(1) 9 | assert(f, 'Frame creation failed') 10 | @c.free_frame(1) 11 | end 12 | def test_name 13 | f = @c.create_frame(1) 14 | assert(@c.frame_name, 'Failed to get frame name') 15 | @c.frame_name="test" 16 | assert(@c.frame_name == "test", 'Failed to set frame name') 17 | @c.free_frame(1) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /ruby/test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'minitest/autorun' 4 | 5 | $LOAD_PATH.unshift(".libs").unshift("lib") 6 | 7 | Dir.glob("./t/tc*.rb").each{ |t| 8 | require t 9 | } 10 | 11 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | pkgdata_DATA = caca.txt 5 | 6 | EXTRA_DIST = caca.txt cacademo.vcxproj cacafire.vcxproj cacaview.vcxproj 7 | AM_CPPFLAGS += -DLIBCACA=1 -DX_DISPLAY_MISSING=1 8 | 9 | bin_PROGRAMS = cacademo cacafire cacaplay cacaview img2txt cacaclock $(fcntl_programs) 10 | noinst_PROGRAMS = cacadraw 11 | 12 | cacademo_SOURCES = cacademo.c texture.h 13 | cacademo_LDADD = ../caca/libcaca.la ../caca/libcaca.la 14 | cacademo_LDFLAGS = @MATH_LIBS@ 15 | 16 | cacafire_SOURCES = aafire.c 17 | cacafire_LDADD = ../caca/libcaca.la ../caca/libcaca.la 18 | 19 | cacaview_SOURCES = cacaview.c common-image.c common-image.h 20 | cacaview_LDADD = ../caca/libcaca.la ../caca/libcaca.la 21 | cacaview_CFLAGS = $(IMLIB2_CFLAGS) 22 | cacaview_LDFLAGS = $(IMLIB2_LIBS) 23 | 24 | cacadraw_SOURCES = cacadraw.c 25 | cacadraw_LDADD = ../caca/libcaca.la ../caca/libcaca.la 26 | 27 | cacaplay_SOURCES = cacaplay.c 28 | cacaplay_LDADD = ../caca/libcaca.la ../caca/libcaca.la 29 | 30 | cacaserver_SOURCES = cacaserver.c 31 | cacaserver_LDADD = ../caca/libcaca.la 32 | 33 | cacaclock_SOURCES = cacaclock.c 34 | cacaclock_LDADD = ../caca/libcaca.la 35 | 36 | 37 | img2txt_SOURCES = img2txt.c common-image.c common-image.h 38 | img2txt_LDADD = ../caca/libcaca.la 39 | img2txt_CFLAGS = $(IMLIB2_CFLAGS) 40 | img2txt_LDFLAGS = $(IMLIB2_LIBS) 41 | 42 | if USE_NETWORK 43 | fcntl_programs = cacaserver 44 | else 45 | fcntl_programs = 46 | endif 47 | 48 | -------------------------------------------------------------------------------- /src/caca.txt: -------------------------------------------------------------------------------- 1 | 12 6 6 3 2 | , 3 | ` ,_ , 4 | ` _( )_ 5 | _( ` )_ 6 | ( `-. ' ) 7 | `-.____,-' 8 | h 9 | h gg h 10 | h gggggg 11 | gggggggggg 12 | gggggggggggg 13 | gggggggggg 14 | 12 6 6 3 15 | . , 16 | ` ,_ 17 | _( )_ ' 18 | _( ` )_ 19 | ( `-. ' ) 20 | `-.____,-' 21 | h h 22 | h gg 23 | gggggg h 24 | gggggggggg 25 | gggggggggggg 26 | gggggggggg 27 | -------------------------------------------------------------------------------- /src/cacademo.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cacalabs/libcaca/f42aa68fc798db63b7b2a789ae8cf5b90b57b752/src/cacademo.c -------------------------------------------------------------------------------- /src/common-image.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Imaging tools for cacaview and img2irc 3 | * Copyright © 2003—2018 Sam Hocevar 4 | * All Rights Reserved 5 | * 6 | * This program is free software. It comes without any warranty, to 7 | * the extent permitted by applicable law. You can redistribute it 8 | * and/or modify it under the terms of the Do What the Fuck You Want 9 | * to Public License, Version 2, as published by the WTFPL Task Force. 10 | * See http://www.wtfpl.net/ for more details. 11 | */ 12 | 13 | struct image 14 | { 15 | char *pixels; 16 | size_t w, h; 17 | struct caca_dither *dither; 18 | void *priv; 19 | }; 20 | 21 | /* Local functions */ 22 | extern struct image * load_image(char const *); 23 | extern void unload_image(struct image *); 24 | 25 | -------------------------------------------------------------------------------- /tools/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | include $(top_srcdir)/build/autotools/common.am 3 | 4 | noinst_PROGRAMS = optipal sortchars $(pango_programs) 5 | 6 | optipal_SOURCES = optipal.c 7 | 8 | sortchars_SOURCES = sortchars.c 9 | sortchars_LDADD = ../caca/libcaca.la 10 | 11 | makefont_SOURCES = makefont.c 12 | makefont_LDADD = ../caca/libcaca.la 13 | makefont_CFLAGS = $(PANGOFT2_CFLAGS) 14 | makefont_LDFLAGS = $(PANGOFT2_LIBS) 15 | 16 | if USE_PANGO 17 | pango_programs = makefont 18 | else 19 | pango_programs = 20 | endif 21 | 22 | --------------------------------------------------------------------------------