You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

117 lines
2.5 KiB

  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  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://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains the libcaca raw input and output driver
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #if !defined(__KERNEL__)
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include "cucul.h"
  23. #include "caca.h"
  24. #include "caca_internals.h"
  25. static int raw_init_graphics(caca_display_t *dp)
  26. {
  27. unsigned int width = cucul_get_canvas_width(dp->cv);
  28. unsigned int height = cucul_get_canvas_height(dp->cv);
  29. char const *geometry;
  30. #if defined(HAVE_GETENV)
  31. geometry = getenv("CACA_GEOMETRY");
  32. if(geometry && *geometry)
  33. sscanf(geometry, "%ux%u", &width, &height);
  34. #endif
  35. dp->resize.allow = 1;
  36. cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
  37. dp->resize.allow = 0;
  38. return 0;
  39. }
  40. static int raw_end_graphics(caca_display_t *dp)
  41. {
  42. return 0;
  43. }
  44. static int raw_set_display_title(caca_display_t *dp, char const *title)
  45. {
  46. return -1;
  47. }
  48. static unsigned int raw_get_display_width(caca_display_t const *dp)
  49. {
  50. return 0;
  51. }
  52. static unsigned int raw_get_display_height(caca_display_t const *dp)
  53. {
  54. return 0;
  55. }
  56. static void raw_display(caca_display_t *dp)
  57. {
  58. void *buffer;
  59. unsigned long int len;
  60. buffer = cucul_export_memory(dp->cv, "caca", &len);
  61. if(!buffer)
  62. return;
  63. fwrite(buffer, len, 1, stdout);
  64. fflush(stdout);
  65. free(buffer);
  66. }
  67. static void raw_handle_resize(caca_display_t *dp)
  68. {
  69. ;
  70. }
  71. static int raw_get_event(caca_display_t *dp, caca_privevent_t *ev)
  72. {
  73. ev->type = CACA_EVENT_NONE;
  74. return 0;
  75. }
  76. /*
  77. * Driver initialisation
  78. */
  79. int raw_install(caca_display_t *dp)
  80. {
  81. dp->drv.driver = CACA_DRIVER_RAW;
  82. dp->drv.init_graphics = raw_init_graphics;
  83. dp->drv.end_graphics = raw_end_graphics;
  84. dp->drv.set_display_title = raw_set_display_title;
  85. dp->drv.get_display_width = raw_get_display_width;
  86. dp->drv.get_display_height = raw_get_display_height;
  87. dp->drv.display = raw_display;
  88. dp->drv.handle_resize = raw_handle_resize;
  89. dp->drv.get_event = raw_get_event;
  90. dp->drv.set_mouse = NULL;
  91. dp->drv.set_cursor = NULL;
  92. return 0;
  93. }
  94. #endif /* !__KERNEL__ */