title.c

来自「umon bootloader source code, support mip」· C语言 代码 · 共 69 行

C
69
字号
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef BUILD_WITH_VCC
#define WIN32_LEAN_AND_MEAN
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <io.h>
#include <winsock2.h>
#endif

#ifndef BUILD_WITH_VCC
void
SetConsoleTitle(char *title)
{
	char *term, *tp;

	term = getenv("TERM");
	if ((term == (char *)0) || (*term == 0)) {
		term = "xterm";
	}
	else {
		tp = term;
		while(*tp) {
			*tp = tolower(*tp);
			tp++;
		}
	}

	if(strcmp(term,"xterm") == 0) {
		printf("\033]2;%s\007",title);
	}
	else if(strcmp(term,"cygwin") == 0) {
		printf("\033]2;%s\007",title);
	}
	else if(strncmp(term,"vt10",4) == 0) {
		printf("\033]2;%s\007",title);
		printf("\033]1;%s\007",title);
	}
	else {
		fprintf(stderr,"title: Terminal type '%s' unrecognized\n",term);
	}
}
#endif

int
main(int argc,char *argv[])
{
	char	string[256];
	char	*title;

	if (argc == 1) {
		title = getenv("TITLE");
		if (title)
			SetConsoleTitle(title);
		else
			SetConsoleTitle("");
	}
	else if (argc == 2)
		SetConsoleTitle(argv[1]);
	else {
		fprintf(stderr,"%s [new title]\n",argv[0]);
		exit(1);
	}
	exit(0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?