<?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>code.random() &#187; Uncategorized</title>
	<atom:link href="http://code.pui.ch/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.pui.ch</link>
	<description>Random code-snippets and tips</description>
	<lastBuildDate>Thu, 19 Jan 2012 07:09:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to switch gnu screen windows in iTerm2 via keyboard shortcuts</title>
		<link>http://code.pui.ch/2011/11/03/how-to-switch-gnu-screen-windows-in-iterm2-via-keyboard-shortcuts/</link>
		<comments>http://code.pui.ch/2011/11/03/how-to-switch-gnu-screen-windows-in-iterm2-via-keyboard-shortcuts/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 11:17:08 +0000</pubDate>
		<dc:creator>philipp.keller</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://code.pui.ch/?p=35</guid>
		<description><![CDATA[I&#8217;m obsessed with having optimal keyboard shortcuts with whatever program. I recently switched from using client-side textmate to server-side vim as I want to move as much as possible to the cloud.
I have looked for a good way to switch windows in gnu screen for a long time without having to use ctrl-a 1. That&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m obsessed with having optimal keyboard shortcuts with whatever program. I recently switched from using client-side textmate to server-side vim as I want to move as much as possible to the cloud.</p>
<p>I have looked for a good way to switch windows in gnu screen for a long time without having to use <code>ctrl-a 1</code>. That&#8217;s what I came up with:</p>
<p><span id="more-35"></span></p>
<p>
In Preferences, map your keys (e.g. cmd-1 or alt-1) to action: send hex code.<br />
The hex code depends on what is your &#8220;screen key&#8221;.
</p>
<h3>Screen key ctrl-z</h3>
<table>
<tr>
<th>Screen<br />number</th>
<th>hex code</th>
</tr>
<tr>
<td>1</td>
<td><code>0x1a 0x31</code></td>
</tr>
<tr>
<td>2</td>
<td><code>0x1a 0x32</code></td>
</tr>
<tr>
<td>9</td>
<td><code>0x1a 0x39</code></td>
</tr>
</table>
<h3>Screen key ctrl-a</h3>
<table>
<tr>
<th>Screen<br />number</th>
<th>hex code</th>
</tr>
<tr>
<td>1</td>
<td><code>0x01 0x31</code></td>
</tr>
<tr>
<td>2</td>
<td><code>0x01 0x32</code></td>
</tr>
<tr>
<td>9</td>
<td><code>0x01 0x39</code></td>
</tr>
</table>
<h3>What is they key stroke in hex?</h3>
<p>If you want to map other commands, <a href="http://www.unix-manuals.com/refs/misc/ascii-table.html">here</a> is a good resource</p>
]]></content:encoded>
			<wfw:commentRss>http://code.pui.ch/2011/11/03/how-to-switch-gnu-screen-windows-in-iterm2-via-keyboard-shortcuts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: display refreshing status (like top)</title>
		<link>http://code.pui.ch/2010/04/04/python-display-refreshing-status-like-top/</link>
		<comments>http://code.pui.ch/2010/04/04/python-display-refreshing-status-like-top/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 21:24:50 +0000</pubDate>
		<dc:creator>philipp.keller</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://code.pui.ch/?p=18</guid>
		<description><![CDATA[In scripts I often want to display some status information (e.g. progress), this can be achieved with e.g.:
PLAIN TEXT
PYTHON:




print "progress: %i %%\r" % i,


sys.stdout.flush&#40;&#41; 






but this just works for one-liners. I wanted to have what top or less do: open a new "window" and being able to write everywhere in the window, not just on [...]]]></description>
			<content:encoded><![CDATA[<p>In scripts I often want to display some status information (e.g. progress), this can be achieved with e.g.:</p>
<div class="igBar"><span id="lpython-3"><a href="#" onclick="javascript:showPlainTxt('python-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PYTHON:</span>
<div id="python-3">
<div class="python">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">"progress: %i %%<span style="color: #000099; font-weight: bold;">\r</span>"</span> % i,</div>
</li>
<li style="font-weight: bold;color:#26536A; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>but this just works for one-liners. I wanted to have what <code>top</code> or <code>less</code> do: open a new "window" and being able to write <strong>everywhere</strong> in the window, not just on the last line.</p>
<p>Found out that <a href="http://docs.python.org/library/curses.html">curses</a> does exactly that - but I didn't find a stripped-to-the-bare-necessities-example, so here you are:</p>
<div class="igBar"><span id="lpython-4"><a href="#" onclick="javascript:showPlainTxt('python-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PYTHON:</span>
<div id="python-4">
<div class="python">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">curses</span>, <span style="color: #dc143c;">time</span></div>
</li>
<li style="font-weight: bold;color:#26536A; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">datetime</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">w = <span style="color: #dc143c;">curses</span>.<span style="color: black;">initscr</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">try</span>:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; w.<span style="color: black;">erase</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; w.<span style="color: black;">addstr</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">"some status..<span style="color: #000099; font-weight: bold;">\n</span>current time<span style="color: #000099; font-weight: bold;">\n</span>%s"</span> % <span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; w.<span style="color: black;">refresh</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;color:#800000;">1</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">finally</span>:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; ">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #dc143c;">curses</span>.<span style="color: black;">endwin</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://code.pui.ch/2010/04/04/python-display-refreshing-status-like-top/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

