0

Is there any way to move the cursor backwards while accounting for previous lines, i.e. when the cursor goes back from the beginning of the line it goes to the last non-empty character of the previous line?

Tornado547
  • 231
  • 2
  • 10
  • this action depends on the parameters in the `termcap` (in linux) contents. If your using windows then I suggest doing a bit of online research – user3629249 Mar 10 '19 at 22:13

2 Answers2

1

So there's no built in method for this, so I had to write my own

void backspace(){

  int x,y;
  getyx(stdscr,y,x);

  if(x == 0) {

    if( y == 0 ) {

      return;
    }

    x = getmaxx(stdscr) - 1;

    move(--y,x);

    char ch = ' ';

    while(ch == ' ' && x != 0){
      move(y,--x);
      ch=inch();
    }

  } else {
    move(y,x-1);

  } 


  delch();
}

Note that I have removed some irrelevant file I/O related code that was in this method.

Tornado547
  • 231
  • 2
  • 10
0

You can do that easily in a curses (full-screen) application (by reading the characters from the virtual screen using winch or win_wch), but would find it much harder in a termcap/terminfo low-level application because there is no portable method for reading directly from the terminal's screen.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105