📄 setterm.c
字号:
if (opt_repeat && vcterm) { if (opt_rep_on) printf("\033[?8h"); else printf("\033[?8l"); } /* -appcursorkeys [on|off]. Vc only (vt102) */ if (opt_appcursorkeys && vcterm) { if (opt_appck_on) printf("\033[?1h"); else printf("\033[?1l"); }#if 0 /* -snow [on|off]. Vc only. */ if (opt_snow && vcterm) { if (opt_sn_on) printf("%s%s%s", DCS, "snow.on", ST); else printf("%s%s%s", DCS, "snow.off", ST); } /* -softscroll [on|off]. Vc only. */ if (opt_softscroll && vcterm) { if (opt_so_on) printf("%s%s%s", DCS, "softscroll.on", ST); else printf("%s%s%s", DCS, "softscroll.off", ST); }#endif /* -default. Vc sets default rendition, otherwise clears all * attributes. */ if (opt_default) { if (vcterm) printf("\033[0m"); else putp(ti_entry("sgr0")); } /* -foreground black|red|green|yellow|blue|magenta|cyan|white|default. * Vc only (ANSI). */ if (opt_foreground && vcterm) { printf("%s%s%c%s", ESC, "[3", '0' + opt_fo_color, "m"); } /* -background black|red|green|yellow|blue|magenta|cyan|white|default. * Vc only (ANSI). */ if (opt_background && vcterm) { printf("%s%s%c%s", ESC, "[4", '0' + opt_ba_color, "m"); } /* -ulcolor black|red|green|yellow|blue|magenta|cyan|white|default. * Vc only. */ if (opt_ulcolor && vcterm) { printf("\033[1;%d]", opt_ul_color); } /* -hbcolor black|red|green|yellow|blue|magenta|cyan|white|default. * Vc only. */ if (opt_hbcolor && vcterm) { printf("\033[2;%d]", opt_hb_color); } /* -inversescreen [on|off]. Vc only (vt102). */ if (opt_inversescreen) { if (vcterm) { if (opt_invsc_on) printf("\033[?5h"); else printf("\033[?5l"); } } /* -bold [on|off]. Vc behaves as expected, otherwise off turns off * all attributes. */ if (opt_bold) { if (opt_bo_on) putp(ti_entry("bold")); else { if (vcterm) printf("%s%s", ESC, "[22m"); else putp(ti_entry("sgr0")); } } /* -half-bright [on|off]. Vc behaves as expected, otherwise off turns off * all attributes. */ if (opt_halfbright) { if (opt_hb_on) putp(ti_entry("dim")); else { if (vcterm) printf("%s%s", ESC, "[22m"); else putp(ti_entry("sgr0")); } } /* -blink [on|off]. Vc behaves as expected, otherwise off turns off * all attributes. */ if (opt_blink) { if (opt_bl_on) putp(ti_entry("blink")); else { if (vcterm) printf("%s%s", ESC, "[25m"); else putp(ti_entry("sgr0")); } } /* -reverse [on|off]. Vc behaves as expected, otherwise off turns * off all attributes. */ if (opt_reverse) { if (opt_re_on) putp(ti_entry("rev")); else { if (vcterm) printf("%s%s", ESC, "[27m"); else putp(ti_entry("sgr0")); } } /* -underline [on|off]. */ if (opt_underline) { if (opt_un_on) putp(ti_entry("smul")); else putp(ti_entry("rmul")); } /* -store. Vc only. */ if (opt_store && vcterm) { printf("\033[8]"); } /* -clear [all|rest]. */ if (opt_clear) { if (opt_cl_all) putp(ti_entry("clear")); else putp(ti_entry("ed")); } /* -tabs Vc only. */ if (opt_tabs && vcterm) { int i; if (opt_tb_array[0] == -1) show_tabs(); else { for(i=0; opt_tb_array[i] > 0; i++) printf("\033[%dG\033H", opt_tb_array[i]); putchar('\r'); } } /* -clrtabs Vc only. */ if (opt_clrtabs && vcterm) { int i; if (opt_tb_array[0] == -1) printf("\033[3g"); else for(i=0; opt_tb_array[i] > 0; i++) printf("\033[%dG\033[g", opt_tb_array[i]); putchar('\r'); } /* -regtabs Vc only. */ if (opt_regtabs && vcterm) { int i; printf("\033[3g\r"); for(i=opt_rt_len+1; i<=160; i+=opt_rt_len) printf("\033[%dC\033H",opt_rt_len); putchar('\r'); } /* -blank [0-60]. */ if (opt_blank && vcterm) printf("\033[9;%d]", opt_bl_min); /* -powersave [on|vsync|hsync|powerdown|off] (console) */ if (opt_powersave) { char ioctlarg[2]; ioctlarg[0] = 10; /* powersave */ ioctlarg[1] = opt_ps_mode; if (ioctl(0,TIOCLINUX,ioctlarg)) fprintf(stderr,_("cannot (un)set powersave mode\n")); } /* -powerdown [0-60]. */ if (opt_powerdown) { printf("\033[14;%d]", opt_pd_min); }#if 0 /* -standout [num]. */ if (opt_standout) /* nothing */;#endif /* -snap [1-NR_CONS]. */ if (opt_snap || opt_append) { FILE *F; F = fopen(opt_sn_name, opt_snap ? "w" : "a"); if (!F) { perror(opt_sn_name); fprintf(stderr,("setterm: can not open dump file %s for output\n"), opt_sn_name); exit(-1); } screendump(opt_sn_num, F); fclose(F); } /* -msg [on|off]. */ if (opt_msg && vcterm) { if (opt_msg_on) /* 7 -- Enable printk's to console */ result = klogctl(7, NULL, 0); else /* 6 -- Disable printk's to console */ result = klogctl(6, NULL, 0); if (result != 0) printf(_("klogctl error: %s\n"), strerror(errno)); } /* -msglevel [0-8] */ if (opt_msglevel && vcterm) { /* 8 -- Set level of messages printed to console */ result = klogctl(8, NULL, opt_msglevel_num); if (result != 0) printf(_("klogctl error: %s\n"), strerror(errno)); } /* -blength [0-2000] */ if (opt_blength && vcterm) { printf("\033[11;%d]", opt_blength_l); } /* -bfreq freqnumber */ if (opt_bfreq && vcterm) { printf("\033[10;%d]", opt_bfreq_f); }}static voidscreendump(int vcnum, FILE *F) { char infile[MAXPATHLEN]; unsigned char header[4]; unsigned int rows, cols; int fd, i, j; char *inbuf, *outbuf, *p, *q; sprintf(infile, "/dev/vcsa%d", vcnum); fd = open(infile, O_RDONLY); if (fd < 0 && vcnum == 0) { /* vcsa0 is often called vcsa */ sprintf(infile, "/dev/vcsa"); fd = open(infile, O_RDONLY); } if (fd < 0) { /* try devfs name - for zero vcnum just /dev/vcc/a */ /* some gcc's warn for %.u - add 0 */ sprintf(infile, "/dev/vcc/a%.0u", vcnum); fd = open(infile, O_RDONLY); } if (fd < 0) { sprintf(infile, "/dev/vcsa%d", vcnum); goto try_ioctl; } if (read(fd, header, 4) != 4) goto try_ioctl; rows = header[0]; cols = header[1]; if (rows * cols == 0) goto try_ioctl; inbuf = malloc(rows*cols*2); outbuf = malloc(rows*(cols+1)); if(!inbuf || !outbuf) { fputs(_("Out of memory"), stderr); exit(1); } if (read(fd, inbuf, rows*cols*2) != rows*cols*2) { fprintf(stderr, _("Error reading %s\n"), infile); exit(1); } p = inbuf; q = outbuf; for(i=0; i<rows; i++) { for(j=0; j<cols; j++) { *q++ = *p; p += 2; } while(j-- > 0 && q[-1] == ' ') q--; *q++ = '\n'; } if (fwrite(outbuf, 1, q-outbuf, F) != q-outbuf) { fprintf(stderr, _("Error writing screendump\n")); exit(1); } return;try_ioctl: {#define NUM_COLS 160#define NUM_ROWS 75 char buf[NUM_COLS+1]; unsigned char screenbuf[NUM_ROWS*NUM_COLS]; screenbuf[0] = 0; screenbuf[1] = (unsigned char) vcnum; if (ioctl(0,TIOCLINUX,screenbuf) < 0) { fprintf(stderr,_("couldn't read %s, and cannot ioctl dump\n"), infile); exit(1); } rows = screenbuf[0]; cols = screenbuf[1]; for (i=0; i<rows; i++) { strncpy(buf, screenbuf+2+(cols*i), cols); buf[cols] = '\0'; j = cols; while (--j && (buf[j] == ' ')) buf[j] = '\0'; fputs(buf,F); fputc('\n',F); } }}intmain(int argc, char **argv) { int bad_arg = FALSE; /* Set if error in arguments. */ int arg, modifier; char *term; /* Terminal type. */ int vcterm; /* Set if terminal is a virtual console. */ setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); if (argc < 2) bad_arg = TRUE; /* Parse arguments. */ for (arg = 1; arg < argc;) { if (*argv[arg] == '-') { /* Parse a single option. */ for (modifier = arg + 1; modifier < argc; modifier++) { if (*argv[modifier] == '-') break; } parse_option(argv[arg] + 1, modifier - arg - 1, &argv[arg + 1], &bad_arg); arg = modifier; } else { bad_arg = TRUE; arg++; } } /* Display syntax message if error in arguments. */ if (bad_arg) { usage(argv[0]); exit(1); } /* Find out terminal name. */ if (opt_term) { term = opt_te_terminal_name; } else { term = getenv("TERM"); if (term == NULL) { fprintf(stderr, _("%s: $TERM is not defined.\n"), argv[0]); exit(1); } } /* Find terminfo entry. */ setupterm(term, 1, (int *)0); /* See if the terminal is a virtual console terminal. */ vcterm = (!strncmp(term, "con", 3) || !strncmp(term, "linux", 5)); /* Perform the selected options. */ perform_sequence(vcterm); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -