How to hide cursor in a Linux/Unix console?

Posted on 2004-09-01
Last Modified: 2008-01-09

I am looking for a way to hide the cursor in a Linux/Unix console, or at least move the cursor to a desirable position. I don’t wish to permanently alter the cursor, just while my program runs in the terminal. I assume it’s not as easy as in the windows dos prompt but hopefully it won’t include package instalment. Thanks in advance.
Question by:Aidman
  • 2
  • 2
  • 2
  • +1
LVL 86

Expert Comment

ID: 11957487
It is not really easy, but can be done using 'ncurses'. Check out ("Writing Programs with NCURSES by Eric S. Raymond and Zeyd M. Ben-Halim") and ("NCURSES Programming HOWTO")
LVL 23

Expert Comment

ID: 11959062
The shell command would be
 setterm -cursor off

now on a linux terminal... In C  (brute force method)

  fflush(stdout) ;

Those are terminal codes.
To move the cursor around, you can try other codes, i.e.
   printf("\e[5H");  change position row 5
   printf("\e[5;3H");  change position to row 5 column 3

To do this in a clean manner that will work with terminals other than the local Linux console,
using curses/ncurses is the best choice I think; however.
LVL 23

Accepted Solution

Mysidia earned 150 total points
ID: 11959068
Err, oops
        printf("\e[?25l");        is cursor off

        printf("\e[?25h");       is cursor on
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

LVL 46

Expert Comment

by:Sjef Bosman
ID: 11961367
Curses is meant for all types of old-fashioned terminals (VT100 etc., BeeHive, VT36). Not all of them used to implement a cursor-off/on. The escape sequences above assume a VT100 or comparable terminal. It is therefore important that you have set your Linux console to simulate a VT100.

Author Comment

ID: 11973445
Mysidia, I tested your solution in the terminal by writing: echo "\e[?25l"
and it worked perfectly, however strangly it didn't work when writting it in code.

The gcc compiler returned "warning: dubious escape: \e" when I used printf("\e[?25l")
and when executed it just printed "e[?25l". Then I wrote printf("\\e[?25l")
and it compiled fine but still didn't affect the cursor just printed "\e[?25l".
I even tested calling system("echo \"\\e[?25l\"") and system("echo \"\e[?25l\"")
but that also only printed string.

Any ideas?
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 100 total points
ID: 11974132
Instead of \e, try \033

Author Comment

ID: 11991086
Sorry for the delay, haven’t had good opportunities to test the solution, until now that is...
Anyways many thanks for the excellent solution!

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question