# Terminal escape sequences

**URL:** <https://www.ruby-forum.com/t/terminal-escape-sequences/173292>\
**Category:** Ruby\
**Created:** [August 6, 2009, 10:57am UTC](https://www.ruby-forum.com/t/terminal-escape-sequences/173292 "2009-08-06T10:57:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [August 6, 2009, 10:57am UTC](https://www.ruby-forum.com/t/terminal-escape-sequences/173292/1 "2009-08-06T10:57:40Z")

</div>

Hi all,

Looking through the PDoc source to see how it renders the build progress  
meter, I see:

log “\c[[F\c[[K Rendering: #{dest}”

Is there a good reference for these escape sequences anywhere? They’re  
not  
terribly Google-friendly.

---

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [August 6, 2009, 11:37am UTC](https://www.ruby-forum.com/t/terminal-escape-sequences/173292/2 "2009-08-06T11:37:29Z")

</div>

Hi,

2009/8/6 James C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi all,
> 
> Looking through the PDoc source to see how it renders the build progress  
> meter, I see:
> 
> Â log “\c[[F\c[[K Â Â Rendering: #{dest}”
> 
> Is there a good reference for these escape sequences anywhere? They’re not  
> terribly Google-friendly.

“\c[” is same to “\e”  
“\c[[F” is invalid sequence. cf: “\c[[f” means “Move cursor to upper  
left corner”  
“\c[[K” means “Clear line from cursor right”

Refer to [http://ascii-table.com/ansi-escape-sequences-vt-100.php](http://ascii-table.com/ansi-escape-sequences-vt-100.php)

Regards,

Park H.

---

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [August 6, 2009, 11:48am UTC](https://www.ruby-forum.com/t/terminal-escape-sequences/173292/3 "2009-08-06T11:48:01Z")

</div>

2009/8/6 Heesob P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > Is there a good reference for these escape sequences anywhere? They’re  
> > not  
> > terribly Google-friendly.
> 
> “\c[” is same to “\e”  
> “\c[[F” is invalid sequence. cf: “\c[[f” means “Move cursor to upper  
> left corner”  
> “\c[[K” means “Clear line from cursor right”
> 
> Refer to [http://ascii-table.com/ansi-escape-sequences-vt-100.php](http://ascii-table.com/ansi-escape-sequences-vt-100.php)

Thanks. \e[F is not listed though on my system it seems to have the  
effect  
of returning the cursor to the start of the line, so \e[F\e[K can be  
used to  
overwrite the whole of the current line. Anyone know if this is commonly  
implemented or is it Ubuntu-specific?

James

---

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [August 6, 2009, 12:06pm UTC](https://www.ruby-forum.com/t/terminal-escape-sequences/173292/4 "2009-08-06T12:06:11Z")

</div>

2009/8/6 Heesob P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > Is there a good reference for these escape sequences anywhere? They’re not  
> > terribly Google-friendly.
> 
> “\c[” is same to “\e”  
> “\c[[F” is invalid sequence. cf: “\c[[f” means “Move cursor to upper  
> left corner”  
> “\c[[K” means “Clear line from cursor right”
> 
> Refer to [http://ascii-table.com/ansi-escape-sequences-vt-100.php](http://ascii-table.com/ansi-escape-sequences-vt-100.php)

Correction:  
“\c[[F” means “Cursor Preceding Line”  
“\c[[K” means “Erase in Line”

Refer to [Miscellaneous Text Files: Ansi escape code sequences](http://www.atariarchives.org/cfn/12/02/0075.php)

Regards,

Park H.

---

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [August 6, 2009, 11:55am UTC](https://www.ruby-forum.com/t/terminal-escape-sequences/173292/5 "2009-08-06T11:55:38Z")

</div>

James C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> terribly Google-friendly.  
> Each terminal kind has its own escape sequences. There are thousands  
> of different kinds of terminals. A subset of their escape sequences  
> are referenced in the termcap or terminfo files, for use by libraries  
> such as curses, to provide a certain level of terminal independance on  
> the application side.

However, nowadays we don’t use many physical terminals anymore. We  
still use virtual terminals (xterm, Terminal.app, etc). So there is  
still diversity, but much less.

There are standardized escape sequences, and most kinds of terminal  
actually includes at least a basic subset of these standard escape  
sequences. There’s the ISO-6429 standard, but you will need money to  
get it. There is also the ECMA-048 standard which should be identical  
to ISO-6429 and can be downloaded from the web. There’s also an ANSI  
standard that should be identical or quite similar, but I don’t know  
the reference. However, these standard escape sequences are often  
known by the name ANSI escape sequences (probably because on Microsoft  
systems they’re implemented by a module stored in a file named  
ANSI.SYS).

So to have the highest possible level of terminal compatibility, you  
should rather use a curses library (which will select the escape  
sequence to send depending on the terminal of the user).

If you choose to use these standard escape sequences, you will  
restrict your program to terminals that implement these standard  
escape sequences (probably 95% of the (virtual) terminals in use  
today, so not a big loss).

But even in this later case, I would advise you to abstract them away.

Instead of writting:

```
log "\c[[F\c[[K Rendering: #{dest}"

```

write:

```
log "#{Ecma048.cpl}${Ecma048.el} Rendering: #{dest}"

```

(Notice that most of these escape sequences may take optional numeric  
arguments.  
CPL (Cursor Preceding Line) with an argument would could back several  
lines.)

---

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [August 6, 2009, 12:17pm UTC](https://www.ruby-forum.com/t/terminal-escape-sequences/173292/6 "2009-08-06T12:17:54Z")

</div>

Hi,

Am Donnerstag, 06. Aug 2009, 17:56:53 +0900 schrieb James C.:

> Looking through the PDoc source to see how it renders the build progress  
> meter, I see:
> 
> log “\c[[F\c[[K Rendering: #{dest}”
> 
> Is there a good reference for these escape sequences anywhere? They’re not  
> terribly Google-friendly.

This is the whole truth: [http://www.xfree86.org/current/ctlseqs.html](http://www.xfree86.org/current/ctlseqs.html).

Be aware that there are a lot of terminal programs (xterm, KDE,  
Gnome, Xfce4, aterm, wterm, …) and not everything is implemented  
everywhere.

If you like to track what escape sequences some programs write  
you can use the script command.

Bertram

---

<div class="post-metadata">

**Author:** ![james-calivar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@james-calivar](https://www.ruby-forum.com/u/james-calivar)\
**Post date:** [August 6, 2009, 1:25pm UTC](https://www.ruby-forum.com/t/terminal-escape-sequences/173292/7 "2009-08-06T13:25:50Z")

</div>

Heesob P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> > Is there a good reference for these escape sequences anywhere? They’re not  
> > terribly Google-friendly.
> 
> “\c[” is same to “\e”  
> “\c[[F” is invalid sequence. cf: “\c[[f” means “Move cursor to upper  
> left corner”

ESC [ F is CPL, Cursor Preceding Line, in ECMA-048.

> “\c[[K” means “Clear line from cursor right”
> 
> Refer to [http://ascii-table.com/ansi-escape-sequences-vt-100.php](http://ascii-table.com/ansi-escape-sequences-vt-100.php)

Which would only prove that the VT-100 terminals don’t implement  
ECMA-048.
