2 * Copyright (c) 1994-1996 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software withough specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/usr.sbin/vidcontrol/vidcontrol.c,v 1.32.2.7 2002/09/15 22:31:50 dd Exp $
29 * $DragonFly: src/usr.sbin/vidcontrol/vidcontrol.c,v 1.15 2008/11/02 21:52:46 swildner Exp $
32 #include <machine/console.h>
34 #include <sys/consio.h>
35 #include <sys/errno.h>
36 #include <sys/types.h>
51 #define DATASIZE(x) ((x).w * (x).h * 256 / 8)
56 #define DUMP_FMT_REV 1
59 char legal_colors
[16][16] = {
60 "black", "blue", "green", "cyan",
61 "red", "magenta", "brown", "white",
62 "grey", "lightblue", "lightgreen", "lightcyan",
63 "lightred", "lightmagenta", "yellow", "lightwhite"
68 vid_info_t console_info
;
69 unsigned char screen_map
[256];
70 int video_mode_number
;
71 struct video_info video_mode_info
;
80 int video_mode_changed
;
81 int normal_fore_color
, normal_back_color
;
82 int revers_fore_color
, revers_back_color
;
85 struct video_info new_mode_info
;
89 * Initialize revert data.
91 * NOTE: the following parameters are not yet saved/restored:
93 * screen saver timeout
95 * mouse character and mouse show/hide state
96 * vty switching on/off state
105 if (ioctl(0, VT_GETACTIVE
, &cur_info
.active_vty
) == -1)
106 errc(1, errno
, "getting active vty");
108 cur_info
.console_info
.size
= sizeof(cur_info
.console_info
);
110 if (ioctl(0, CONS_GETINFO
, &cur_info
.console_info
) == -1)
111 errc(1, errno
, "getting console information");
113 if (ioctl(0, GIO_SCRNMAP
, &cur_info
.screen_map
) == -1)
114 errc(1, errno
, "getting screen map");
116 if (ioctl(0, CONS_GET
, &cur_info
.video_mode_number
) == -1)
117 errc(1, errno
, "getting video mode number");
119 cur_info
.video_mode_info
.vi_mode
= cur_info
.video_mode_number
;
121 if (ioctl(0, CONS_MODEINFO
, &cur_info
.video_mode_info
) == -1)
122 errc(1, errno
, "getting video mode parameters");
124 normal_fore_color
= cur_info
.console_info
.mv_norm
.fore
;
125 normal_back_color
= cur_info
.console_info
.mv_norm
.back
;
126 revers_fore_color
= cur_info
.console_info
.mv_rev
.fore
;
127 revers_back_color
= cur_info
.console_info
.mv_rev
.back
;
132 * If something goes wrong along the way we call revert() to go back to the
133 * console state we came from (which is assumed to be working).
135 * NOTE: please also read the comments of init().
143 ioctl(0, VT_ACTIVATE
, (caddr_t
) (long) cur_info
.active_vty
);
145 fprintf(stderr
, "\e[=%dA", cur_info
.console_info
.mv_ovscan
);
146 fprintf(stderr
, "\e[=%dF", cur_info
.console_info
.mv_norm
.fore
);
147 fprintf(stderr
, "\e[=%dG", cur_info
.console_info
.mv_norm
.back
);
148 fprintf(stderr
, "\e[=%dH", cur_info
.console_info
.mv_rev
.fore
);
149 fprintf(stderr
, "\e[=%dI", cur_info
.console_info
.mv_rev
.back
);
151 ioctl(0, PIO_SCRNMAP
, &cur_info
.screen_map
);
152 ioctl(0, CONS_SET
, &cur_info
.video_mode_number
);
154 if (cur_info
.video_mode_info
.vi_flags
& V_INFO_GRAPHICS
) {
155 size
[0] = cur_info
.video_mode_info
.vi_width
/ 8;
156 size
[1] = cur_info
.video_mode_info
.vi_height
/
157 cur_info
.console_info
.font_size
;
158 size
[2] = cur_info
.console_info
.font_size
;
160 ioctl(0, KDRASTER
, size
);
166 * Print a short usage string describing all options, then exit.
173 "usage: vidcontrol [-CdLPpx] [-b color] [-c appearance]"
174 " [-f [size] file]\n"
175 " [-g geometry] [-h size] [-i adapter | mode]"
177 " [-M char] [-m on | off] [-r foreground"
179 " [-S on | off] [-s number] [-t N | off]"
181 " [foreground [background]] [show]\n");
188 * Retrieve the next argument from the command line (for options that require
189 * more than one argument).
193 nextarg(int ac
, char **av
, int *indp
, int oc
, int strict
)
196 return(av
[(*indp
)++]);
200 errx(1, "option requires two arguments -- %c", oc
);
208 * Guess which file to open. Try to open each combination of a specified set
209 * of file name components.
213 openguess(const char *a
[], const char *b
[], const char *c
[], const char *d
[], char **name
)
218 for (i
= 0; a
[i
] != NULL
; i
++) {
219 for (j
= 0; b
[j
] != NULL
; j
++) {
220 for (k
= 0; c
[k
] != NULL
; k
++) {
221 for (l
= 0; d
[l
] != NULL
; l
++) {
222 asprintf(name
, "%s%s%s%s",
223 a
[i
], b
[j
], c
[k
], d
[l
]);
225 f
= fopen(*name
, "r");
241 * Load a screenmap from a file and set it.
245 load_scrnmap(char *filename
)
251 const char *a
[] = {"", SCRNMAP_PATH
, NULL
};
252 const char *b
[] = {filename
, NULL
};
253 const char *c
[] = {"", ".scm", NULL
};
254 const char *d
[] = {"", NULL
};
256 fd
= openguess(a
, b
, c
, d
, &name
);
260 errx(1, "screenmap file not found");
263 size
= sizeof(scrnmap
);
265 if (decode(fd
, (char *)&scrnmap
, size
) != size
) {
268 if (fread(&scrnmap
, 1, size
, fd
) != (size_t)size
) {
271 errx(1, "bad screenmap file");
275 if (ioctl(0, PIO_SCRNMAP
, &scrnmap
) == -1) {
277 errc(1, errno
, "loading screenmap");
285 * Set the default screenmap.
289 load_default_scrnmap(void)
294 for (i
= 0; i
< 256; i
++)
295 *((char*)&scrnmap
+ i
) = i
;
297 if (ioctl(0, PIO_SCRNMAP
, &scrnmap
) == -1) {
299 errc(1, errno
, "loading default screenmap");
305 * Print the current screenmap to stdout.
311 unsigned char map
[256];
314 if (ioctl(0, GIO_SCRNMAP
, &map
) == -1) {
316 errc(1, errno
, "getting screenmap");
319 for (i
=0; i
<sizeof(map
); i
++) {
320 if (i
> 0 && i
% 16 == 0)
321 fprintf(stdout
, "\n");
324 fprintf(stdout
, " %02x", map
[i
]);
326 fprintf(stdout
, " %03d", map
[i
]);
329 fprintf(stdout
, "\n");
334 * Determine a file's size.
342 if (fstat(fileno(file
), &sb
) == 0)
350 * Load a font from file and set it.
354 load_font(char *type
, char *filename
)
358 unsigned long io
= 0; /* silence stupid gcc(1) in the Wall mode */
359 char *name
, *fontmap
, size_sufx
[6];
360 const char *a
[] = {"", FONT_PATH
, NULL
};
361 const char *b
[] = {filename
, NULL
};
362 const char *c
[] = {"", size_sufx
, NULL
};
363 const char *d
[] = {"", ".fnt", NULL
};
370 } sizes
[] = {{8, 16, PIO_FONT8x16
},
371 {8, 14, PIO_FONT8x14
},
375 vinfo
.size
= sizeof(vinfo
);
377 if (ioctl(0, CONS_GETINFO
, &vinfo
) == -1) {
379 errc(1, errno
, "obtaining current video mode parameters");
382 snprintf(size_sufx
, sizeof(size_sufx
), "-8x%d", vinfo
.font_size
);
384 fd
= openguess(a
, b
, c
, d
, &name
);
388 errx(1, "%s: can't load font file", filename
);
393 if (sscanf(type
, "%dx%d", &w
, &h
) == 2) {
394 for (i
= 0; sizes
[i
].w
!= 0; i
++) {
395 if (sizes
[i
].w
== w
&& sizes
[i
].h
== h
) {
396 size
= DATASIZE(sizes
[i
]);
398 font_height
= sizes
[i
].h
;
405 errx(1, "%s: bad font size specification", type
);
408 /* Apply heuristics */
413 size
= DATASIZE(sizes
[0]);
414 fontmap
= (char*) malloc(size
);
415 dsize
[0] = decode(fd
, fontmap
, size
);
416 dsize
[1] = fsize(fd
);
420 for (j
= 0; j
< 2; j
++) {
421 for (i
= 0; sizes
[i
].w
!= 0; i
++) {
422 if (DATASIZE(sizes
[i
]) == dsize
[j
]) {
425 font_height
= sizes
[i
].h
;
435 errx(1, "%s: can't guess font size", filename
);
441 fontmap
= (char*) malloc(size
);
443 if (decode(fd
, fontmap
, size
) != size
) {
445 if (fsize(fd
) != size
||
446 fread(fontmap
, 1, size
, fd
) != (size_t)size
) {
450 errx(1, "%s: bad font file", filename
);
454 if (ioctl(0, io
, fontmap
) == -1) {
456 errc(1, errno
, "loading font");
465 * Set the timeout for the screensaver.
469 set_screensaver_timeout(char *arg
)
473 if (!strcmp(arg
, "off")) {
478 if ((*arg
== '\0') || (nsec
< 1)) {
480 errx(1, "argument must be a positive number");
484 if (ioctl(0, CONS_BLANKTIME
, &nsec
) == -1) {
486 errc(1, errno
, "setting screensaver period");
492 * Set the cursor's shape/type.
496 set_cursor_type(char *appearance
)
500 if (!strcmp(appearance
, "normal"))
502 else if (!strcmp(appearance
, "blink"))
504 else if (!strcmp(appearance
, "destructive"))
508 errx(1, "argument to -c must be normal, blink or destructive");
511 if (ioctl(0, CONS_CURSORTYPE
, &type
) == -1) {
513 errc(1, errno
, "setting cursor type");
519 * Set the video mode.
523 video_mode(int argc
, char **argv
, int *mode_index
)
527 unsigned long mode_num
;
528 } modes
[] = {{ "80x25", M_VGA_C80x25
},
529 { "80x30", M_VGA_C80x30
},
530 { "80x43", M_ENH_C80x43
},
531 { "80x50", M_VGA_C80x50
},
532 { "80x60", M_VGA_C80x60
},
533 { "132x25", M_VESA_C132x25
},
534 { "132x43", M_VESA_C132x43
},
535 { "132x50", M_VESA_C132x50
},
536 { "132x60", M_VESA_C132x60
},
537 { "VGA_40x25", M_VGA_C40x25
},
538 { "VGA_80x25", M_VGA_C80x25
},
539 { "VGA_80x30", M_VGA_C80x30
},
540 { "VGA_80x50", M_VGA_C80x50
},
541 { "VGA_80x60", M_VGA_C80x60
},
543 { "VGA_90x25", M_VGA_C90x25
},
544 { "VGA_90x30", M_VGA_C90x30
},
545 { "VGA_90x43", M_VGA_C90x43
},
546 { "VGA_90x50", M_VGA_C90x50
},
547 { "VGA_90x60", M_VGA_C90x60
},
549 { "VGA_320x200", M_CG320
},
550 { "EGA_80x25", M_ENH_C80x25
},
551 { "EGA_80x43", M_ENH_C80x43
},
552 { "VESA_132x25", M_VESA_C132x25
},
553 { "VESA_132x43", M_VESA_C132x43
},
554 { "VESA_132x50", M_VESA_C132x50
},
555 { "VESA_132x60", M_VESA_C132x60
},
556 { "VESA_800x600", M_VESA_800x600
},
560 int new_mode_num
= 0;
565 * Parse the video mode argument...
568 if (*mode_index
< argc
) {
569 if (!strncmp(argv
[*mode_index
], "MODE_", 5)) {
570 if (!isdigit(argv
[*mode_index
][5]))
571 errx(1, "invalid video mode number");
573 new_mode_num
= atoi(&argv
[*mode_index
][5]);
575 for (i
= 0; modes
[i
].name
!= NULL
; ++i
) {
576 if (!strcmp(argv
[*mode_index
], modes
[i
].name
)) {
577 new_mode_num
= modes
[i
].mode_num
;
582 if (modes
[i
].name
== NULL
)
583 errx(1, "invalid video mode name");
587 * Collect enough information about the new video mode...
590 new_mode_info
.vi_mode
= new_mode_num
;
592 if (ioctl(0, CONS_MODEINFO
, &new_mode_info
) == -1) {
594 errc(1, errno
, "obtaining new video mode parameters");
598 * Try setting the new mode.
601 if (ioctl(0, CONS_SET
, &new_mode_num
) == -1) {
603 errc(1, errno
, "setting video mode");
607 * For raster modes it's not enough to just set the mode.
608 * We also need to explicitly set the raster mode.
611 if (new_mode_info
.vi_flags
& V_INFO_GRAPHICS
) {
614 if (font_height
== 0)
615 font_height
= cur_info
.console_info
.font_size
;
617 size
[2] = font_height
;
621 if ((vesa_cols
* 8 > new_mode_info
.vi_width
) ||
623 size
[0] = new_mode_info
.vi_width
/ 8;
630 if ((vesa_rows
* font_height
> new_mode_info
.vi_height
) ||
632 size
[1] = new_mode_info
.vi_height
/
638 /* set raster mode */
640 if (ioctl(0, KDRASTER
, size
)) {
642 errc(1, errno
, "activating raster display");
646 video_mode_changed
= 1;
654 * Return the number for a specified color name.
658 get_color_number(char *color
)
662 for (i
=0; i
<16; i
++) {
663 if (!strcmp(color
, legal_colors
[i
]))
671 * Get normal text and background colors.
675 get_normal_colors(int argc
, char **argv
, int *color_index
)
679 if (*color_index
< argc
&&
680 (color
= get_color_number(argv
[*color_index
])) != -1) {
682 normal_fore_color
= color
;
685 if (*color_index
< argc
&&
686 (color
= get_color_number(argv
[*color_index
])) != -1) {
688 normal_back_color
= color
;
695 * Get reverse text and background colors.
699 get_reverse_colors(int argc
, char **argv
, int *color_index
)
703 if ((color
= get_color_number(argv
[*(color_index
)-1])) != -1) {
704 revers_fore_color
= color
;
707 if (*color_index
< argc
&&
708 (color
= get_color_number(argv
[*color_index
])) != -1) {
710 revers_back_color
= color
;
717 * Set normal and reverse foreground and background colors.
723 fprintf(stderr
, "\e[=%dF", normal_fore_color
);
724 fprintf(stderr
, "\e[=%dG", normal_back_color
);
725 fprintf(stderr
, "\e[=%dH", revers_fore_color
);
726 fprintf(stderr
, "\e[=%dI", revers_back_color
);
731 * Switch to virtual terminal #arg.
735 set_console(char *arg
)
739 if(!arg
|| strspn(arg
,"0123456789") != strlen(arg
)) {
741 errx(1, "bad console number");
746 if (n
< 1 || n
> 16) {
748 errx(1, "console number out of range");
749 } else if (ioctl(0, VT_ACTIVATE
, (caddr_t
) (long) n
) == -1) {
751 errc(1, errno
, "switching vty");
757 * Sets the border color.
761 set_border_color(char *arg
)
765 if ((color
= get_color_number(arg
)) != -1)
766 fprintf(stderr
, "\e[=%dA", color
);
773 set_mouse_char(char *arg
)
775 struct mouse_info mouse
;
778 l
= strtol(arg
, NULL
, 0);
780 if ((l
< 0) || (l
> UCHAR_MAX
)) {
782 errx(1, "argument to -M must be 0 through %d", UCHAR_MAX
);
785 mouse
.operation
= MOUSE_MOUSECHAR
;
786 mouse
.u
.mouse_char
= (int)l
;
788 if (ioctl(0, CONS_MOUSECTL
, &mouse
) == -1) {
790 errc(1, errno
, "setting mouse character");
796 * Show/hide the mouse.
802 struct mouse_info mouse
;
804 if (!strcmp(arg
, "on")) {
805 mouse
.operation
= MOUSE_SHOW
;
806 } else if (!strcmp(arg
, "off")) {
807 mouse
.operation
= MOUSE_HIDE
;
810 errx(1, "argument to -m must be either on or off");
812 ioctl(0, CONS_MOUSECTL
, &mouse
);
817 set_lockswitch(char *arg
)
821 if (!strcmp(arg
, "off")) {
823 } else if (!strcmp(arg
, "on")) {
827 errx(1, "argument to -S must be either on or off");
830 if (ioctl(0, VT_LOCKSWITCH
, &data
) == -1) {
832 errc(1, errno
, "turning %s vty switching",
833 data
== 0x01 ? "off" : "on");
839 * Return the adapter name for a specified type.
843 adapter_name(int type
)
848 } names
[] = {{ KD_MONO
, "MDA" },
849 { KD_HERCULES
, "Hercules" },
859 for (i
= 0; names
[i
].type
!= -1; ++i
) {
860 if (names
[i
].type
== type
)
864 return names
[i
].name
;
869 * Show graphics adapter information.
873 show_adapter_info(void)
875 struct video_adapter_info ad
;
879 if (ioctl(0, CONS_ADPINFO
, &ad
) == -1) {
881 errc(1, errno
, "obtaining adapter information");
884 printf("fb%d:\n", ad
.va_index
);
885 printf(" %.*s%d, type:%s%s (%d), flags:0x%x\n",
886 (int)sizeof(ad
.va_name
), ad
.va_name
, ad
.va_unit
,
887 (ad
.va_flags
& V_ADP_VESA
) ? "VESA " : "",
888 adapter_name(ad
.va_type
), ad
.va_type
, ad
.va_flags
);
889 printf(" initial mode:%d, current mode:%d, BIOS mode:%d\n",
890 ad
.va_initial_mode
, ad
.va_mode
, ad
.va_initial_bios_mode
);
891 printf(" frame buffer window:0x%x, buffer size:0x%zx\n",
892 ad
.va_window
, ad
.va_buffer_size
);
893 printf(" window size:0x%zx, origin:0x%x\n",
894 ad
.va_window_size
, ad
.va_window_orig
);
895 printf(" display start address (%d, %d), scan line width:%d\n",
896 ad
.va_disp_start
.x
, ad
.va_disp_start
.y
, ad
.va_line_width
);
897 printf(" reserved:0x%x\n", ad
.va_unused0
);
902 * Show video mode information.
908 struct video_info vinfo
;
913 printf(" mode# flags type size "
914 "font window linear buffer\n");
915 printf("---------------------------------------"
916 "---------------------------------------\n");
918 for (mode
= 0; mode
< M_VESA_MODE_MAX
; ++mode
) {
919 vinfo
.vi_mode
= mode
;
921 if (ioctl(0, CONS_MODEINFO
, &vinfo
))
923 if (vinfo
.vi_mode
!= mode
)
926 printf("%3d (0x%03x)", mode
, mode
);
927 printf(" 0x%08x", vinfo
.vi_flags
);
929 if (vinfo
.vi_flags
& V_INFO_GRAPHICS
) {
932 snprintf(buf
, sizeof(buf
), "%dx%dx%d %d",
933 vinfo
.vi_width
, vinfo
.vi_height
,
934 vinfo
.vi_depth
, vinfo
.vi_planes
);
938 snprintf(buf
, sizeof(buf
), "%dx%d",
939 vinfo
.vi_width
, vinfo
.vi_height
);
942 printf(" %c %-15s", c
, buf
);
943 snprintf(buf
, sizeof(buf
), "%dx%d",
944 vinfo
.vi_cwidth
, vinfo
.vi_cheight
);
945 printf(" %-5s", buf
);
946 printf(" 0x%05x %2dk %2dk",
947 vinfo
.vi_window
, (int)vinfo
.vi_window_size
/ 1024,
948 (int)vinfo
.vi_window_gran
/1024);
949 printf(" 0x%08x %dk\n",
950 vinfo
.vi_buffer
, (int)vinfo
.vi_buffer_size
/ 1024);
958 if (!strcmp(arg
, "adapter")) {
960 } else if (!strcmp(arg
, "mode")) {
964 errx(1, "argument to -i must be either adapter or mode");
974 fprintf(stdout
, "\e[=0G\n\n");
976 for (i
= 0; i
< 8; i
++) {
977 fprintf(stdout
, "\e[=15F\e[=0G %2d \e[=%dF%-16s"
978 "\e[=15F\e[=0G %2d \e[=%dF%-16s "
979 "\e[=15F %2d \e[=%dGBACKGROUND\e[=0G\n",
980 i
, i
, legal_colors
[i
], i
+8, i
+8,
981 legal_colors
[i
+8], i
, i
);
984 fprintf(stdout
, "\e[=%dF\e[=%dG\e[=%dH\e[=%dI\n",
985 info
.mv_norm
.fore
, info
.mv_norm
.back
,
986 info
.mv_rev
.fore
, info
.mv_rev
.back
);
991 * Snapshot the video memory of that terminal, using the CONS_SCRSHOT
992 * ioctl, and writes the results to stdout either in the special
993 * binary format (see manual page for details), or in the plain
998 dump_screen(int mode
)
1003 vinfo
.size
= sizeof(vinfo
);
1005 if (ioctl(0, CONS_GETINFO
, &vinfo
) == -1) {
1007 errc(1, errno
, "obtaining current video mode parameters");
1010 shot
.buf
= alloca(vinfo
.mv_csz
* vinfo
.mv_rsz
* sizeof(u_int16_t
));
1012 if (shot
.buf
== NULL
) {
1014 errx(1, "failed to allocate memory for dump");
1017 shot
.xsize
= vinfo
.mv_csz
;
1018 shot
.ysize
= vinfo
.mv_rsz
;
1020 if (ioctl(0, CONS_SCRSHOT
, &shot
) == -1) {
1022 errc(1, errno
, "dumping screen");
1025 if (mode
== DUMP_RAW
) {
1026 printf("SCRSHOT_%c%c%c%c", DUMP_FMT_REV
, 2,
1027 shot
.xsize
, shot
.ysize
);
1031 write(STDOUT_FILENO
, shot
.buf
,
1032 shot
.xsize
* shot
.ysize
* sizeof(u_int16_t
));
1038 line
= alloca(shot
.xsize
+ 1);
1042 errx(1, "failed to allocate memory for line buffer");
1045 for (y
= 0; y
< shot
.ysize
; y
++) {
1046 for (x
= 0; x
< shot
.xsize
; x
++) {
1047 ch
= shot
.buf
[x
+ (y
* shot
.xsize
)];
1050 if (isprint(ch
) == 0)
1056 /* Trim trailing spaces */
1060 } while (line
[x
] == ' ' && x
!= 0);
1071 * Set the console history buffer size.
1075 set_history(char *opt
)
1081 if ((*opt
== '\0') || size
< 0) {
1083 errx(1, "argument must be a positive number");
1086 if (ioctl(0, CONS_HISTORY
, &size
) == -1) {
1088 errc(1, errno
, "setting history buffer size");
1094 * Clear the console history buffer.
1100 if (ioctl(0, CONS_CLRHIST
) == -1) {
1102 errc(1, errno
, "clearing history buffer");
1108 main(int argc
, char **argv
)
1118 info
.size
= sizeof(info
);
1120 if (ioctl(0, CONS_GETINFO
, &info
) == -1)
1121 err(1, "must be on a virtual console");
1123 while((opt
= getopt(argc
, argv
, "b:Cc:df:g:h:i:l:LM:m:pPr:S:s:t:x")) != -1) {
1126 set_border_color(optarg
);
1132 set_cursor_type(optarg
);
1139 font
= nextarg(argc
, argv
, &optind
, 'f', 0);
1146 load_font(type
, font
);
1149 if (sscanf(optarg
, "%dx%d",
1150 &vesa_cols
, &vesa_rows
) != 2) {
1152 warnx("incorrect geometry: %s", optarg
);
1157 set_history(optarg
);
1163 load_scrnmap(optarg
);
1166 load_default_scrnmap();
1169 set_mouse_char(optarg
);
1175 dump_screen(DUMP_RAW
);
1178 dump_screen(DUMP_TXT
);
1181 get_reverse_colors(argc
, argv
, &optind
);
1184 set_lockswitch(optarg
);
1187 set_console(optarg
);
1190 set_screensaver_timeout(optarg
);
1200 if (optind
< argc
&& !strcmp(argv
[optind
], "show")) {
1205 video_mode(argc
, argv
, &optind
);
1207 get_normal_colors(argc
, argv
, &optind
);
1209 if (colors_changed
|| video_mode_changed
) {
1210 if (!(new_mode_info
.vi_flags
& V_INFO_GRAPHICS
)) {
1211 if ((normal_back_color
< 8) && (revers_back_color
< 8)) {
1215 errx(1, "bg color for text modes must be < 8");
1222 if ((optind
!= argc
) || (argc
== 1))