<?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>chys&#039;s random notes &#187; terminal</title>
	<atom:link href="http://en.chys.info/tag/terminal/feed/" rel="self" type="application/rss+xml" />
	<link>http://en.chys.info</link>
	<description>Study more problems; Talk less of isms.</description>
	<lastBuildDate>Tue, 27 Dec 2011 11:56:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Reduce the delay after ESC in ncurses</title>
		<link>http://en.chys.info/2009/09/esdelay-ncurses/</link>
		<comments>http://en.chys.info/2009/09/esdelay-ncurses/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 15:55:01 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ncurses]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tiary]]></category>

		<guid isPermaLink="false">http://en.chys.info/?p=667</guid>
		<description><![CDATA[In ncurses-based programs, the default delay after the ESC key is way too long. (Such a delay is necessary to differentiate the ESC key from function keys.) There seems to be no such delay in VIM. But with strace, we can find that VIM actually delays, but for only 25 milliseconds, shorter than 100ms &#8211; [...]<hr/>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.gnu.org/software/ncurses/">ncurses</a>-based programs, the default delay after the ESC key is way too long. (Such a delay is necessary to differentiate the ESC key from function keys.)</p>
<p>There seems to be no such delay in <a href="http://www.vim.org">VIM</a>. But with <a href="http://linux.die.net/man/1/strace">strace</a>, we can find that VIM actually delays, but for only 25 milliseconds, shorter than 100ms &#8211; the minimal time interval that human can perceive:</p>
<blockquote><pre>
read(0, "\33"..., 4096)                 = 1
select(6, [0 3 5], NULL, [0 3], {0, 0}) = 0 (Timeout)
gettimeofday({1253979790, 537775}, NULL) = 0
select(6, [0 3 5], NULL, [0 3], {0, <span style="color: red; font-weight: bold;">25000</span>}) = 0 (Timeout)
</pre>
</blockquote>
<p>If 25ms works reliably for VIM, so should it do for other programs. There seems to be no functions setting this interval in ncurses, but we can directly modify the global variable <code>ESCDELAY</code>. Ncurses also accepts the environment variable also named <code>ESCDELAY</code>, so we may also want to honor the user&#8217;s choice:</p>
<blockquote><pre>
if (getenv ("ESCDELAY") == NULL)
  ESCDELAY = 25;
</pre>
</blockquote>
<p>Not confident in its portability, I detect this undocumented (it seems) feature with <a href="http://www.cmake.org">cmake</a> in <a href="http://code.google.com/p/tiary">tiary</a> (my project).</p>
<hr/>
<p>Update (Feb. 22, 2010): It&#8217;s preferable to use the function <code>set_escdelay</code>.</p>
<hr/><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2009/09/esdelay-ncurses/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How BASH Changes Terminal Window Title</title>
		<link>http://en.chys.info/2008/12/how-bash-changes-terminal-window-title/</link>
		<comments>http://en.chys.info/2008/12/how-bash-changes-terminal-window-title/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 06:52:00 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://blog.chys.info/2008/12/how-bash-changes-terminal-window-title/</guid>
		<description><![CDATA[In many distributions bash automatically changes the terminal title. I thought it was hardcoded in bash, but it turns out to be not. It is usually implemented with PROMPT_COMMAND. Environment variable $PROMPT_COMMAND defines the command to be automatically executed before displaying the primary prompt (i.e. $PS1). It is set by a script that is sourced [...]<hr/>
Related posts:<ol>
<li><a href='http://en.chys.info/2009/04/globstar-in-bash-4-follows-symlinks/' rel='bookmark' title='globstar in bash 4 follows directory symlinks'>globstar in bash 4 follows directory symlinks</a></li>
<li><a href='http://en.chys.info/2008/11/send-ctrl-a-to-sessions-in-screen/' rel='bookmark' title='Send Ctrl-A to sessions in SCREEN'>Send Ctrl-A to sessions in SCREEN</a></li>
<li><a href='http://en.chys.info/2009/02/extglob/' rel='bookmark' title='Extended pattern matching in BASH'>Extended pattern matching in BASH</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In many distributions <a href="http://www.gnu.org/software/bash/">bash</a> automatically changes the terminal title. I thought it was hardcoded in bash, but it turns out to be not. It is usually implemented with <code>PROMPT_COMMAND</code>.</p>
<p>Environment variable <code>$PROMPT_COMMAND</code> defines the command to be automatically executed before displaying the primary prompt (i.e. <code>$PS1</code>). It is set by a script that is sourced by interative instances of bash. In Gentoo it is in <code>/etc/bash/bashrc</code>:<br />
<blockquote>
<pre>case ${TERM} in
    xterm*|rxvt*|Eterm|aterm|kterm|gnome*|interix)
        PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
        ;;
    screen)
        PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
        ;;
esac</pre>
</blockquote>
<p>
In fact, the first version above also works with newer versions of <a href="http://www.gnu.org/software/screen/">screen</a>.
<div class="blogger-post-footer">
<hr />
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://creativecommons.org/images/public/somerights20.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</div>
<hr/><p>Related posts:<ol>
<li><a href='http://en.chys.info/2009/04/globstar-in-bash-4-follows-symlinks/' rel='bookmark' title='globstar in bash 4 follows directory symlinks'>globstar in bash 4 follows directory symlinks</a></li>
<li><a href='http://en.chys.info/2008/11/send-ctrl-a-to-sessions-in-screen/' rel='bookmark' title='Send Ctrl-A to sessions in SCREEN'>Send Ctrl-A to sessions in SCREEN</a></li>
<li><a href='http://en.chys.info/2009/02/extglob/' rel='bookmark' title='Extended pattern matching in BASH'>Extended pattern matching in BASH</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2008/12/how-bash-changes-terminal-window-title/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jumbled Characters after Catting a Binary File</title>
		<link>http://en.chys.info/2008/10/jumbled-characters-after-catting-a-binary-file/</link>
		<comments>http://en.chys.info/2008/10/jumbled-characters-after-catting-a-binary-file/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 02:05:00 +0000</pubDate>
		<dc:creator>chys</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://blog.chys.info/2008/10/jumbled-characters-after-catting-a-binary-file/</guid>
		<description><![CDATA[When this happens, simply press Ctrl-V Ctrl-O Ctrl-M. Or alternatively, type &#8220;reset&#8221; and Return (Enter). A terminal interpretes 0x0e byte as &#8220;activates the G1 character set&#8221;, and 0x0f as &#8220;activates the G0 character set&#8221;. The characters we read are in the G0 set. So, if there is no byte 0x0f after the last 0x0e in [...]<hr/>
Related posts:<ol>
<li><a href='http://en.chys.info/2009/03/utf-8/' rel='bookmark' title='UTF-8'>UTF-8</a></li>
<li><a href='http://en.chys.info/2008/10/determine-the-existence-of-a-file-in-makefile/' rel='bookmark' title='Determine the existence of a file in Makefile'>Determine the existence of a file in Makefile</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When this happens, simply press Ctrl-V Ctrl-O Ctrl-M. Or alternatively, type &#8220;reset&#8221; and Return (Enter).</p>
<p>A terminal interpretes 0x0e byte as &#8220;activates the G1 character set&#8221;, and 0x0f as &#8220;activates the G0 character set&#8221;. The characters we read are in the G0 set. So, if there is no byte 0x0f after the last 0x0e in a binary file, everything will be shown in the unreadable G1 set, including the next shell prompt.</p>
<p>How does Ctrl-V Ctrl-O Ctrl-M work?<br />Ctrl-V is an &#8216;escape character&#8217; &#8211; the next keystroke will always be interpreted as a literal character; Ctrl-O is 0x0f; Ctrl-M is carriage return. So the shell gets the command &#8220;x0f&#8221; and outputs the error message &#8220;bash: x0f: command not found&#8221;. The byte 0x0f in this message turns the active character back to the readable G0.</p>
<p>G1 character set is not often used these days. Konsole chooses not to implement it at all, so we never have this problem in Konsole.
<div class="blogger-post-footer">
<hr />
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://creativecommons.org/images/public/somerights20.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>.</div>
<hr/><p>Related posts:<ol>
<li><a href='http://en.chys.info/2009/03/utf-8/' rel='bookmark' title='UTF-8'>UTF-8</a></li>
<li><a href='http://en.chys.info/2008/10/determine-the-existence-of-a-file-in-makefile/' rel='bookmark' title='Determine the existence of a file in Makefile'>Determine the existence of a file in Makefile</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://en.chys.info/2008/10/jumbled-characters-after-catting-a-binary-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

