<?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>BenV&#039;s notes &#187; perl</title>
	<atom:link href="http://notes.benv.junerules.com/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://notes.benv.junerules.com</link>
	<description>Rants and notes</description>
	<lastBuildDate>Wed, 28 Jul 2010 13:36:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Necta.pl lives again!</title>
		<link>http://notes.benv.junerules.com/all/software/necta-pl-lives-again/</link>
		<comments>http://notes.benv.junerules.com/all/software/necta-pl-lives-again/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 16:35:17 +0000</pubDate>
		<dc:creator>BenV</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[irssi]]></category>
		<category><![CDATA[necta]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://notes.benv.junerules.com/?p=787</guid>
		<description><![CDATA[When nectarine died a few years ago (or at least, that&#8217;s how I view it) with their broken harddisks, lost backups and whatnot, I gave up on the necta.pl tool me and a friend of mine had written. However, a few months ago I got back into listening to the new scenemusic.eu who got everything [...]]]></description>
			<content:encoded><![CDATA[<p>When nectarine died a few years ago (or at least, that&#8217;s how I view it) with their broken harddisks, lost backups and whatnot, I gave up on the necta.pl tool me and a friend of mine had written.<br />
However, a few months ago I got back into listening to the new scenemusic.eu who got everything back up and running based on recovered data from the old Nectarine.<br />
It seems like they did a proper job of setting up a new site, and they even provide a nice xml backend for tools like this.</p>
<p>So after a while I decided to revive our tool. This time I took the time to curse even more at Irssi and their script support, so I implemented the nonblocking fetcher and nectarine parser<br />
in separate libraries. Well, isn&#8217;t that fun. Reloading those things was a problem (/script load necta wouldn&#8217;t reload those underlying libraries), but fortunately Garion helped me out here after <a href="http://comments.gmane.org/gmane.network.irc.irssi.user/889">a mail to the Irssi mailing list</a>. Thanks Garion!</p>
<p>Anyway, I&#8217;ve put the first release up for download on this page:<br />
<a href="http://notes.benv.junerules.com/necta/">http://notes.benv.junerules.com/necta/</a></p>
<p>Or a direct link to the download:<br />
<a href="http://notes.benv.junerules.com/wp-content/plugins/download-monitor/download.php?id=irssi_necta-0.01.tar.bz2" title="Downloaded 24 times">Irssi Necta script v0.01</a> - Version 0.01 - SHA: 62f7c4994750dac154807f2be43c85a8d2020182</p>
<p>Let the bug report begin <img src='http://notes.benv.junerules.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
<a href="http://notes.benv.junerules.com/wp-content/uploads/2010/04/necta-irssi-0.01-test.png"><img src="http://notes.benv.junerules.com/wp-content/uploads/2010/04/necta-irssi-0.01-test-300x122.png" alt="necta-irssi-0.01" title="necta-irssi-0.01" width="300" height="122" class="alignnone size-medium wp-image-791" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://notes.benv.junerules.com/all/software/necta-pl-lives-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dos2unix</title>
		<link>http://notes.benv.junerules.com/all/software/dos2unix/</link>
		<comments>http://notes.benv.junerules.com/all/software/dos2unix/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 17:41:37 +0000</pubDate>
		<dc:creator>BenV</dc:creator>
				<category><![CDATA[Morons]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[dos]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://notes.benv.junerules.com/?p=237</guid>
		<description><![CDATA[Another annoying thing: morons that save their files with dos line endings. Also known as &#8220;I&#8217;ve got motherfucking ^M in my file, AAAIIEEEEYGGrrgrll&#8220;. I usually find out about this when bash complains about stuff like this: benv@janeman:~$ ./bla.pl -bash: ./bla.pl: /usr/bin/perl^M: bad interpreter: No such file or directory (HAAAAAT!!!) Solution: benv@janeman:~$ vim kankerfile :set fileformat=unix [...]]]></description>
			<content:encoded><![CDATA[<p>Another annoying thing: morons that save their files with dos line endings.<br />
Also known as &#8220;<span style="color:#FF0000">I&#8217;ve got motherfucking ^M in my file, AAAIIEEEEYGGrrgrll</span>&#8220;.<br />
I usually find out about this when bash complains about stuff like this:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">benv<span style="color: #000000; font-weight: bold;">@</span>janeman:~$ .<span style="color: #000000; font-weight: bold;">/</span>bla.pl <br />
-bash: .<span style="color: #000000; font-weight: bold;">/</span>bla.pl: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">perl</span>^M: bad interpreter: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory</div></div>
<p>(<span style="font-size: 200%; color:#FF0000">HAAAAAT!!!</span>)</p>
<p>Solution:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">benv<span style="color: #000000; font-weight: bold;">@</span>janeman:~$ <span style="color: #c20cb9; font-weight: bold;">vim</span> kankerfile<br />
:<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #007800;">fileformat</span>=unix<br />
:wq</div></div>
<p>(Don&#8217;t confuse fileformat with filetype, one is used for encoding, the other for things as syntax highlighting)</p>
<p>Solution 2:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">benv<span style="color: #000000; font-weight: bold;">@</span>janeman:~$ dos2unix kankerfile</div></div>
<p>I never use this since I never have that piece of cancer called dos2unix, but some distros do.</p>
<p>Solution 3:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-ie</span> <span style="color: #ff0000;">'s/\r//g'</span> bla.pl</div></div>
<p>That should fix it. On to the &#8220;let&#8217;s trash my home directory with my fancy new perl script that I just converted&#8221; <img src='http://notes.benv.junerules.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://notes.benv.junerules.com/all/software/dos2unix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(n)Curses magic part 2: magic!</title>
		<link>http://notes.benv.junerules.com/all/software/ncurses-magic-part-2-magic/</link>
		<comments>http://notes.benv.junerules.com/all/software/ncurses-magic-part-2-magic/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 16:15:00 +0000</pubDate>
		<dc:creator>BenV</dc:creator>
				<category><![CDATA[Boring]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[curses]]></category>
		<category><![CDATA[ncurses]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://notes.benv.junerules.com/?p=187</guid>
		<description><![CDATA[So while messing around with some perl/curses stuff I got fancy with colors and soon found out about the limited support of colors in terminals and therefore also Curses. Anyway, I made this little &#8220;fractal plasma&#8221; thingy with it, see if you can get it running It&#8217;s not really a fractal plasma, so don&#8217;t get [...]]]></description>
			<content:encoded><![CDATA[<p>So while messing around with some perl/curses stuff I got fancy with colors and soon found out about the limited support of colors in terminals and therefore also Curses.<br />
Anyway, I made this little &#8220;fractal plasma&#8221; thingy with it, see if you can get it running <img src='http://notes.benv.junerules.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
It&#8217;s not really a fractal plasma, so don&#8217;t get technical on that, but it describes it best I think.</p>
<p>To get it running, open up your favorite terminal that supports 256 colors and allows palette changing &#8211; I found both xterm and urxvt to work.<br />
Make sure your TERM variable is set to something that allows this, for instance in urxvt:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">TERM</span>=rxvt-256color<br />
$ .<span style="color: #000000; font-weight: bold;">/</span>fractplasm.pl</div></div>
<p>or this worked for me with xterm:</p>
<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">TERM</span>=xterm-256color<br />
$ .<span style="color: #000000; font-weight: bold;">/</span>fractplasm.pl</div></div>
<p>Something like this is the result:<br />
<a href="http://notes.benv.junerules.com/wp-content/uploads/2009/08/fractplasm.png"><img src="http://notes.benv.junerules.com/wp-content/uploads/2009/08/fractplasm-300x150.png" alt="fractplasm" title="fractplasm" width="300" height="150" class="aligncenter size-medium wp-image-188" /></a><br />
<a href="http://notes.benv.junerules.com/wp-content/uploads/2009/08/fractplasm2.png"><img src="http://notes.benv.junerules.com/wp-content/uploads/2009/08/fractplasm2-300x209.png" alt="fractplasm2" title="fractplasm2" width="300" height="209" class="aligncenter size-medium wp-image-190" /></a></p>
<a href="http://notes.benv.junerules.com/wp-content/plugins/download-monitor/download.php?id=fractplasm.pl" title="Downloaded 146 times">fractplasm.pl</a> - Version 0.1 - SHA: 83086edd86b25eed5fddcbbf6beaae53924e06f6
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.benv.junerules.com/all/software/ncurses-magic-part-2-magic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>(n)Curses magic: are you a magician?</title>
		<link>http://notes.benv.junerules.com/all/software/ncurses-magic-are-you-a-magician/</link>
		<comments>http://notes.benv.junerules.com/all/software/ncurses-magic-are-you-a-magician/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 14:39:13 +0000</pubDate>
		<dc:creator>BenV</dc:creator>
				<category><![CDATA[Morons]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[curses]]></category>
		<category><![CDATA[ncurses]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Slackbuild.pl]]></category>

		<guid isPermaLink="false">http://notes.benv.junerules.com/?p=158</guid>
		<description><![CDATA[Hej readers, I decided to work on making slackbuild.pl a bit more acceptable in terms of usability and looks. The reason for this is that the dialog program doesn&#8217;t exactly do what I want. That is, it works&#8230;. but that&#8217;s pretty much all I can say about it. It doesn&#8217;t allow me to make a [...]]]></description>
			<content:encoded><![CDATA[<p>Hej readers,</p>
<p>I decided to work on making slackbuild.pl a bit more acceptable in terms of usability and looks. The reason for this is that the dialog program doesn&#8217;t exactly do what I want.<br />
That is, it works&#8230;. but that&#8217;s pretty much all I can say about it. It doesn&#8217;t allow me to make a comined checkbox/menu thing that I want for my configure options part. Next to that it&#8217;s tedious to fork and parse its output all the time, and let&#8217;s not even get started about looks and input issues.<br />
So I figured: hmm, dialog is made in ncurses, perl has a Curses lib&#8230;. let&#8217;s play!<span id="more-158"></span></p>
<p>First off I read through most of <a href="http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/" title="NCURSES programming howto">NCURSES Programming HOWTO</a>. Somehow it felt familiar, probably because I already went through it when messing with iotop. Next, I realized that google is pretty much useless when you try to search for &#8216;curses&#8217; and perl, probably because it&#8217;s the misspelled version of &#8216;cursus&#8217; which means &#8216;course&#8217; in dutch. However, ncurses is something you can search for and find -some- (but few) bits and pieces of information.</p>
<p>Time for a hello world.</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span><br />
<span style="color: #000000; font-weight: bold;">use</span> Curses<span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># init curses</span><br />
initscr<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
noecho<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
start_color<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
init_pair<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> COLOR_CYAN<span style="color: #339933;">,</span> COLOR_BLACK<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Print some stuff and wait for user input</span><br />
attron<span style="color: #009900;">&#40;</span>COLOR_PAIR<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
addstr<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Hello, world!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
getch<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Cleanup and end</span><br />
endwin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>And we run this, and voila:<br />
<a href="http://notes.benv.junerules.com/wp-content/uploads/2009/08/curses1.png"><img src="http://notes.benv.junerules.com/wp-content/uploads/2009/08/curses1-300x150.png" alt="curses1" title="curses1" width="300" height="150" class="aligncenter size-medium wp-image-161" /></a></p>
<p>Well, that was easy enough. Of course I already knew all this shit, I made iotop after all&#8230;<br />
Now time for more advanced trickery: windows.<br />
What I want is simple: tailbox, yesnobox, checkboxconfigureoptionsthingy and all that with some good style.<br />
&#8220;<span style="color: #FF0000">YOU SAID SIMPLE!</span>&#8221;<br />
Well, I never said it would be easy <img src='http://notes.benv.junerules.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>So my idea was to make the stdscr the backtitle, should be easy enough to always paint that the same way right?<br />
And then make the other things windows above that. Now the mysteries start.<br />
A little code to test the windowing concepts:</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span><br />
<span style="color: #000000; font-weight: bold;">use</span> Curses<span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># init again</span><br />
initscr<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
noecho<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
cbreak<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># no waiting for enter anymore on getch</span><br />
start_color<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
init_pair<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> COLOR_CYAN<span style="color: #339933;">,</span> COLOR_BLACK<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># make some windows that overlap</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$win</span> <span style="color: #339933;">=</span> newwin<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$win2</span> <span style="color: #339933;">=</span> newwin<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># some text in them</span><br />
addstr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;World!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
addstr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Hello&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># give them borders</span><br />
attrset<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win</span><span style="color: #339933;">,</span> COLOR_PAIR<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
box<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
attroff<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win</span><span style="color: #339933;">,</span> COLOR_PAIR<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
box<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win2</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'|'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Show them! (in correct overlapping order!)</span><br />
refresh<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
refresh<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Make user press 'q' this time</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$key</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$key</span> <span style="color: #339933;">=</span> getch<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">ne</span> ERR <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">$key</span> <span style="color: #b1b100;">ne</span> <span style="color: #ff0000;">'q'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># cleanup and exit</span><br />
delwin<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
delwin<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
endwin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>And here&#8217;s our beautiful result:<br />
<a href="http://notes.benv.junerules.com/wp-content/uploads/2009/08/curses2.png"><img src="http://notes.benv.junerules.com/wp-content/uploads/2009/08/curses2-300x150.png" alt="curses2" title="curses2" width="300" height="150" class="aligncenter size-medium wp-image-166" /></a><br />
&#8230;. what the.<br />
Our window is empty?<br />
But how could this be?<br />
<span style="color: #FF00FF">M</span><span style="color: #FF5555">A</span><span style="color: #00FF55">G</span><span style="color: #55FFFF">I</span><span style="color: #77aaFF">C</span><span style="color: #9f00FF">!</span><span style="color: #33AA66">!</span><span style="color: #66AAFF">!</span><span style="color: #991155">!</span><br />
However, it does wait for the &#8216;q&#8217; button before exiting, so not everything failed&#8230;</p>
<p>This sort of nonsense is exactly the reason why I started this post. Right now I&#8217;m having some serious doubts about continuing this curse*COUGH*s project, but on the other hand, it&#8217;s a nice challenge. Probably one of the reasons dialog is such a piece of junk&#8230; the library is garbage! <img src='http://notes.benv.junerules.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Note that there are a few other options, such as <a href="http://search.cpan.org/~mdxi/Curses-UI-0.9607/lib/Curses/UI.pm" title="Curses::UI">Curses::UI</a>, but they seem to be a bit more junk than I want, not to mention another depedency. Nah, I&#8217;ll figure it out using Curses for as long as I can manage to not go crazy.</p>
<p>Some pointers I found out:</p>
<ul>
<li>Printing stuff outside a window (because the window is too small) makes it go bonkers. It might not appear at all, overwrite other stuff&#8230; you name it.</li>
<li>A big pitfall is the y,x syntax. Where one would expect coordinates in the x,y format, curses makes you curse and reverse.</li>
<li>Another pitfall is forgetting the refresh, or messing up the order of the refreshes. I&#8217;m writing some wrappers for that in slackbuild.pl.</li>
<li>Overlapping windows are another source of fun, in order to make sure the overlapped window gets repainted properly you can use <code class="codecolorer perl vibrant"><span class="perl">touchwin<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$win</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></span></code> on it.</li>
</ul>
<p>Oh yeah, if you ever decide to write a curses program:<br />
Make sure to set a __DIE__ handler that RESTORES THE TERMINAL PROPERLY! If one thing annoys people it&#8217;s messing up their stuff&#8230;. and not closing Curses properly does exactly that.<br />
For those who wonder how to get out of such a broken terminal, type in &#8216;<span style="color: #00FFFF">reset</span>&#8216; and hit enter. (or twice if you&#8217;re a bad typist). No, this won&#8217;t reset your pc, it will simply reset your terminal to sanity.</p>
<p>&#8220;<span style="color:#FF0055">But what about the broken code in the second example?</span>&#8221;<br />
Oh yeah&#8230; another case of forgetting to call refresh. What we did there was to properly refresh the imaginary windows.<br />
However, we forgot to refresh the real stdscr window that contains them! So nothing was output to the screen. Lovely.<br />
It&#8217;s still a bit fuzzy here though, so don&#8217;t mind me if I screwed up the reasoning, but that&#8217;s what I understand about it now. It&#8217;ll get better <img src='http://notes.benv.junerules.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
Anyway, insert a <code class="codecolorer perl vibrant"><span class="perl">refresh<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></span></code> at line 25 and it&#8217;ll do what you&#8217;d expect. It&#8217;ll look like this:<br />
<a href="http://notes.benv.junerules.com/wp-content/uploads/2009/08/curses3.png"><img src="http://notes.benv.junerules.com/wp-content/uploads/2009/08/curses3-300x195.png" alt="curses3" title="curses3" width="300" height="195" class="aligncenter size-medium wp-image-172" /></a></p>
<p>Good luck with your cursed rabbits!</p>
<p>***<span style="color: #00FF00">followup here:</span><a href="http://notes.benv.junerules.com/software/ncurses-magic-part-2-magic/">ncurses magic part 2</a>***</p>
]]></content:encoded>
			<wfw:commentRss>http://notes.benv.junerules.com/all/software/ncurses-magic-are-you-a-magician/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
