Search code examples
terminalcommand-line-interfaced

Remove n characters from console


I'm writing a program in D that doesn't need a GUI. I remember that in C++, there was a way to remove a number of characters from console/terminal, but I don't know how to do this in D. How do I remove a number of characters from the console/terminal?


Solution

  • (This didn't fit into a comment and I think it's what you are referring to)

    Do you mean getchar? You have direct access to the entire standard C library in D. For example have a look at this simple script:

    void main()
    {
        import core.stdc.stdio : getchar;
        foreach(i; 0..3)
            getchar();
    
        import std.stdio;
        writeln(readln());
    }
    

    When you compile & execute this script (e.g. here with rdmd)

    echo "Hello world" | rdmd main.d
    

    it would print:

    lo world
    

    But I have to agree with Adam that just slicing readln is easier and looks nicer ;-)