Solved

How to hide cursor in a Linux/Unix console?

Posted on 2004-09-01
7
5,571 Views
Last Modified: 2008-01-09
Hi,

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.
0
Comment
Question by:Aidman
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
It is not really easy, but can be done using 'ncurses'. Check out http://web.cs.mun.ca/~rod/ncurses/ncurses.html ("Writing Programs with NCURSES by Eric S. Raymond and Zeyd M. Ben-Halim") and http://en.tldp.org/HOWTO/NCURSES-Programming-HOWTO/ ("NCURSES Programming HOWTO")
0
 
LVL 23

Expert Comment

by:Mysidia
Comment Utility
The shell command would be
 setterm -cursor off

now on a linux terminal... In C  (brute force method)
  printf("\e[?25l");
  fflush(stdout);

  printf("\e[?25h");
  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.
0
 
LVL 23

Accepted Solution

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

        printf("\e[?25h");       is cursor on
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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.
0
 

Author Comment

by:Aidman
Comment Utility
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?
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 100 total points
Comment Utility
Instead of \e, try \033
0
 

Author Comment

by:Aidman
Comment Utility
Sorry for the delay, haven’t had good opportunities to test the solution, until now that is...
Anyways many thanks for the excellent solution!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now