\b not working?

Hi,

New to Ruby and can’t seem to get the \b escape to work. Code:

j=0
while j<10
print rand(1…10)
sleep (0.1)
print “\b”
j+=1
end

Output:

4523175329

  • just a series of 10 random numbers on the same line.

Am I missing something, or shouldn’t it backspace, and print all the #s
in the first character space?

Your help appreciated!
Jeff

On 14 September 2012 09:24, Cookie R. [email protected] wrote:

end
Jeff
In short: it depends where you’re printing it.

The raw bytes streaming from your program’s $stdout stream include a
bunch of digits (value 0x30 to 0x39) and the odd “\b” (0x08). It’s up
to the terminal/console/etc. that receives them and formats them for
display to interpret the 0x08-bytes the way you intended.

Where are you running said script? (Which operating system, terminal
emulator, etc.?)

Thanks for your reply!

I’m on a Mac, running Aptana Studio 3. Does that help?

Cheers

Matthew K. wrote in post #1075924:

On 14 September 2012 09:24, Cookie R. [email protected] wrote:

end
Jeff
In short: it depends where you’re printing it.

The raw bytes streaming from your program’s $stdout stream include a
bunch of digits (value 0x30 to 0x39) and the odd “\b” (0x08). It’s up
to the terminal/console/etc. that receives them and formats them for
display to interpret the 0x08-bytes the way you intended.

Where are you running said script? (Which operating system, terminal
emulator, etc.?)

Eek - thanks so much for your time, Matthew - appreciate it!

Hopefully someone else can chime in.

Matthew K. wrote in post #1075926:

Matthew K. wrote in post #1075924:

In short: it depends where you’re printing it.

Where are you running said script? (Which operating system, terminal
emulator, etc.?)

On 14 September 2012 09:46, Cookie R. [email protected] wrote:

Thanks for your reply!

I’m on a Mac, running Aptana Studio 3. Does that help?

I’m afraid it doesn’t help me, since I’m not a Mac user. From what I
can see (although it’s hard to find any real information) Aptana
Studio seems to use the system’s built-in terminal, and while I’ve
seen some comments on the OSX terminal not handling keyboard
backspace/delete propertly, all the proposed solutions imply that
actually printing a ^H / 0x08 / “\b” should work.

Hopefully someone else can help you.

By the way, your loop works fine in my Linux terminal. :wink:

On Thu, Sep 13, 2012 at 5:10 PM, Cookie R. [email protected]
wrote:

By the way, your loop works fine in my Linux terminal. :wink:

No idea what Aptana has to do with it but it works fine in a Mac
(10.7.4)
terminal as well.

Have you tried looking into these differences?

print “\b”

puts “\b”

p “\b”

Your code works in Windows 7 irb.

Matthew K. wrote in post #1075924:

In short: it depends where you’re printing it.

Where are you running said script? (Which operating system, terminal
emulator, etc.?)

On 14 September 2012 09:46, Cookie R. [email protected] wrote:

Thanks for your reply!

I’m on a Mac, running Aptana Studio 3. Does that help?

I’m afraid it doesn’t help me, since I’m not a Mac user. From what I
can see (although it’s hard to find any real information) Aptana
Studio seems to use the system’s built-in terminal, and while I’ve
seen some comments on the OSX terminal not handling keyboard
backspace/delete propertly, all the proposed solutions imply that
actually printing a ^H / 0x08 / “\b” should work.

Hopefully someone else can help you.

By the way, your loop works fine in my Linux terminal. :wink:

OSX Lion, standard system ruby, running in iTerm2:

$ ruby -e ‘puts “X\bY”’
Y
$

Any others that can help with this? I’m running RubyMine on Mac and
experiencing the same thing with the \b not properly backspacing.

Thanks!

Brian C. wrote in post #1076055:

OSX Lion, standard system ruby, running in iTerm2:

$ ruby -e ‘puts “X\bY”’
Y
$

On Sun, Sep 23, 2012 at 10:26 PM, Jeff L. [email protected] wrote:

Any others that can help with this? I’m running RubyMine on Mac and
experiencing the same thing with the \b not properly backspacing.

All I know is that the terminal emulators built into editors and IDEs
like RubyMine often don’t support the full range of interactions
possible in a proper terminal emulator, like Terminal or iTerm2. It’s
possible JetBrains just didn’t implement output of the backspace
character (ASCII 8); I believe it’s very seldom used in actually
programs.

Long story short: Use a real terminal, like Terminal or iTerm2.