LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-22-2005, 07:06 AM   #1
rajsun
Member
 
Registered: Mar 2005
Posts: 61

Rep: Reputation: 15
Help me out.....


hi all,
i'm rajesh new to Linux programming. i want move my consol based curssor to desired position. i used the

system("tput cup x y");

but fail to place the curssor at (x,y) coordinate. is there any escape sequences which can place the curssor to desired location in screen(console) without using ncurses.

if any then please help me out .
waiting for ur responses.....
rajesh.
 
Old 03-22-2005, 08:31 AM   #2
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
I assume that you're using C.

No offense meant, but systeming out to do this is not good.
In the first place, system is creating it's own instance of the
shell. Even though the cursor is being moved in that shell, once
the command finishes, the shell is closed, and now the program
is back to it's own shell.

Secondly, you can read why using system is bad on the
system man page.

However, as long as the terminal in which you are working supports
ANSI escape codes (which it should), then you can easily printf
ansi escape codes to accomplish the cursor placement.
Code:
#include <stdio.h>

int main(void)
{
  printf(
      "\e[s"               // save cursor position
      "\e[5;10f"           // go to line 5, column 10
      "Located at 5,10"    // print something at location
      "\e[u"               // return to stored cuirsor position
      "Done!\n"
  );

  return 0;
}
Just google search for ansi escape codes for all sorts of other interesting
things you can do with them.

Last edited by TheLinuxDuck; 03-22-2005 at 08:32 AM.
 
Old 03-24-2005, 07:10 AM   #3
sandipan
Newbie
 
Registered: Mar 2005
Location: India
Distribution: Red Hat Linux 8.0
Posts: 5

Rep: Reputation: 0
using curses should make it a lot more easier, u got function like "mvprintw" to print ur output to a particular position on screen.
 
Old 03-24-2005, 08:04 AM   #4
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
Quote:
Originally posted by sandipan
using curses should make it a lot more easier, u got function like "mvprintw" to print ur output to a particular position on screen.
Easier? I completely disagree. Ncurses is bloated when you don't need all it's power. If you only need some selective color settings and positional movement: A simple function, like:
Code:
void gotoxy(const int x, const int y) {
  printf("\e[%d;%d%c", y, x, 'H');
}
and now your cursor movement code is finished and easy to use... and doesn't add the overhead that ncurses adds to the binary. As for colors, set an enum equal to the color numbers, and write a simple function to handle colors.. seems alot easier to me.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration