<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Unix &#8211; Noise</title>
	<atom:link href="https://noise.getoto.net/tag/unix/feed/" rel="self" type="application/rss+xml" />
	<link>https://noise.getoto.net</link>
	<description>The collective thoughts of the interwebz</description>
	<lastBuildDate>Wed, 22 May 2024 00:00:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>Safe terminal escape codes</title>
		<link>https://noise.getoto.net/2024/05/22/safe-terminal-escape-codes/</link>
		
		<dc:creator><![CDATA[arp242.net]]></dc:creator>
		<pubDate>Wed, 22 May 2024 00:00:00 +0000</pubDate>
				<category><![CDATA[Unix]]></category>
		<guid isPermaLink="false">https://www.arp242.net/safeterm.html</guid>

					<description><![CDATA[

<p>A long time ago when the Unix greybeards were slightly less grey beards everyone
was using hardware terminals to talk to some mainframe. Those terminals had
wildly different feature sets and ways to implement them, which you needed to
know about if you wanted your program to run on more than one type of terminal.
Hence systems like terminfo and termcap.</p>

<p>The TeleVideo 955 used <code>\x1b[=5l</code> for bold text, and the IBM 3161 used <code>\x1b4H</code>.
Both were introduced in 1985. The TeleVideo 950 from 1980 didn’t support bold
text at all.</p>

<p>Today everyone is using software terminal emulators, and they all just implement
ANSI escape codes for the common stuff. No one is sending <code>\x1b[=5l</code> or
<code>\x1b4H</code>.</p>

<p>Do you still need terminfo? It depends. If you just want to style some text and
maybe do some basic cursor operations: probably not. If you want to use more
advanced operations or read key input: probably yes. If you want maximum
compatibility (there’s probably someone using a hardware Wyse terminal, or SunOS
4 with CDE): absolutely.</p>

<p>Here is a list of terminal escape sequences that should always work on any
vaguely modern terminal, where “modern” means “since the mid-90s or so”.</p>

<p>This was generated by looking at every terminfo file I could find with my
<a href="https://github.com/arp242/termfo">termfo</a> tool (specifically, <code>termfo find-cap</code>) and occasionally testing some
things to verify it works. I don’t care what some spec says; I care about what
works.</p>

<p>The escape character is always omitted; so <code>[0m</code> is <code>\x1b[0m</code>.</p>

<h2>Graphics <a href="https://www.arp242.net/#graphics"></a></h2>
<p>These can be combined in a single sequence by joining with a <code>;</code>. For example
<code>\x1b[1;4m</code> for underlined bold text. These can also be combined with colours;
for example <code>\x1b[1;38;2;0;255;0;41m</code> to set bold, foreground colour with true
colour, and background colour with 16 colour.</p>

<p>Just using <code>\x1b[1m\x1b[4m</code> also works.</p>

<table>
  <thead>
    <tr>
      <th>Code</th>
      <th>Terminfo (short, long)</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>[0m</td>
      <td>sgr0,  exit_attribute_mode</td>
      <td>Turn off all attributes and colours.</td>
    </tr>
    <tr>
      <td>[1m</td>
      <td>bold,  enter_bold_mode</td>
      <td>Enter bold mode.</td>
    </tr>
    <tr>
      <td>[2m</td>
      <td>dim,   enter_dim_mode</td>
      <td>Enter half-bright mode.<sup role="doc-noteref"><a href="https://www.arp242.net/#fn:dim" class="footnote" rel="footnote">[1]</a></sup></td>
    </tr>
    <tr>
      <td>[3m</td>
      <td>sitm,  enter_italics_mode</td>
      <td>Enter italic mode.<sup role="doc-noteref"><a href="https://www.arp242.net/#fn:sitm" class="footnote" rel="footnote">[2]</a></sup></td>
    </tr>
    <tr>
      <td>[4m</td>
      <td>smul,  enter_underline_mode</td>
      <td>Enter underline mode.</td>
    </tr>
    <tr>
      <td>[5m</td>
      <td>blink, enter_blink_mode</td>
      <td>Enter blinking mode.<sup role="doc-noteref"><a href="https://www.arp242.net/#fn:blink" class="footnote" rel="footnote">[3]</a></sup></td>
    </tr>
    <tr>
      <td>[7m</td>
      <td>rev,   enter_reverse_mode</td>
      <td>Enter reverse video mode.</td>
    </tr>
    <tr>
      <td>[8m</td>
      <td>invis, enter_secure_mode</td>
      <td>Enter blank mode.<sup role="doc-noteref"><a href="https://www.arp242.net/#fn:invis" class="footnote" rel="footnote">[4]</a></sup></td>
    </tr>
    <tr>
      <td>[9m</td>
      <td>smxx</td>
      <td>Enter strikeout mode.</td>
    </tr>
  </tbody>
</table>

<p>Colours are set with <code>setab</code> / <code>set_a_background</code> and <code>setaf</code> /
<code>set_a_foreground</code>; the format depends on which colour scheme you want to use.</p>

<h3>16-colours <a href="https://www.arp242.net/#16-colours"></a></h3>
<p>Pretty much everything supports 16 colours, unless explicitly disabled by the
user. The exact shade is determined by the terminal.</p>

<p>Escapes as «regular» «bright»:</p>

<table>
  <thead>
    <tr>
      <th>Foreground</th>
      <th>Background</th>
      <th>Colour</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>[30m  [90m</td>
      <td>[40m [100m</td>
      <td>black</td>
    </tr>
    <tr>
      <td>[31m  [91m</td>
      <td>[41m [101m</td>
      <td>red</td>
    </tr>
    <tr>
      <td>[32m  [92m</td>
      <td>[42m [102m</td>
      <td>green</td>
    </tr>
    <tr>
      <td>[33m  [93m</td>
      <td>[43m [103m</td>
      <td>yellow</td>
    </tr>
    <tr>
      <td>[34m  [94m</td>
      <td>[44m [104m</td>
      <td>blue</td>
    </tr>
    <tr>
      <td>[35m  [95m</td>
      <td>[45m [105m</td>
      <td>magenta</td>
    </tr>
    <tr>
      <td>[36m  [96m</td>
      <td>[46m [106m</td>
      <td>cyan</td>
    </tr>
    <tr>
      <td>[37m  [97m</td>
      <td>[47m [107m</td>
      <td>white</td>
    </tr>
  </tbody>
</table>

<h3>256-colours <a href="https://www.arp242.net/#256-colours"></a></h3>
<p>Choose a colour from a <a href="https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit">pre-defined table of 256 colours</a>. This is
supported on almost all current terminal emulators, unless explicitly disabled
by the user.</p>

<p>Where «C» is a number from 0 to 255:</p>

<div class="pre-wrap">
<pre><code>[38;5;«C»m   Foreground
[48;5;«C»m   Background
</code></pre>
</div>

<h3>True colours <a href="https://www.arp242.net/#true-colours"></a></h3>
<p>Use “true” RGB colours; this is supported on almost all current terminal
emulators, unless explicitly disabled by the user.</p>

<p>Where «R», «G», «B» are the red, green and blue values as decimal, 0 to 255:</p>

<div class="pre-wrap">
<pre><code>[38;2;«R»;«R»;«B»m   Foreground
[48;2;«R»;«G»;«B»m   Background
</code></pre>
</div>

<h2>Cursor movement <a href="https://www.arp242.net/#cursor-movement"></a></h2>

<table>
  <thead>
    <tr>
      <th>Code</th>
      <th>Terminfo (short, long)</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>[«R»;«C»H</td>
      <td>cup,  cursor_address</td>
      <td>Set cursor position to «R», «C».<sup role="doc-noteref"><a href="https://www.arp242.net/#fn:cup" class="footnote" rel="footnote">[5]</a></sup></td>
    </tr>
    <tr>
      <td>[«N»A</td>
      <td>cuu,  parm_up_cursor</td>
      <td>Move «N» lines down.</td>
    </tr>
    <tr>
      <td>[«N»B</td>
      <td>cud,  parm_down_cursor</td>
      <td>Move «N» lines up.</td>
    </tr>
    <tr>
      <td>[«N»C</td>
      <td>cuf,  parm_right_cursor</td>
      <td>Move «N» characters to the right.</td>
    </tr>
    <tr>
      <td>[«N»D</td>
      <td>cub,  parm_left_cursor</td>
      <td>Move «N» characters to the left.</td>
    </tr>
    <tr>
      <td>7</td>
      <td>sc,   save_cursor</td>
      <td>Save current cursor position.</td>
    </tr>
    <tr>
      <td>8</td>
      <td>rc,   restore_cursor</td>
      <td>Restore cursor to position of last save_cursor.</td>
    </tr>
  </tbody>
</table>

<p>The «N» can be omitted in the above, in which case it will default to 1. For
<code>cup</code> the «R» and/or «C» can be omitted, and will default to 1.</p>

<h2>Inserting and deleting text <a href="https://www.arp242.net/#inserting-and-deleting-text"></a></h2>

<table>
  <thead>
    <tr>
      <th>Code</th>
      <th>Terminfo (short, long)</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>[J</td>
      <td>ed,  clr_eos</td>
      <td>Clear from cursor to end of screen.</td>
    </tr>
    <tr>
      <td>[K</td>
      <td>el,  clr_eol</td>
      <td>Clear from cursor to end of line.</td>
    </tr>
    <tr>
      <td>[1K</td>
      <td>el1, clr_bol</td>
      <td>Clear from cursor to beginning of line.</td>
    </tr>
    <tr>
      <td>[«N»M</td>
      <td>dl,  parm_delete_line</td>
      <td>Delete «N» lines, moving all the lines below up.</td>
    </tr>
    <tr>
      <td>[«N»P</td>
      <td>dch, parm_dch</td>
      <td>Delete «N» characters, moving all afterwards left.</td>
    </tr>
    <tr>
      <td>[«N»L</td>
      <td>il,  parm_insert_line</td>
      <td>Insert «N» lines, moving all lines below down.</td>
    </tr>
    <tr>
      <td>[«N»@</td>
      <td>ich, parm_ich</td>
      <td>Insert «N» characters, moving all after right.</td>
    </tr>
  </tbody>
</table>

<p>The «N» can be omitted in the above, in which case it will default to 1.</p>

<h2>Misc <a href="https://www.arp242.net/#misc"></a></h2>

<table>
  <thead>
    <tr>
      <th>Code</th>
      <th>Terminfo (short, long)</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>[?25l</td>
      <td>civis, cursor_invisible</td>
      <td>Make cursor invisible.<sup role="doc-noteref"><a href="https://www.arp242.net/#fn:civis" class="footnote" rel="footnote">[6]</a></sup></td>
    </tr>
    <tr>
      <td>[?25h</td>
      <td>cnorm, cursor_normal</td>
      <td>Make cursor appear normal (undo civis).<sup role="doc-noteref"><a href="https://www.arp242.net/#fn:cnorm" class="footnote" rel="footnote">[7]</a></sup></td>
    </tr>
  </tbody>
</table>

<h2>Keys <a href="https://www.arp242.net/#keys"></a></h2>
<p>Key input handling is kind of a mess, and this is where I really recommend using
a terminfo library if at all possible. This also avoids the whole
backspace/delete key confusion (less of an issue today than it was).</p>

<table>
  <thead>
    <tr>
      <th>Codes</th>
      <th>terminfo (short, long)</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>[A OA</td>
      <td>kcuu1 key_up</td>
      <td>Arrow up</td>
    </tr>
    <tr>
      <td>[B OB</td>
      <td>kcud1 key_down</td>
      <td>Arrow down</td>
    </tr>
    <tr>
      <td>[C OC</td>
      <td>kcuf1 key_right</td>
      <td>Arrow right</td>
    </tr>
    <tr>
      <td>[D OD</td>
      <td>kcub1 key_left</td>
      <td>Arrow left</td>
    </tr>
    <tr>
      <td>[5~ [I</td>
      <td>kpp key_ppage</td>
      <td>PageUp</td>
    </tr>
    <tr>
      <td>[6~ [G</td>
      <td>knp key_npage</td>
      <td>PageDown</td>
    </tr>
    <tr>
      <td>[2~ [L</td>
      <td>kich1 key_ic</td>
      <td>Insert key</td>
    </tr>
    <tr>
      <td>[1~ [H OH [7~</td>
      <td>khome key_home</td>
      <td>Home key</td>
    </tr>
    <tr>
      <td>[4~ [F OF [8~</td>
      <td>kend key_end</td>
      <td>End key</td>
    </tr>
    <tr>
      <td>[11~ [M [[A OP</td>
      <td>key_f1</td>
      <td>F1</td>
    </tr>
    <tr>
      <td>[12~ [N [[B OQ</td>
      <td>key_f2</td>
      <td>F2</td>
    </tr>
    <tr>
      <td>[13~ [O [[C OR</td>
      <td>key_f3</td>
      <td>F3</td>
    </tr>
    <tr>
      <td>[14~ [P [[D OS</td>
      <td>key_f4</td>
      <td>F4</td>
    </tr>
    <tr>
      <td>[15~ [Q [[E</td>
      <td>key_f5</td>
      <td>F5</td>
    </tr>
    <tr>
      <td>[17~ [R</td>
      <td>key_f6</td>
      <td>F6</td>
    </tr>
    <tr>
      <td>[18~ [S</td>
      <td>key_f7</td>
      <td>F7</td>
    </tr>
    <tr>
      <td>[19~ [T</td>
      <td>key_f8</td>
      <td>F8</td>
    </tr>
    <tr>
      <td>[20~ [U</td>
      <td>key_f9</td>
      <td>F9</td>
    </tr>
    <tr>
      <td>[21~ [V</td>
      <td>key_f10</td>
      <td>F10</td>
    </tr>
    <tr>
      <td>[23~ [W</td>
      <td>key_f11</td>
      <td>F11</td>
    </tr>
    <tr>
      <td>[24~ [X</td>
      <td>key_f12</td>
      <td>F12</td>
    </tr>
    <tr>
      <td>\x7f \b</td>
      <td>kbs key_backspace</td>
      <td>Backspace key</td>
    </tr>
    <tr>
      <td>\x7f [3~</td>
      <td>kdch1 key_dc key_delete</td>
      <td>Delete key; <em>usually</em> sends [3~, but some send \x7f</td>
    </tr>
    <tr>
      <td>\x09</td>
      <td>-</td>
      <td>Tab key</td>
    </tr>
    <tr>
      <td>\x0d</td>
      <td>-</td>
      <td>Enter key</td>
    </tr>
  </tbody>
</table>
<div class="postscript" role="doc-endnotes"><strong>Footnotes</strong>
  <ol>
    <li>
      <p>Except FreeBSD system console where it’s <code>[30;1m</code>. <a href="https://www.arp242.net/#fnref:dim" class="reversefootnote" role="doc-backlink">↩</a></p>
    </li>
    <li>
      <p>Not super-widely supported, sometimes displays as reverse. <a href="https://www.arp242.net/#fnref:sitm" class="reversefootnote" role="doc-backlink">↩</a></p>
    </li>
    <li>
      <p>Often doesn’t do anything (because it’s annoying). <a href="https://www.arp242.net/#fnref:blink" class="reversefootnote" role="doc-backlink">↩</a></p>
    </li>
    <li>
      <p>Characters can still be copy/pasted. <a href="https://www.arp242.net/#fnref:invis" class="reversefootnote" role="doc-backlink">↩</a></p>
    </li>
    <li>
      <p>Top-left is 1;1 <a href="https://www.arp242.net/#fnref:cup" class="reversefootnote" role="doc-backlink">↩</a></p>
    </li>
    <li>
      <p>mtm terminfo doesn’t include the question mark, and Linux console adds another escape (<code>\x1b[?1c</code>). But for both this also works. <a href="https://www.arp242.net/#fnref:civis" class="reversefootnote" role="doc-backlink">↩</a></p>
    </li>
    <li>
      <p>Has <code>[?12l</code> for some, but works without that on all; for FreeBSD terminfo has <code>[=0C</code> but that doesn’t work (<code>[?25h</code> does) <a href="https://www.arp242.net/#fnref:cnorm" class="reversefootnote" role="doc-backlink">↩</a></p>
    </li>
  </ol>
</div>]]></description>
		
		
		<enclosure url="" length="0" type="" />

			</item>
		<item>
		<title>s/bash/zsh/g</title>
		<link>https://noise.getoto.net/2021/10/20/s-bash-zsh-g/</link>
		
		<dc:creator><![CDATA[arp242.net]]></dc:creator>
		<pubDate>Wed, 20 Oct 2021 00:00:00 +0000</pubDate>
				<category><![CDATA[Без категория]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[zsh]]></category>
		<guid isPermaLink="false">https://www.arp242.net/why-zsh.html</guid>

					<description><![CDATA[You would expect this to work, no?


bash% echo $(( .1 + .2 ))
bash: .1 + .2 : syntax error: operand expected (error token is ".1 + .2 ")



Well, bash says no, but zsh just works:


zsh% echo $(( .1 + .2 ))
0.30000000000000004      # Well, "works" ins...]]></description>
		
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Object Caching 24/64 objects using Memcached
Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Memcached

Served from: noise.getoto.net @ 2025-12-08 15:11:03 by W3 Total Cache
-->