tput.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /*
  3. * Copyright (C) 2023 Ferass El Hafidi <vitali64pmemail@protonmail.com>
  4. */
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <errno.h>
  8. #include <unistd.h>
  9. /* Requirements in common.h */
  10. #define REQ_PRINT_USAGE
  11. #define REQ_ERRPRINT
  12. #include "../common/common.h"
  13. #define DESCRIPTION "Change terminal characteristics."
  14. #define OPERANDS "init|clear|reset"
  15. int main(int argc, char *argv[]) {
  16. int argument;
  17. char *argv0 = strdup(argv[0]);
  18. if (argc < 2)
  19. return 1 + print_usage(argv0, DESCRIPTION, OPERANDS, VERSION);
  20. while ((argument = getopt(argc, argv, "")) != -1 ) {
  21. /* To be used when -T gets implemented */
  22. if (argument == '?')
  23. return 1 + print_usage(argv0,
  24. DESCRIPTION, OPERANDS, VERSION);
  25. } argc -= optind; argv += optind;
  26. if (!strcmp(argv[0], "init") ||
  27. !strcmp(argv[0], "reset")) /* init/reset */
  28. /* According to POSIX.1-2017 tput(1):
  29. * > The difference between resetting and initializing a
  30. * > terminal is left unspecified
  31. */
  32. write(STDOUT_FILENO, "\033c", 3);
  33. else if (!strcmp(argv[0], "clear")) /* clear */
  34. write(STDOUT_FILENO, "\033[1;1H\033[2J", 11);
  35. else return 3 + print_usage(argv0, DESCRIPTION, OPERANDS, VERSION);
  36. return errprint(argv0, NULL, errno);
  37. }