Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

lineconsole.c 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. /** @file
  20. *
  21. * Line-based console
  22. *
  23. */
  24. #include <stdint.h>
  25. #include <stddef.h>
  26. #include <ipxe/ansiesc.h>
  27. #include <ipxe/lineconsole.h>
  28. /**
  29. * Print a character to a line-based console
  30. *
  31. * @v character Character to be printed
  32. * @ret print Print line
  33. */
  34. size_t line_putchar ( struct line_console *line, int character ) {
  35. /* Strip ANSI escape sequences */
  36. character = ansiesc_process ( &line->ctx, character );
  37. if ( character < 0 )
  38. return 0;
  39. /* Ignore carriage return */
  40. if ( character == '\r' )
  41. return 0;
  42. /* Treat newline as a terminator */
  43. if ( character == '\n' )
  44. character = 0;
  45. /* Add character to buffer */
  46. line->buffer[line->index++] = character;
  47. /* Do nothing more unless we reach end-of-line (or end-of-buffer) */
  48. if ( ( character != 0 ) &&
  49. ( line->index < ( line->len - 1 /* NUL */ ) ) ) {
  50. return 0;
  51. }
  52. /* Reset to start of buffer */
  53. line->index = 0;
  54. return 1;
  55. }