September 09, 2015
On Wednesday, 9 September 2015 at 00:44:57 UTC, via Digitalmars-d-learn wrote:
> On Wed, Sep 09, 2015 at 12:05:52AM +0000, Joel via Digitalmars-d-learn wrote:
>> Now I get the error:
>
> What is your code calling the function? The prompt might just be too long.

import terminal;

void main() {
    auto terminal = Terminal(ConsoleOutputType.linear); // I think I changed ConsoleOutputType from some thing else that didn't work
    auto line = terminal.getline("your prompt: ");
    terminal.writeln("You wrote: ", line);
}

September 09, 2015
On Wednesday, 9 September 2015 at 01:35:26 UTC, Joel wrote:
>     auto line = terminal.getline("your prompt: ");


Huh, that should work unless your terminal is outrageously narrow or maybe output starting on the right side of the screen already.

But I can't look much further without having a mac myself, could be a few other causes :(

September 09, 2015
Maybe you can try gnu readline instead:


extern(C) char* readline(const(char)* prompt);
pragma(lib, "readline");
pragma(lib, "curses");
void main() {
        auto line = readline("your line: ");
        import std.stdio, std.conv;
        writeln(to!string(line));
}
September 09, 2015
On Wednesday, 9 September 2015 at 17:47:44 UTC, Adam D. Ruppe wrote:
> Maybe you can try gnu readline instead:
>
>
> extern(C) char* readline(const(char)* prompt);
> pragma(lib, "readline");
> pragma(lib, "curses");
> void main() {
>         auto line = readline("your line: ");
>         import std.stdio, std.conv;
>         writeln(to!string(line));
> }

Thanks Adam. That works better than normal. Up and down don't work though.
September 09, 2015
On Wednesday, 9 September 2015 at 21:27:05 UTC, Joel wrote:
> Thanks Adam. That works better than normal. Up and down don't work though.

There's another function called add_history for that. Readline is a pretty popular library (also GPL though, keep that in mind if you distribute your program, it must also be GPL if you use it) so you can find more info on the net:

http://web.mit.edu/gnu/doc/html/rlman_2.html


Basic thing is if you want to add it to history, call add_history(ptr_it_returned); and it will then be available for up/down access.

Also, readline is a C library, so it does expect you to free the memory it allocates too.... but you can probably just let that slide, it'll be fairly small leaks all things considered.


If I can ever actually get access to a Mac, I'll try to debug my other lib on one too.
1 2
Next ›   Last »