Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

117 строки
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. #if !defined(__KERNEL__)
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include "cucul.h"
  22. #include "caca.h"
  23. #include "caca_internals.h"
  24. static int raw_init_graphics(caca_display_t *dp)
  25. {
  26. int width = cucul_get_canvas_width(dp->cv);
  27. int height = cucul_get_canvas_height(dp->cv);
  28. char const *geometry;
  29. #if defined(HAVE_GETENV)
  30. geometry = getenv("CACA_GEOMETRY");
  31. if(geometry && *geometry)
  32. sscanf(geometry, "%ux%u", &width, &height);
  33. #endif
  34. dp->resize.allow = 1;
  35. cucul_set_canvas_size(dp->cv, width ? width : 80, height ? height : 24);
  36. dp->resize.allow = 0;
  37. return 0;
  38. }
  39. static int raw_end_graphics(caca_display_t *dp)
  40. {
  41. return 0;
  42. }
  43. static int raw_set_display_title(caca_display_t *dp, char const *title)
  44. {
  45. return -1;
  46. }
  47. static int raw_get_display_width(caca_display_t const *dp)
  48. {
  49. return 0;
  50. }
  51. static int raw_get_display_height(caca_display_t const *dp)
  52. {
  53. return 0;
  54. }
  55. static void raw_display(caca_display_t *dp)
  56. {
  57. void *buffer;
  58. size_t len;
  59. buffer = cucul_export_memory(dp->cv, "caca", &len);
  60. if(!buffer)
  61. return;
  62. fwrite(buffer, len, 1, stdout);
  63. fflush(stdout);
  64. free(buffer);
  65. }
  66. static void raw_handle_resize(caca_display_t *dp)
  67. {
  68. ;
  69. }
  70. static int raw_get_event(caca_display_t *dp, caca_privevent_t *ev)
  71. {
  72. ev->type = CACA_EVENT_NONE;
  73. return 0;
  74. }
  75. /*
  76. * Driver initialisation
  77. */
  78. int raw_install(caca_display_t *dp)
  79. {
  80. dp->drv.id = CACA_DRIVER_RAW;
  81. dp->drv.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__ */