gap-packages/PackageManager

Interactive confirmation for RemovePackage

Closed this issue · 2 comments

Are you sure you want to recursively delete /? [y/N]

In PackageMaker, I am using this:

BindGlobal( "FlushOutput", function()
    Print("\c");
end );

BindGlobal( "Notice", function(arg)
    Print(TextAttr.bold, TextAttr.2);
    CallFuncList(Print, arg);
    Print(TextAttr.reset);
end );

BindGlobal( "Warning", function(arg)
    Print(TextAttr.bold, TextAttr.3);
    CallFuncList(Print, arg);
    Print(TextAttr.reset);
end );

BindGlobal( "AskYesNoQuestion", function( question )
    local stream, default, ans;

    stream := InputTextUser();

    Print(question);
    default := ValueOption( "default" );
    if default = true then
        Print(" [Y/n] "); FlushOutput();
    elif default = false then
        Print(" [y/N] "); FlushOutput();
    else
        default := fail;
        Print(" [y/n] "); FlushOutput();
    fi;

    while true do
        ans := CharInt(ReadByte(stream));
        if ans in "yYnN" then
            Print([ans,'\n']);
            ans := ans in "yY";
            break;
        elif ans in "\n\r" and default <> fail then
            Print("\n");
            ans := default;
            break;
        elif ans = '\c' then
            Print("\nUser aborted\n"); # HACK since Ctrl-C does not work
            JUMP_TO_CATCH("abort"); # HACK, undocumented command
        fi;
    od;

    CloseStream(stream);
    return ans;
end );

Done in 424e688.

Thanks again for all that helpful code.