From e54c6af754423a7767e836a1c3b25a5e2de0eba8 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Tue, 8 May 2018 17:19:28 +0900 Subject: [PATCH] move set command to an app named term-set --- apps/sh.c | 72 ----------------------------------------------- apps/term-set.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 72 deletions(-) create mode 100644 apps/term-set.c diff --git a/apps/sh.c b/apps/sh.c index 7691bd36..38f36a8d 100644 --- a/apps/sh.c +++ b/apps/sh.c @@ -912,77 +912,6 @@ uint32_t shell_cmd_exit(int argc, char * argv[]) { return -1; } -uint32_t shell_cmd_set(int argc, char * argv[]) { - char * term = getenv("TERM"); - if (!term || strstr(term, "toaru") != term) { - fprintf(stderr, "Unrecognized terminal. These commands are for the とある terminal only.\n"); - return 1; - } - if (argc < 2) { - fprintf(stderr, "%s: expected argument\n", argv[0]); - return 1; - } - - if (!strcmp(argv[1], "alpha")) { - if (argc < 3) { - fprintf(stderr, "%s %s [0 or 1]\n", argv[0], argv[1]); - return 1; - } - int i = atoi(argv[2]); - if (i) { - printf("\033[2001z"); - } else { - printf("\033[2000z"); - } - fflush(stdout); - return 0; - } else if (!strcmp(argv[1], "scale")) { - if (argc < 3) { - fprintf(stderr, "%s %s [floating point size, 1.0 = normal]\n", argv[0], argv[1]); - return 1; - } - printf("\033[1555;%sz", argv[2]); - fflush(stdout); - return 0; - } else if (!strcmp(argv[1], "gamma")) { - if (argc < 3) { - fprintf(stderr, "%s %s [floating point gamma, 1.7 = normal]\n", argv[0], argv[1]); - return 1; - } - printf("\033[1556;%sz", argv[2]); - fflush(stdout); - return 0; - } else if (!strcmp(argv[1], "sdf")) { - if (argc < 3) { - fprintf(stderr, "%s %s [sdf enabled, 1 = yes]\n", argv[0], argv[1]); - return 1; - } - printf("\033[1557;%sz", argv[2]); - fflush(stdout); - return 0; - } else if (!strcmp(argv[1], "size")) { - if (argc < 4) { - fprintf(stderr, "%s %s [width] [height]\n", argv[0], argv[1]); - return 1; - } - printf("\033[3000;%s;%sz", argv[2], argv[3]); - fflush(stdout); - return 0; - } else if (!strcmp(argv[1], "--help")) { - fprintf(stderr, "Available arguments:\n" - " alpha - alpha transparency enabled / disabled\n" - " scale - font scaling\n" - " size - terminal width/height in characters\n" - " force-raw - sets terminal to raw mode before commands\n" - " no-force-raw - disables forced raw mode\n" - ); - return 0; - } - - fprintf(stderr, "%s: unrecognized argument\n", argv[0]); - return 1; -} - uint32_t shell_cmd_help(int argc, char * argv[]) { show_version(); @@ -1003,5 +932,4 @@ void install_commands() { shell_install_command("export", shell_cmd_export, "set environment variables"); shell_install_command("help", shell_cmd_help, "display this help text"); shell_install_command("history", shell_cmd_history, "list command history"); - shell_install_command("set", shell_cmd_set, "enable special terminal options"); } diff --git a/apps/term-set.c b/apps/term-set.c new file mode 100644 index 00000000..59bf8d54 --- /dev/null +++ b/apps/term-set.c @@ -0,0 +1,74 @@ +#include +#include +#include + +int main(int argc, char * argv[]) { + char * term = getenv("TERM"); + if (!term || strstr(term, "toaru") != term) { + fprintf(stderr, "Unrecognized terminal. These commands are for the とある terminal only.\n"); + return 1; + } + if (argc < 2) { + fprintf(stderr, "%s: expected argument\n", argv[0]); + return 1; + } + + if (!strcmp(argv[1], "alpha")) { + if (argc < 3) { + fprintf(stderr, "%s %s [0 or 1]\n", argv[0], argv[1]); + return 1; + } + int i = atoi(argv[2]); + if (i) { + printf("\033[2001z"); + } else { + printf("\033[2000z"); + } + fflush(stdout); + return 0; + } else if (!strcmp(argv[1], "scale")) { + if (argc < 3) { + fprintf(stderr, "%s %s [floating point size, 1.0 = normal]\n", argv[0], argv[1]); + return 1; + } + printf("\033[1555;%sz", argv[2]); + fflush(stdout); + return 0; + } else if (!strcmp(argv[1], "gamma")) { + if (argc < 3) { + fprintf(stderr, "%s %s [floating point gamma, 1.7 = normal]\n", argv[0], argv[1]); + return 1; + } + printf("\033[1556;%sz", argv[2]); + fflush(stdout); + return 0; + } else if (!strcmp(argv[1], "sdf")) { + if (argc < 3) { + fprintf(stderr, "%s %s [sdf enabled, 1 = yes]\n", argv[0], argv[1]); + return 1; + } + printf("\033[1557;%sz", argv[2]); + fflush(stdout); + return 0; + } else if (!strcmp(argv[1], "size")) { + if (argc < 4) { + fprintf(stderr, "%s %s [width] [height]\n", argv[0], argv[1]); + return 1; + } + printf("\033[3000;%s;%sz", argv[2], argv[3]); + fflush(stdout); + return 0; + } else if (!strcmp(argv[1], "--help")) { + fprintf(stderr, "Available arguments:\n" + " alpha - alpha transparency enabled / disabled\n" + " scale - font scaling\n" + " size - terminal width/height in characters\n" + " force-raw - sets terminal to raw mode before commands\n" + " no-force-raw - disables forced raw mode\n" + ); + return 0; + } + + fprintf(stderr, "%s: unrecognized argument\n", argv[0]); + return 1; +}