<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Gray Soft / My Projects / I Just Want One Character!</title>
  <id>tag:graysoftinc.com,2014-03-20:/posts/22</id>
  <updated>2014-04-03T22:46:33Z</updated>
  <link rel="self" href="http://graysoftinc.com/my-projects/i-just-want-one-character/feed.xml"/>
  <link rel="alternate" href="http://graysoftinc.com/my-projects/i-just-want-one-character"/>
  <author>
    <name>James Edward Gray II</name>
  </author>
  <entry>
    <title>The 8th Comment on "I Just Want One Character!"</title>
    <link rel="alternate" href="http://graysoftinc.com/my-projects/i-just-want-one-character#comment_334"/>
    <id>tag:graysoftinc.com,2009-10-15:/comments/334</id>
    <updated>2014-04-03T22:46:33Z</updated>
    <summary>Well it looks like you just keep spinning off `Thread`s there, one a second.  The main `Thread` doesn&amp;#39;t wait for your `Thread.new { … }` block to finish, so it just keeps cycling and creating more `Thread`s.  Perhaps you meant to wait on each `Thr...</summary>
    <content type="html">&lt;p&gt;Well it looks like you just keep spinning off &lt;code&gt;Thread&lt;/code&gt;s there, one a second.  The main &lt;code&gt;Thread&lt;/code&gt; doesn't wait for your &lt;code&gt;Thread.new { … }&lt;/code&gt; block to finish, so it just keeps cycling and creating more &lt;code&gt;Thread&lt;/code&gt;s.  Perhaps you meant to wait on each &lt;code&gt;Thread&lt;/code&gt; to finish before moving on?  You could change your &lt;code&gt;Thread&lt;/code&gt; code to something like &lt;code&gt;Thread.new { … }.join&lt;/code&gt; to accomplish that.&lt;/p&gt;</content>
    <author>
      <name>James Edward Gray II</name>
    </author>
  </entry>
  <entry>
    <title>The 7th Comment on "I Just Want One Character!"</title>
    <link rel="alternate" href="http://graysoftinc.com/my-projects/i-just-want-one-character#comment_333"/>
    <id>tag:graysoftinc.com,2009-10-15:/comments/333</id>
    <updated>2014-04-03T22:46:33Z</updated>
    <summary>thanks Gray. really saved my night&amp;#39;s &amp;#39;hack&amp;#39; but:

```ruby
# -&amp;gt; i had to add extra requires and 
#################################################
require &amp;#39;rubygems&amp;#39;
require &amp;#39;highline/import&amp;#39;
require &amp;quot;highline/system_extensions&amp;quot;
include Hig...</summary>
    <content type="html">&lt;p&gt;thanks Gray. really saved my night's 'hack' but:&lt;/p&gt;

&lt;div class="highlight highlight-ruby"&gt;&lt;pre&gt;&lt;span class="c1"&gt;# -&amp;gt; i had to add extra requires and &lt;/span&gt;
&lt;span class="c1"&gt;#################################################&lt;/span&gt;
&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'rubygems'&lt;/span&gt;
&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'highline/import'&lt;/span&gt;
&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s2"&gt;"highline/system_extensions"&lt;/span&gt;
&lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;HighLine&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;SystemExtensions&lt;/span&gt;

&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="k"&gt;begin&lt;/span&gt;

&lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\r\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; 

&lt;span class="nb"&gt;sleep&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="no"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="n"&gt;char&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_character&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;char&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chr&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="nb"&gt;exit&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
&lt;span class="c1"&gt;###############################################33&lt;/span&gt;

&lt;span class="c1"&gt;#leaves my bash prompt (Ubuntu 8.04) unresponsive (actaully there's no&lt;/span&gt;
&lt;span class="c1"&gt;#more echoing of keyboard input within the prompt that executes this&lt;/span&gt;
&lt;span class="c1"&gt;#script!&lt;/span&gt;
&lt;span class="c1"&gt;#Inform me please, thanks.&lt;/span&gt;
&lt;span class="c1"&gt;#&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;</content>
    <author>
      <name>Nemesis Fixx</name>
    </author>
  </entry>
  <entry>
    <title>The 6th Comment on "I Just Want One Character!"</title>
    <link rel="alternate" href="http://graysoftinc.com/my-projects/i-just-want-one-character#comment_78"/>
    <id>tag:graysoftinc.com,2006-10-25:/comments/78</id>
    <updated>2014-04-03T22:42:54Z</updated>
    <summary>I&amp;#39;ve just released HighLine 1.2.3 which should fix the Cygwin issue.  Thanks for pointing it out.</summary>
    <content type="html">&lt;p&gt;I've just released HighLine 1.2.3 which should fix the Cygwin issue.  Thanks for pointing it out.&lt;/p&gt;</content>
    <author>
      <name>James Edward Gray II</name>
    </author>
  </entry>
  <entry>
    <title>The 5th Comment on "I Just Want One Character!"</title>
    <link rel="alternate" href="http://graysoftinc.com/my-projects/i-just-want-one-character#comment_77"/>
    <id>tag:graysoftinc.com,2006-10-22:/comments/77</id>
    <updated>2014-04-03T22:42:54Z</updated>
    <summary>`HighLine::SystemExtensions.get_character` does not work when executed on rxvt terminal under cygwin;
`# Unix savvy getc().  (Second choice.)` method must be used in this case.</summary>
    <content type="html">&lt;p&gt;&lt;code&gt;HighLine::SystemExtensions.get_character&lt;/code&gt; does not work when executed on rxvt terminal under cygwin;&lt;br&gt;&lt;code&gt;# Unix savvy getc().  (Second choice.)&lt;/code&gt; method must be used in this case.&lt;/p&gt;</content>
    <author>
      <name>gm.vlkv@gmail.com</name>
    </author>
  </entry>
  <entry>
    <title>The 4th Comment on "I Just Want One Character!"</title>
    <link rel="alternate" href="http://graysoftinc.com/my-projects/i-just-want-one-character#comment_76"/>
    <id>tag:graysoftinc.com,2006-10-22:/comments/76</id>
    <updated>2014-03-27T01:38:24Z</updated>
    <summary>Very nice, works flawlessly on both Linux(ubuntu) and WinXP. Thanks</summary>
    <content type="html">&lt;p&gt;Very nice, works flawlessly on both Linux(ubuntu) and WinXP. Thanks&lt;/p&gt;</content>
    <author>
      <name>Jon Egil</name>
    </author>
  </entry>
  <entry>
    <title>The 3rd Comment on "I Just Want One Character!"</title>
    <link rel="alternate" href="http://graysoftinc.com/my-projects/i-just-want-one-character#comment_75"/>
    <id>tag:graysoftinc.com,2006-10-19:/comments/75</id>
    <updated>2014-04-03T22:41:39Z</updated>
    <summary>`SystemExtensions` Rocks. 

I vendored it in Ruport and modified it slightly so that I could play around with getting the terminal geometry.

I think i just added a method or to for convenience, but I should really go ahead and stick them back...</summary>
    <content type="html">&lt;p&gt;&lt;code&gt;SystemExtensions&lt;/code&gt; Rocks. &lt;/p&gt;

&lt;p&gt;I vendored it in Ruport and modified it slightly so that I could play around with getting the terminal geometry.&lt;/p&gt;

&lt;p&gt;I think i just added a method or to for convenience, but I should really go ahead and stick them back in &lt;code&gt;HighLine&lt;/code&gt;…&lt;/p&gt;</content>
    <author>
      <name>Gregory</name>
    </author>
  </entry>
  <entry>
    <title>The 2nd Comment on "I Just Want One Character!"</title>
    <link rel="alternate" href="http://graysoftinc.com/my-projects/i-just-want-one-character#comment_71"/>
    <id>tag:graysoftinc.com,2006-10-07:/comments/71</id>
    <updated>2014-04-03T22:41:02Z</updated>
    <summary>Yeah, that was careless of me.  That shebang line only works on some operating systems.  It works on my Mac OS X 10.4 for example, but I believe 10.3 chokes on it.  Better to point it your local Ruby install, as Peter did.

If you have `HighLine...</summary>
    <content type="html">&lt;p&gt;Yeah, that was careless of me.  That shebang line only works on some operating systems.  It works on my Mac OS X 10.4 for example, but I believe 10.3 chokes on it.  Better to point it your local Ruby install, as Peter did.&lt;/p&gt;

&lt;p&gt;If you have &lt;code&gt;HighLine&lt;/code&gt; installed as a gem, you will need to make gems available, yes.  I generally don't like using an explicit require for that in the code, because it makes rubygems a dependancy.  Generally I just run the code with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ruby -rubygems ...
&lt;/code&gt;&lt;/pre&gt;</content>
    <author>
      <name>James Edward Gray II</name>
    </author>
  </entry>
  <entry>
    <title>The 1st Comment on "I Just Want One Character!"</title>
    <link rel="alternate" href="http://graysoftinc.com/my-projects/i-just-want-one-character#comment_70"/>
    <id>tag:graysoftinc.com,2006-10-07:/comments/70</id>
    <updated>2014-04-03T22:41:02Z</updated>
    <summary>Maybe i did something wrong but the above example didn&amp;#39;t work for me. I had to change the line:

```ruby
#!/usr/bin/env ruby -w
```

to

```ruby
#!/usr/bin/ruby -w
```

and also I had to add one more line:

```ruby
require &amp;#39;rubygems...</summary>
    <content type="html">&lt;p&gt;Maybe i did something wrong but the above example didn't work for me. I had to change the line:&lt;/p&gt;

&lt;div class="highlight highlight-ruby"&gt;&lt;pre&gt;&lt;span class="c1"&gt;#!/usr/bin/env ruby -w&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;to&lt;/p&gt;

&lt;div class="highlight highlight-ruby"&gt;&lt;pre&gt;&lt;span class="c1"&gt;#!/usr/bin/ruby -w&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;and also I had to add one more line:&lt;/p&gt;

&lt;div class="highlight highlight-ruby"&gt;&lt;pre&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'rubygems'&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;That is maybe because of that env didn't worked for me.&lt;/p&gt;</content>
    <author>
      <name>Peter</name>
    </author>
  </entry>
  <entry>
    <title>I Just Want One Character!</title>
    <link rel="alternate" href="http://graysoftinc.com/my-projects/i-just-want-one-character"/>
    <id>tag:graysoftinc.com,2006-10-01:/posts/22</id>
    <updated>2014-04-03T22:46:33Z</updated>
    <summary>Here's a simple trick that comes in handy surprisingly often.  If you want "any key" to really work for things other than return, you will like this one.</summary>
    <content type="html">&lt;p&gt;Every so often a person asks the question on Ruby Talk, "How can I get just one character from the keyboard (without needing the user to hit return)?"  Everyone is always quick to post solutions, but sadly there are some issues with almost every one of them.&lt;/p&gt;

&lt;p&gt;The general consensus is that this is a tough problem to solve correctly.  I say that's the exact reason to let &lt;a href="https://github.com/JEG2/highline"&gt;HighLine&lt;/a&gt; handle this for you:&lt;/p&gt;

&lt;div class="highlight highlight-ruby"&gt;&lt;pre&gt;&lt;span class="c1"&gt;#!/usr/bin/env ruby -w&lt;/span&gt;

&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s2"&gt;"highline/system_extensions"&lt;/span&gt;
&lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;HighLine&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;SystemExtensions&lt;/span&gt;

&lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;"Enter one character:  "&lt;/span&gt;
&lt;span class="n"&gt;char&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_character&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;char&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chr&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;That doesn't look too tough, does it?&lt;/p&gt;

&lt;p&gt;What's terrific about this solution is that under-the-hood &lt;code&gt;HighLine&lt;/code&gt; will check your platform and libraries and then try to use the solution that makes the most sense for your environment.  The code is really pretty robust too, because people a lot smarter than me have been sending in patches for over a year, slowly eliminating all of those tricky edge cases.&lt;/p&gt;

&lt;p&gt;As you can see, I've split this functionality of &lt;code&gt;HighLine&lt;/code&gt; into a separate module so you don't even need to load the full &lt;code&gt;HighLine&lt;/code&gt; system.  This was done just because this is such a real and common problem.  This section of &lt;code&gt;HighLine&lt;/code&gt; is &lt;a href="https://github.com/JEG2/highline/blob/master/lib/highline/system_extensions.rb"&gt;one pure Ruby file&lt;/a&gt;, so feel free to vendor it if the external dependency is an issue.&lt;/p&gt;

&lt;p&gt;Trust me, reading individual characters from the keyboard doesn't have to be that tough.  You just need the right tool for the job.&lt;/p&gt;</content>
    <author>
      <name>James Edward Gray II</name>
    </author>
  </entry>
</feed>
