www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - OSX prompt limit

reply "Joel" <joelcnz gmail.com> writes:
In Mac OS, when typing with readln etc. I can't use the cursor 
keys. Works in Windows though.
Sep 03 2015
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Friday, 4 September 2015 at 02:17:57 UTC, Joel wrote:
 In Mac OS, when typing with readln etc. I can't use the cursor 
 keys. Works in Windows though.
That's normal, line editing on Unix terminals is a kinda advanced library feature. The most common lib to do it, GNU readline, is actually a big thing that pushed the GPL because of how useful it was and it happened to use that license. I wrote one too though it is a bit bulky. https://github.com/adamdruppe/arsd/blob/master/terminal.d import terminal; void main() { auto terminal = Terminal(ConsoleOutputMode.linear); auto line = terminal.getline("your prompt: "); terminal.writeln("You wrote: ", line); } compile: dmd yourapp.d terminal.d
Sep 03 2015
parent reply "Joel" <joelcnz gmail.com> writes:
On Friday, 4 September 2015 at 03:31:40 UTC, Adam D. Ruppe wrote:
 On Friday, 4 September 2015 at 02:17:57 UTC, Joel wrote:
 In Mac OS, when typing with readln etc. I can't use the cursor 
 keys. Works in Windows though.
That's normal, line editing on Unix terminals is a kinda advanced library feature. The most common lib to do it, GNU readline, is actually a big thing that pushed the GPL because of how useful it was and it happened to use that license. I wrote one too though it is a bit bulky. https://github.com/adamdruppe/arsd/blob/master/terminal.d import terminal; void main() { auto terminal = Terminal(ConsoleOutputMode.linear); auto line = terminal.getline("your prompt: "); terminal.writeln("You wrote: ", line); } compile: dmd yourapp.d terminal.d
I get these errors with terminal.d (on OSX): Joels-MacBook-Pro:small joelcnz$ rdmd term.d arsd/terminal.d(1268): Error: undefined identifier 'SIGWINCH' arsd/terminal.d(1381): Error: undefined identifier 'SIGWINCH' Joels-MacBook-Pro:small joelcnz$ Note: I've got term.d as the main file, I've got terminal.d in arsd folder I've put up an issue on your github site.
Sep 07 2015
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 8 September 2015 at 06:24:12 UTC, Joel wrote:
 arsd/terminal.d(1268): Error: undefined identifier 'SIGWINCH'
There's a missing value in the signal header for OSX ! Could you run this little C program for me on your Mac and let me know the output? --- #include<stdio.h> #include<signal.h> int main() { printf("%d\n", SIGWINCH); } --- I can't find the numeric value online either and I don't have a mac myself to check the headers :( ugh.
Sep 08 2015
parent reply "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= writes:
On Tuesday, 8 September 2015 at 13:02:35 UTC, Adam D. Ruppe wrote:
 On Tuesday, 8 September 2015 at 06:24:12 UTC, Joel wrote:
 arsd/terminal.d(1268): Error: undefined identifier 'SIGWINCH'
There's a missing value in the signal header for OSX ! Could you run this little C program for me on your Mac and let me know the output? --- #include<stdio.h> #include<signal.h> int main() { printf("%d\n", SIGWINCH); } --- I can't find the numeric value online either and I don't have a mac myself to check the headers :( ugh.
28 SIGWINCH discard signal Window size change
Sep 08 2015
parent reply "Ola Fosheim =?UTF-8?B?R3LDuHN0YWQi?= writes:
Or just take it from the man page:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/signal.3.html
Sep 08 2015
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 8 September 2015 at 13:17:31 UTC, Ola Fosheim Grøstad 
wrote:
 Or just take it from the man page:

 https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/signal.3.html
ah excellent. My web search came up with https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/m n2/sigaction.2.html which didn't give the value! anyway the git is updated now
Sep 08 2015
next sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 9/8/15 9:20 AM, Adam D. Ruppe wrote:
 On Tuesday, 8 September 2015 at 13:17:31 UTC, Ola Fosheim Grøstad wrote:
 Or just take it from the man page:

 https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/signal.3.html
ah excellent. My web search came up with https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man2/sigaction.2.html which didn't give the value!
That's because it's iOS. You have to be careful with apple documentation, they look the same for both MacOS and ios, but often they are slightly different. -Steve
Sep 08 2015
prev sibling parent reply "Joel" <joelcnz gmail.com> writes:
On Tuesday, 8 September 2015 at 13:20:20 UTC, Adam D. Ruppe wrote:
 On Tuesday, 8 September 2015 at 13:17:31 UTC, Ola Fosheim 
 Grøstad wrote:
 Or just take it from the man page:

 https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/signal.3.html
ah excellent. My web search came up with https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/m n2/sigaction.2.html which didn't give the value! anyway the git is updated now
Now I get the error: object.Exception terminal.d(2745): too narrow terminal to draw It has a negative number in it. Thanks for working on it.
Sep 08 2015
parent reply via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
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.
Sep 08 2015
parent reply "Joel" <joelcnz gmail.com> writes:
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); }
Sep 08 2015
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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 :(
Sep 09 2015
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
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));
}
Sep 09 2015
parent reply "Joel" <joelcnz gmail.com> writes:
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.
Sep 09 2015
parent "Adam D. Ruppe" <destructionator gmail.com> writes:
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.
Sep 09 2015