0

I have a ncurses-based text editor in c++ that uses tabs. Is there a way to make the tab columns shift by a certain amount to account for a side-ruler?

I can start my program with different sized tabs by setting TABSIZE, eg TABSIZE=4. This is nice, but on top of this I need to adjust where the first/all tab columns are calculated at.

This is a stripped down version to show the issue. The first and second columns of x's are smaller since the ruler takes away the available space at the start of the line, but the second and last columns are fine.

void write(std::string s) { //helper function
    printw(s.c_str());
}

int main() {
    initscr(); //start and clear
    TABSIZE=8; //default tabsize
    refresh();

    for (int i=1;i<10;i++) {
        write(std::to_string(i)+" | x\tx\tx\n");
    }

    getch();
    endwin();

    return 0;
}

//output from above

1 | x   x       x
2 | x   x       x
3 | x   x       x
4 | x   x       x
5 | x   x       x
6 | x   x       x
7 | x   x       x
8 | x   x       x
9 | x   x       x

The end result would be having the tab columns start at the ruler length (eg 3) instead of 0 (start of line)

Dosisod
  • 307
  • 2
  • 15
  • ncurses does not appear to support setting soft tabs at arbitrary positions. You may consider (1) displaying text in its own window that does not contain the ruler, and the ruler in its own window; or (2) interoret the tab character yourself. – n. m. could be an AI May 28 '19 at 03:33
  • My hopes is to not have to make tab renderer/parser, but if I cant find another way then I will have to do it like that – Dosisod May 28 '19 at 03:36
  • If you are making an editor you pretty much have to do tabs yourself anyway. What happens if you move your cursor to the middle of the tab character? – n. m. could be an AI May 28 '19 at 03:50
  • So yea I would still have to do it anyways, darn. Thanks anyways – Dosisod May 28 '19 at 04:03

0 Answers0