move set command to an app named term-set

This commit is contained in:
K. Lange 2018-05-08 17:19:28 +09:00
parent 8ccbcb001c
commit e54c6af754
2 changed files with 74 additions and 72 deletions

View File

@ -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");
}

74
apps/term-set.c Normal file
View File

@ -0,0 +1,74 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}