Results 1 to 2 of 2

Thread: clearing a single line or block of lines

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Burlington, ON, Canada
    Posts
    99

    clearing a single line or block of lines

    In C is there a way to clear a single line or a block of lines without affecting the text on the rest of the screen? Also, I assume that if I can clear a single line, I can also clear it after a certain point on the line.

    Thx,
    Steve

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    In standard console mode on ANSI-compliant terminals you can use ANSI escape sequences to do what you want.

    This is from memory so you need to check it out, including typos.
    For futher ref - check out ANSI escape sequences or ANSI.SYS on the net - google is best.


    Code:
    #define zout(c) memset(&c,0x00,sizeof(c))
    #include <strings.h>
    
    void setup(char*);
    void linedel(int col,int row){ /*delete from col -> EOL on row */
          const char esc =27;
          char tmp[20];
          zout(tmp);
          setup(tmp);
          /* send esc[s esc[row;colH esc[K esc[u */
          printf("%s%s%s%d;%dH%s%s%s%s",
                   tmp,"s",            
                   tmp,row,col,        
                   tmp,"K",            
                   tmp,"u");           
          return;   
    }
    
    void setup(char * src){
          char *buf;
          buf=src;
          *buf++=27; /* escape */
          *buf++='[';  /* open sq bracket */
          *buf=0x00;
          return;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width