⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 termcap.html

📁 this is a mirrored site c-faq. thought might need offline
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN"><!-- This collection of hypertext pages is Copyright 1995-2005 by Steve Summit. --><!-- Content from the book "C Programming FAQs: Frequently Asked Questions" --><!-- (Addison-Wesley, 1995, ISBN 0-201-84519-9) is made available here by --><!-- permission of the author and the publisher as a service to the community. --><!-- It is intended to complement the use of the published text --><!-- and is protected by international copyright laws. --><!-- The on-line content may be accessed freely for personal use --><!-- but may not be published or retransmitted without explicit permission. --><!-- --><!-- this page built Sat Dec 24 21:47:47 2005 by faqproc version 2.7 --><!-- from source file osdepio.sgml dated Sat Jul  3 17:23:16 2004 --><!-- corresponding to FAQ list version 4.0 --><html><!-- Mirrored from c-faq.com/osdep/termcap.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:59:02 GMT --><head><meta name=GENERATOR content="faqproc"><title>Question 19.4</title><link href="baton.html" rev=precedes><link href="waitforkey.html" rel=precedes><link href="index.html" rev=subdocument></head><body bgcolor="#ffffff"><a href="baton.html" rev=precedes><img src="../images/buttonleft.gif" alt="prev"></a><a href="index.html" rev=subdocument><img src="../images/buttonup.gif" alt="up"></a><a href="waitforkey.html" rel=precedes><img src="../images/buttonright.gif" alt="next"></a>&nbsp;<a href="../index-2.html"><img src="../images/buttontop.gif" alt="top/contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><hr><p><!-- qbegin --><h1>comp.lang.c FAQ list<font color=blue>&middot;</font><!-- qtag -->Question 19.4</h1><p><font face=Helvetica size=8 color=blue><b>Q:</b></font>How can I clear the screen?<br>How can Iprinttext in color?<br>How can Imove the cursorto a specific x,&nbsp;y position?</p><p><hr><p><font face=Helvetica size=8 color=blue><b>A:</b></font>Such things depend on theterminal type (or display)you're using.You will have to use a library such astermcap, terminfo, or curses,or some system-specific routines, to perform these operations.</p><p>Functionsin the curses libraryto look for are<TT>clear</TT>,<TT>move</TT>,<TT>standout</TT>/<TT>standend</TT>,and<TT>attron</TT>/<TT>attroff</TT>/<TT>attrset</TT>;the last three work withattribute codes such as A_REVERSE.In MS-DOS libraries,there are typically functions named<TT>gotoxy</TT>and<TT>clrscr</TT>or<TT>_clearscreen</TT>;you can also use the ANSI.SYS driver or low-level interrupts.Under termcap or terminfo,use <TT>tgetstr</TT>to retrieve strings like<TT>cl</TT>,<TT>so</TT>/<TT>se</TT>,and <TT>cm</TT>for clear screen, standout mode, and cursor motion respectively,then output the strings;using <TT>cm</TT> additionally requires calling <TT>tgoto</TT>.Some baroque terminals requireattention to other ``capabilities'' as well;study thedocumentation carefully.Be aware that some older terminalsmaynot support the desired capabilitiesat all.</p><p>Most modern terminal emulation schemessupport the ANSI escape sequencesfor cursor motion and visual attributes,so if you're willing to sacrifice portability,you can print those sequences directly.Here is a tiny example to whet your appetite:<pre>printf("\033[2J");		/* clear screen */printf("\033[%d;%dH", 10, 20);	/* move cursor (row 10, col 20) */printf("Hello, ");printf("\033[7mworld\033[0m!");	/* inverse video */</pre>Here is a link to some<a href="sd21.html" rel=subdocument>more explanation, and brief lists of codes.</a>The portable way of emitting these sequences(if you're not going whole-hog and using curses)is to use termcap or terminfo;here is<a href="sd22.html" rel=subdocument>an example.</a></p><p>For clearing the screen,a halfway portable solution is to printa form-feed character(<TT>'\f'</TT>),which will causesomedisplaysto clear.Even more portable(albeit even more gunky)might beto print enough newlinesto scroll everything away(although of coursethis leaves the cursor at the bottom of the screen,not the top).As a last resort,you could use <TT>system</TT>(see question <a href="system.html">19.27</a>)to invokean operating system clear-screen command.</p><p>References:PCS Sec. 5.1.4 pp. 54-60, Sec. 5.1.5 pp. 60-62<br>Strang, <I>Programming with curses</I><br>Strang, Mui, and O'Reilly, <I>termcap &amp; terminfo</I><br></p><!-- aend --><p><hr><a href="baton.html" rev=precedes><img src="../images/buttonleft.gif" alt="prev"></a><a href="index.html" rev=subdocument><img src="../images/buttonup.gif" alt="up"></a><a href="waitforkey.html" rel=precedes><img src="../images/buttonright.gif" alt="next"></a>&nbsp;<a href="../questions.html"><img src="../images/buttontop.gif" alt="contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><br><!-- lastfooter --><a href="../about.html">about this FAQ list</a>&nbsp;<a href="../eskimo.html">about eskimo</a>&nbsp;<a href="../search.html">search</a>&nbsp;<a href="../feedback.html">feedback</a>&nbsp;<a href="copyright.html">copyright</a><p>Hosted by<a href="http://www.eskimo.com/"><img src="../../www.eskimo.com/img/link/eskitiny.gif" alt="Eskimo North"></a></body><!-- Mirrored from c-faq.com/osdep/termcap.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:59:02 GMT --></html>

⌨️ 快捷键说明

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