LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 04-02-2007, 04:27 PM   #1
bandwidthjunkie
LQ Newbie
 
Registered: Jan 2007
Location: london
Distribution: Gentoo(amd64) - 2.16.20
Posts: 26

Rep: Reputation: 15
Rewriting multiple lines in C++ terminal application


I have a fairly lengthy C++ terminal application that is doing some heavy maths. Ideally I would like to be able to get a short summary on the screen of what it is currently doing, without it scrolling down a million lines when I run it.

I know how to rewrite one line:
Code:
cout << "\r";
But, is there an "easy" way to clear the last few lines and then rewrite them? Or is this just devil talk?

This only has to run on Linux, would be nice if it could work off the command line (ie not only a terminal window / don't know if there is a difference).
 
Old 04-02-2007, 05:00 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,011

Rep: Reputation: 110Reputation: 110
Try ncurses. Although this feels like normal log-like behaviour seems like it would work if you were smarter about what and when you logged.
 
Old 04-02-2007, 05:01 PM   #3
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
There is no portable way to do this using only standard terminal i/o functions. If you really need it, I suggest you try using (n)curses.
 
Old 04-03-2007, 04:27 AM   #4
bandwidthjunkie
LQ Newbie
 
Registered: Jan 2007
Location: london
Distribution: Gentoo(amd64) - 2.16.20
Posts: 26

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by tuxdev
Try ncurses. Although this feels like normal log-like behaviour seems like it would work if you were smarter about what and when you logged.
Possibly, but it would take a lot more time to be clever about it and I have spent long enough on the code already.

osor << portability is not really too much of an issue, at the moment there are only about 10 machines in the world that I will run this code on. That is fairly unlikely to change. Will give ncurses a look.

[*UPDATE*] Read the ncurses howto and it looks like just what I need. Thanks for the advice.

Last edited by bandwidthjunkie; 04-03-2007 at 06:56 AM.
 
Old 04-06-2007, 09:34 PM   #5
Siiiiiii
LQ Newbie
 
Registered: May 2006
Location: Sweden
Distribution: Vector Linux
Posts: 28

Rep: Reputation: 15
Alternatively, I found this:
http://66.102.9.104/search?q=cache:D...ient=firefox-a
which is a list of all escape sequences for the Linux terminal (or specifically all VT100 terminals). Unfortunately, the original link seems to be broken; I hope you are fine with Google's cache.

So basically, to clear the previous two lines, you would do something like this(in C):

Code:
#include <stdio.h>
#define NUM_LINES 2

int main(){
  char terminal_clearline [4];
  char terminal_moveup [4];

  sprintf(terminal_clearline, "%c[2K", 0x1B);
  sprintf(terminal_moveup, "%c[1A", 0x1B);

  for (int i = 0; i < NUM_LINES; i++){
     printf("%s", terminal_moveup);
     printf("%s", terminal_clearline);
  }
}
I tried to do this in C++, using iostream, but it doesn't seem to work. Perhaps I concatenated the terminal* strings incorrectly. I hope this helps you anyway!

This method is more easy on your computer than using curses (which I assume you'll prefer, calculating millions of lines of math).

/Siiiiiii

Last edited by Siiiiiii; 04-06-2007 at 09:36 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM
gnome-terminal how-to set lines/rows? longtex Linux - Software 3 10-21-2005 03:06 PM
weird lines on X window terminal - I'm worried... towsonu2003 Linux - Hardware 8 09-22-2005 03:34 PM
ISDN multiple lines schimmelpilz Linux - Newbie 1 02-24-2004 05:39 PM
lines remaining when I launch an app or terminal spiteres Linux - General 0 05-27-2003 06:24 AM


All times are GMT -5. The time now is 08:38 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration