How to draw frames on the console, along with accented words?

Asked

Viewed 651 times

1

I use the function BoxDraw below to draw frames, in a program with output in text mode (console).

I cannot use this function if I use accent words, because when I include the library <locale> (for menu words like "Report", for example) Leave my frame BoxDraw.

What can I do to use frames together and the accents correctly?

The code to draw the frames is this:

void BoxDraw(int posX, int posY, int width, int height){
    char TL = 201, TR = 187, BL = 200, BR = 188, LINE = 205, COLUMN = 186;
    gotoxy(posX, posY);
    cout << TL;
    for (int i = 0; i < width - 1; i++){
        cout << LINE;
    }
    cout << TR << endl;
    //columns
    for (int i = 0; i < height - 1; i++){
        gotoxy(posX, posY + i + 1);
        cout << COLUMN << endl;
    }
    for (int i = 0; i < height - 1; i++){
        gotoxy(posX + width, posY + i + 1);
        cout << COLUMN << endl;
    }
    //endcolumns
    gotoxy(posX, posY + height);
    cout << BL;
    for (int i = 0; i < width - 1; i++){
        cout << LINE;
    }
    cout << BR << endl;
}

void sideMenu(Product *p[], int n, int op) {
    static int indice; indice = Product::getNumProduct();
    switch (op) {
    case 1:
        system("cls");      
        insertProduct(p, n, indice);
        getEnterFromInput();
        mainMenu(p, n);
        break;
    case 2:
        system("cls");
        search(p, indice);
        getEnterFromInput();
        mainMenu(p, n);
        break;
    case 3:
        system("cls");
        deleteProduct(p);
        getEnterFromInput();
        mainMenu(p, n);
        break;
    case 4:
        system("cls");
        //debitarValor(c, n);
        getEnterFromInput();
        mainMenu(p, n);
        break;
    case 5:
        system("cls");
        sale(p);
        getEnterFromInput();
        mainMenu(p, n);
        break;
    case 6:
        system("cls");
        report(p);
        getEnterFromInput();
        mainMenu(p, n);
        break;
    case 0:
        system("cls");
        cout << "Saindo!" << endl;
        exit(1);
        break;
    default:
        system("cls");
        cout << "Opção inválida!" << endl;
        getEnterFromInput();
        mainMenu(p, n);
        break;
    }
}
  • This depends a lot on OS support. How your code is calling the cls, I imagine it’s Windows. Anyway, better [Edit] the post and add these details. The problem is that accents take the place of frame characters when you use Codepages, by limiting the amount of possible characters. To use simultaneously, you will need to force the console into Unicode mode: chcp 65001. In addition, you will have to use other codes instead of TL, TR etc, as in Unicode they are from U+2500 onwards. http://unicode-table.com/en/blocks/box-drawing/

  • Here’s an example of how to use Nicode, with this and the block character table above, I think you can: http://www.codeproject.com/Articles/34068/Unicode-Output-to-the-Windows-Console - If you can solve, can post as response in the field below to help other people. Either way, someone might have posted something before. Ah, don’t forget that the code editor also has to be configured to save to UTF-8 in this case, if using sharp literal strings.

  • I edited your question a little bit, I think now you just need to add the used OS, and if you can, a [mcve] with the problem happening.

  • Try using this here: https://github.com/nsf/termbox. I think using it you get a good result.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.