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.

lineconsole.c 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. /** @file
  21. *
  22. * Line-based console
  23. *
  24. */
  25. #include <stdint.h>
  26. #include <stddef.h>
  27. #include <ipxe/ansiesc.h>
  28. #include <ipxe/lineconsole.h>
  29. /**
  30. * Print a character to a line-based console
  31. *
  32. * @v character Character to be printed
  33. * @ret print Print line
  34. */
  35. size_t line_putchar ( struct line_console *line, int character ) {
  36. /* Strip ANSI escape sequences */
  37. character = ansiesc_process ( &line->ctx, character );
  38. if ( character < 0 )
  39. return 0;
  40. /* Ignore carriage return */
  41. if ( character == '\r' )
  42. return 0;
  43. /* Treat newline as a terminator */
  44. if ( character == '\n' )
  45. character = 0;
  46. /* Add character to buffer */
  47. line->buffer[line->index++] = character;
  48. /* Do nothing more unless we reach end-of-line (or end-of-buffer) */
  49. if ( ( character != 0 ) &&
  50. ( line->index < ( line->len - 1 /* NUL */ ) ) ) {
  51. return 0;
  52. }
  53. /* Reset to start of buffer */
  54. line->index = 0;
  55. return 1;
  56. }