parthtamu/rag-code-assistant
0
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4 <head>5 <meta charset="utf-8" />6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="tty — Terminal control functions" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/tty.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/tty.py The tty module defines functions for putting the tty into cbreak and raw modes. Availability: Unix. Because it requires the termios module, it will work only on Unix. The tt..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_tty_d8d9422b.png" />15<meta property="og:image:alt" content="Source code: Lib/tty.py The tty module defines functions for putting the tty into cbreak and raw modes. Availability: Unix. Because it requires the termios module, it will work only on Unix. The tt..." />16<meta name="description" content="Source code: Lib/tty.py The tty module defines functions for putting the tty into cbreak and raw modes. Availability: Unix. Because it requires the termios module, it will work only on Unix. The tt..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20 <title>tty — Terminal control functions — Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21 22 <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23 <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24 <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25 <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26 <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27 28 <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29 <script src="../_static/doctools.js?v=9bcbadda"></script>30 <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31 <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32 33 <script src="../_static/sidebar.js"></script>34 35 <link rel="search" type="application/opensearchdescription+xml"36 title="Search within Python 3.15.0a6 documentation"37 href="../_static/opensearch.xml"/>38 <link rel="author" title="About these documents" href="../about.html" />39 <link rel="index" title="Index" href="../genindex.html" />40 <link rel="search" title="Search" href="../search.html" />41 <link rel="copyright" title="Copyright" href="../copyright.html" />42 <link rel="next" title="pty — Pseudo-terminal utilities" href="pty.html" />43 <link rel="prev" title="termios — POSIX style tty control" href="termios.html" />44 45 46 <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47 48 <link rel="canonical" href="https://docs.python.org/3/library/tty.html">49 50 51 52 53 <style>54 @media only screen {55 table.full-width-table {56 width: 100%;57 }58 }59 </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61 <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62 <script type="text/javascript" src="../_static/copybutton.js"></script>63 <script type="text/javascript" src="../_static/menu.js"></script>64 <script type="text/javascript" src="../_static/search-focus.js"></script>65 <script type="text/javascript" src="../_static/themetoggle.js"></script> 66 <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67 <meta name="readthedocs-addons-api-version" content="1">68 69 </head>70<body>71<div class="mobile-nav">72 <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73 aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74 <nav class="nav-content" role="navigation">75 <label for="menuToggler" class="toggler__label">76 <span></span>77 </label>78 <span class="nav-items-wrapper">79 <a href="https://www.python.org/" class="nav-logo">80 <img src="../_static/py.svg" alt="Python logo">81 </a>82 <span class="version_switcher_placeholder"></span>83 <form role="search" class="search" action="../search.html" method="get">84 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85 <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>86 </svg>87 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88 <input type="submit" value="Go">89 </form>90 </span>91 </nav>92 <div class="menu-wrapper">93 <nav class="menu" role="navigation" aria-label="main navigation">94 <div class="language_switcher_placeholder"></div>95 96<label class="theme-selector-label">97 Theme98 <select class="theme-selector" oninput="activateTheme(this.value)">99 <option value="auto" selected>Auto</option>100 <option value="light">Light</option>101 <option value="dark">Dark</option>102 </select>103</label>104 <div>105 <h4>Previous topic</h4>106 <p class="topless"><a href="termios.html"107 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">termios</span></code> — POSIX style tty control</a></p>108 </div>109 <div>110 <h4>Next topic</h4>111 <p class="topless"><a href="pty.html"112 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pty</span></code> — Pseudo-terminal utilities</a></p>113 </div>114 <script>115 document.addEventListener('DOMContentLoaded', () => {116 const title = document.querySelector('meta[property="og:title"]').content;117 const elements = document.querySelectorAll('.improvepage');118 const pageurl = window.location.href.split('?')[0];119 elements.forEach(element => {120 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));121 url.searchParams.set('pagetitle', title);122 url.searchParams.set('pageurl', pageurl);123 url.searchParams.set('pagesource', "library/tty.rst");124 element.href = url.toString();125 });126 });127 </script>128 <div role="note" aria-label="source link">129 <h3>This page</h3>130 <ul class="this-page-menu">131 <li><a href="../bugs.html">Report a bug</a></li>132 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>133 <li>134 <a href="https://github.com/python/cpython/blob/main/Doc/library/tty.rst?plain=1"135 rel="nofollow">Show source136 </a>137 </li>138 139 </ul>140 </div>141 </nav>142 </div>143</div>144 145 146 <div class="related" role="navigation" aria-label="Related">147 <h3>Navigation</h3>148 <ul>149 <li class="right" style="margin-right: 10px">150 <a href="../genindex.html" title="General Index"151 accesskey="I">index</a></li>152 <li class="right" >153 <a href="../py-modindex.html" title="Python Module Index"154 >modules</a> |</li>155 <li class="right" >156 <a href="pty.html" title="pty — Pseudo-terminal utilities"157 accesskey="N">next</a> |</li>158 <li class="right" >159 <a href="termios.html" title="termios — POSIX style tty control"160 accesskey="P">previous</a> |</li>161 162 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>163 <li><a href="https://www.python.org/">Python</a> »</li>164 <li class="switchers">165 <div class="language_switcher_placeholder"></div>166 <div class="version_switcher_placeholder"></div>167 </li>168 <li>169 170 </li>171 <li id="cpython-language-and-version">172 <a href="../index.html">3.15.0a6 Documentation</a> »173 </li>174 175 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>176 <li class="nav-item nav-item-2"><a href="unix.html" accesskey="U">Unix-specific services</a> »</li>177 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">tty</span></code> — Terminal control functions</a></li>178 <li class="right">179 180 181 <div class="inline-search" role="search">182 <form class="inline-search" action="../search.html" method="get">183 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">184 <input type="submit" value="Go">185 </form>186 </div>187 |188 </li>189 <li class="right">190<label class="theme-selector-label">191 Theme192 <select class="theme-selector" oninput="activateTheme(this.value)">193 <option value="auto" selected>Auto</option>194 <option value="light">Light</option>195 <option value="dark">Dark</option>196 </select>197</label> |</li>198 199 </ul>200 </div> 201 202 <div class="document">203 <div class="documentwrapper">204 <div class="bodywrapper">205 <div class="body" role="main">206 207 <section id="module-tty">208<span id="tty-terminal-control-functions"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">tty</span></code> — Terminal control functions<a class="headerlink" href="#module-tty" title="Link to this heading">¶</a></h1>209<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/tty.py">Lib/tty.py</a></p>210<hr class="docutils" />211<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">tty</span></code> module defines functions for putting the tty into cbreak and raw212modes.</p>213<div class="availability docutils container">214<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p>215</div>216<p>Because it requires the <a class="reference internal" href="termios.html#module-termios" title="termios: POSIX style tty control."><code class="xref py py-mod docutils literal notranslate"><span class="pre">termios</span></code></a> module, it will work only on Unix.</p>217<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">tty</span></code> module defines the following functions:</p>218<dl class="py function">219<dt class="sig sig-object py" id="tty.cfmakeraw">220<span class="sig-prename descclassname"><span class="pre">tty.</span></span><span class="sig-name descname"><span class="pre">cfmakeraw</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tty.cfmakeraw" title="Link to this definition">¶</a></dt>221<dd><p>Convert the tty attribute list <em>mode</em>, which is a list like the one returned222by <a class="reference internal" href="termios.html#termios.tcgetattr" title="termios.tcgetattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">termios.tcgetattr()</span></code></a>, to that of a tty in raw mode.</p>223<div class="versionadded">224<p><span class="versionmodified added">Added in version 3.12.</span></p>225</div>226</dd></dl>227 228<dl class="py function">229<dt class="sig sig-object py" id="tty.cfmakecbreak">230<span class="sig-prename descclassname"><span class="pre">tty.</span></span><span class="sig-name descname"><span class="pre">cfmakecbreak</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mode</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tty.cfmakecbreak" title="Link to this definition">¶</a></dt>231<dd><p>Convert the tty attribute list <em>mode</em>, which is a list like the one returned232by <a class="reference internal" href="termios.html#termios.tcgetattr" title="termios.tcgetattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">termios.tcgetattr()</span></code></a>, to that of a tty in cbreak mode.</p>233<p>This clears the <code class="docutils literal notranslate"><span class="pre">ECHO</span></code> and <code class="docutils literal notranslate"><span class="pre">ICANON</span></code> local mode flags in <em>mode</em> as well234as setting the minimum input to 1 byte with no delay.</p>235<div class="versionadded">236<p><span class="versionmodified added">Added in version 3.12.</span></p>237</div>238<div class="versionchanged">239<p><span class="versionmodified changed">Changed in version 3.12.2: </span>The <code class="docutils literal notranslate"><span class="pre">ICRNL</span></code> flag is no longer cleared. This matches Linux and macOS240<code class="docutils literal notranslate"><span class="pre">stty</span> <span class="pre">cbreak</span></code> behavior and what <a class="reference internal" href="#tty.setcbreak" title="tty.setcbreak"><code class="xref py py-func docutils literal notranslate"><span class="pre">setcbreak()</span></code></a> historically did.</p>241</div>242</dd></dl>243 244<dl class="py function">245<dt class="sig sig-object py" id="tty.setraw">246<span class="sig-prename descclassname"><span class="pre">tty.</span></span><span class="sig-name descname"><span class="pre">setraw</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">when</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">termios.TCSAFLUSH</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tty.setraw" title="Link to this definition">¶</a></dt>247<dd><p>Change the mode of the file descriptor <em>fd</em> to raw. If <em>when</em> is omitted, it248defaults to <a class="reference internal" href="termios.html#termios.TCSAFLUSH" title="termios.TCSAFLUSH"><code class="xref py py-const docutils literal notranslate"><span class="pre">termios.TCSAFLUSH</span></code></a>, and is passed to249<a class="reference internal" href="termios.html#termios.tcsetattr" title="termios.tcsetattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">termios.tcsetattr()</span></code></a>. The return value of <a class="reference internal" href="termios.html#termios.tcgetattr" title="termios.tcgetattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">termios.tcgetattr()</span></code></a>250is saved before setting <em>fd</em> to raw mode; this value is returned.</p>251<div class="versionchanged">252<p><span class="versionmodified changed">Changed in version 3.12: </span>The return value is now the original tty attributes, instead of <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>253</div>254</dd></dl>255 256<dl class="py function">257<dt class="sig sig-object py" id="tty.setcbreak">258<span class="sig-prename descclassname"><span class="pre">tty.</span></span><span class="sig-name descname"><span class="pre">setcbreak</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">when</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">termios.TCSAFLUSH</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#tty.setcbreak" title="Link to this definition">¶</a></dt>259<dd><p>Change the mode of file descriptor <em>fd</em> to cbreak. If <em>when</em> is omitted, it260defaults to <a class="reference internal" href="termios.html#termios.TCSAFLUSH" title="termios.TCSAFLUSH"><code class="xref py py-const docutils literal notranslate"><span class="pre">termios.TCSAFLUSH</span></code></a>, and is passed to261<a class="reference internal" href="termios.html#termios.tcsetattr" title="termios.tcsetattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">termios.tcsetattr()</span></code></a>. The return value of <a class="reference internal" href="termios.html#termios.tcgetattr" title="termios.tcgetattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">termios.tcgetattr()</span></code></a>262is saved before setting <em>fd</em> to cbreak mode; this value is returned.</p>263<p>This clears the <code class="docutils literal notranslate"><span class="pre">ECHO</span></code> and <code class="docutils literal notranslate"><span class="pre">ICANON</span></code> local mode flags as well as setting264the minimum input to 1 byte with no delay.</p>265<div class="versionchanged">266<p><span class="versionmodified changed">Changed in version 3.12: </span>The return value is now the original tty attributes, instead of <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>267</div>268<div class="versionchanged">269<p><span class="versionmodified changed">Changed in version 3.12.2: </span>The <code class="docutils literal notranslate"><span class="pre">ICRNL</span></code> flag is no longer cleared. This restores the behavior270of Python 3.11 and earlier as well as matching what Linux, macOS, & BSDs271describe in their <code class="docutils literal notranslate"><span class="pre">stty(1)</span></code> man pages regarding cbreak mode.</p>272</div>273</dd></dl>274 275<div class="admonition seealso">276<p class="admonition-title">See also</p>277<dl class="simple">278<dt>Module <a class="reference internal" href="termios.html#module-termios" title="termios: POSIX style tty control."><code class="xref py py-mod docutils literal notranslate"><span class="pre">termios</span></code></a></dt><dd><p>Low-level terminal control interface.</p>279</dd>280</dl>281</div>282</section>283 284 285 <div class="clearer"></div>286 </div>287 </div>288 </div>289 <div class="sphinxsidebar" role="navigation" aria-label="Main">290 <div class="sphinxsidebarwrapper">291 <div>292 <h4>Previous topic</h4>293 <p class="topless"><a href="termios.html"294 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">termios</span></code> — POSIX style tty control</a></p>295 </div>296 <div>297 <h4>Next topic</h4>298 <p class="topless"><a href="pty.html"299 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pty</span></code> — Pseudo-terminal utilities</a></p>300 </div>301 <script>302 document.addEventListener('DOMContentLoaded', () => {303 const title = document.querySelector('meta[property="og:title"]').content;304 const elements = document.querySelectorAll('.improvepage');305 const pageurl = window.location.href.split('?')[0];306 elements.forEach(element => {307 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));308 url.searchParams.set('pagetitle', title);309 url.searchParams.set('pageurl', pageurl);310 url.searchParams.set('pagesource', "library/tty.rst");311 element.href = url.toString();312 });313 });314 </script>315 <div role="note" aria-label="source link">316 <h3>This page</h3>317 <ul class="this-page-menu">318 <li><a href="../bugs.html">Report a bug</a></li>319 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>320 <li>321 <a href="https://github.com/python/cpython/blob/main/Doc/library/tty.rst?plain=1"322 rel="nofollow">Show source323 </a>324 </li>325 326 </ul>327 </div>328 </div>329<div id="sidebarbutton" title="Collapse sidebar">330<span>«</span>331</div>332 333 </div>334 <div class="clearer"></div>335 </div> 336 <div class="related" role="navigation" aria-label="Related">337 <h3>Navigation</h3>338 <ul>339 <li class="right" style="margin-right: 10px">340 <a href="../genindex.html" title="General Index"341 >index</a></li>342 <li class="right" >343 <a href="../py-modindex.html" title="Python Module Index"344 >modules</a> |</li>345 <li class="right" >346 <a href="pty.html" title="pty — Pseudo-terminal utilities"347 >next</a> |</li>348 <li class="right" >349 <a href="termios.html" title="termios — POSIX style tty control"350 >previous</a> |</li>351 352 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>353 <li><a href="https://www.python.org/">Python</a> »</li>354 <li class="switchers">355 <div class="language_switcher_placeholder"></div>356 <div class="version_switcher_placeholder"></div>357 </li>358 <li>359 360 </li>361 <li id="cpython-language-and-version">362 <a href="../index.html">3.15.0a6 Documentation</a> »363 </li>364 365 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>366 <li class="nav-item nav-item-2"><a href="unix.html" >Unix-specific services</a> »</li>367 <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">tty</span></code> — Terminal control functions</a></li>368 <li class="right">369 370 371 <div class="inline-search" role="search">372 <form class="inline-search" action="../search.html" method="get">373 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">374 <input type="submit" value="Go">375 </form>376 </div>377 |378 </li>379 <li class="right">380<label class="theme-selector-label">381 Theme382 <select class="theme-selector" oninput="activateTheme(this.value)">383 <option value="auto" selected>Auto</option>384 <option value="light">Light</option>385 <option value="dark">Dark</option>386 </select>387</label> |</li>388 389 </ul>390 </div> 391 <div class="footer">392 © <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.393 <br>394 This page is licensed under the Python Software Foundation License Version 2.395 <br>396 Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.397 <br>398 399 See <a href="/license.html">History and License</a> for more information.<br>400 401 402 <br>403 404 The Python Software Foundation is a non-profit corporation.405<a href="https://www.python.org/psf/donations/">Please donate.</a>406<br>407 <br>408 Last updated on Mar 10, 2026 (08:58 UTC).409 410 <a href="/bugs.html">Found a bug</a>?411 412 <br>413 414 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.415 </div>416 417 </body>418</html>