<?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>High Fibre Programming &#187; command line</title>
	<atom:link href="http://www.4pmp.com/tag/command-line/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.4pmp.com</link>
	<description>PHP, MySQL, C, Java, Linux and other great after dinner speech topics</description>
	<lastBuildDate>Tue, 17 Jan 2012 09:10:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Spinning command line cursor in Java and PHP</title>
		<link>http://www.4pmp.com/2010/01/spinning-command-line-cursor-in-java-and-php/</link>
		<comments>http://www.4pmp.com/2010/01/spinning-command-line-cursor-in-java-and-php/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 09:46:03 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[spin]]></category>
		<category><![CDATA[spinning]]></category>

		<guid isPermaLink="false">http://www.4pmp.com/?p=231</guid>
		<description><![CDATA[Update: I have created an updated article which describes a multithreaded approach in Java Spinning command line cursor in Java I think I must be really bored this morning, I can&#8217;t believe I&#8217;m actually blogging this, but it might be useful for someone, who knows.   Anyway, I am currently writing a program that sits and [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Update:</strong>   I have created an updated article which describes a multithreaded approach in Java <a href="http://www.4pmp.com/2010/01/spinning-command-line-cursor-in-java/">Spinning command line cursor in Java</a></em></p>
<p>I think I must be really bored this morning, I can&#8217;t believe I&#8217;m actually blogging this, but it might be useful for someone, who knows.   Anyway, I am currently writing a program that sits and does stuff for a very long time, and I need a way to nicely indicate the program is still running and doing its stuff.   So I have created a little method that prints a spinning cursor on the command line.   The implementation would of course have to be multithreaded; one thread to do stuff, the other to spin the cursor &#8211; if there&#8217;s time I&#8217;ll update it to a more complete solution, but for now here&#8217;s the spin implementation:</p>
<pre class="brush: java;">

public class Spin
{
    public static void main(String[] args) throws InterruptedException
    {
        String[] phases = {&quot;|&quot;, &quot;/&quot;, &quot;-&quot;, &quot;\\&quot;};

        System.out.printf(&quot;Spinning... |&quot;);

        while (true)
        {
            for (String phase : phases)
            {
                System.out.printf(&quot;\b&quot;+phase);
                Thread.sleep(100);
            }
        }
    }
}
</pre>
<p>And here it is in PHP.</p>
<pre class="brush: php;">
&lt;?php

    $phases = array(&quot;|&quot;, &quot;/&quot;, &quot;-&quot;, &quot;\\&quot;);

    printf(&quot;Spinning... |&quot;);

    while (1)
    {
        foreach ($phases AS $phase)
        {
            printf('%s%s', chr(8), $phase);
            usleep(100000); // Replace this with one iteration of doing stuff
        }
    }
</pre>
<p>Of course PHP doesn&#8217;t support threading so you&#8217;d have to call each iteration of the &#8220;doing stuff&#8221; loop inside the spin loop which would mean you&#8217;d get a bit of a jumpy spinning cursor but I think most people could live with that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.4pmp.com/2010/01/spinning-command-line-cursor-in-java-and-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

