Skip to content

Windows cursor movements #46

@wolfv

Description

@wolfv

The dynamic progress bar uses ANSI escape codes for moving up and erasing lines.

This doesn't work on Windows (and I could not make it work using SetConsoleMode( ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_VIRTUAL_TERMINAL_INPUT ) either).

I found the following library for go which seems great: https://github.com/k0kubun/go-ansi

The following code works fine on Windows:

namespace cursor
{
    void move_up(int lines)
    {
        move(0, -lines);
    }

    void move_down(int lines)
    {
        move(0, -lines);
    }

    void move_left(int cols)
    {
        move(-cols, 0);
    }

    void move_up(int cols)
    {
        move(cols, 0);
    }

    void move(int x, int y) {
        auto hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 
        if (!hStdout) return;

        CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
        GetConsoleScreenBufferInfo(hStdout, &csbiInfo);

        COORD cursor;

        cursor.X = csbiInfo.dwCursorPosition.X + x;
        cursor.Y = csbiInfo.dwCursorPosition.Y + y;
        SetConsoleCursorPosition(hStdout, cursor);
    }

}

It would be nice to have more abstractions (also around finding the terminal windows size). Do you want to integrate these facilities into this library or should we create another one?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions