shsize.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2022, Egahp
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdio.h>
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include "csh.h"
  12. /*!< shsize */
  13. static int shsize(int argc, char **argv)
  14. {
  15. chry_shell_t *csh = (void *)argv[argc + 1];
  16. char *prgname = argv[0];
  17. if ((argc == 2) && !strcmp(argv[1], "--update")) {
  18. if (5 != csh->rl.sput(&csh->rl, "\033[18t", 5)) {
  19. csh_printf(csh, "Failed to request update\r\n");
  20. return -1;
  21. }
  22. return 0;
  23. } else if ((argc == 4) && !strcmp(argv[1], "--config")) {
  24. int row = atoi(argv[2]);
  25. int col = atoi(argv[3]);
  26. if (row > 10 && row < 4096) {
  27. csh->rl.term.row = row;
  28. } else {
  29. csh_printf(csh, "Illegal row %d\r\n", row);
  30. }
  31. if (col > 10 && col < 4096) {
  32. csh->rl.term.col = col;
  33. } else {
  34. csh_printf(csh, "Illegal col %d\r\n", col);
  35. }
  36. } else if (argc == 1) {
  37. } else {
  38. csh_printf(csh, "Usage: %s [--update | --config <row> <col>\r\n", prgname);
  39. return 0;
  40. }
  41. csh_printf(csh, "Window config to row:%d col:%d\r\n", csh->rl.term.row, csh->rl.term.col);
  42. return 0;
  43. }
  44. CSH_SCMD_EXPORT(shsize, );