TS-32: control-d to exit

- Thanks to Eric Hymowitz.
This commit is contained in:
Paul Beckingham 2016-11-11 17:48:26 -05:00
parent 346e8881e4
commit ccd21f4060
4 changed files with 12 additions and 5 deletions

View file

@ -21,3 +21,4 @@ suggestions:
hosaka
Lars Kumbier
Iain R. Learmonth
Eric Hymowitz

View file

@ -2,6 +2,8 @@
- TS-29 tasksh hangs trying to read task from stdin
(thanks to ilove zfs).
- TS-32 control-d to exit
(thanks to Eric Hymowitz).
------ current release ---------------------------

2
NEWS
View file

@ -1,7 +1,7 @@
New Features in tasksh 1.2.0
-
- Responds to Ctrl-D by exiting.
New commands in tasksh 1.2.0

View file

@ -69,6 +69,7 @@ const std::string getResponse (const std::string& prompt)
if (! line_read)
{
std::cout << "\n";
response = "<EOF>";
}
else
{
@ -105,12 +106,17 @@ static int commandLoop (bool autoClear)
std::cout << "\033[2J\033[0;0H";
int status = 0;
if (command != "")
if (! isatty (fileno (stdin)) && command == "")
{
status = -1;
}
else if (command != "")
{
std::vector <std::string> args = split (command, ' ');
// Dispatch command.
if (closeEnough ("exit", args[0], 3)) status = -1;
if (args[0] == "<EOF>") status = -1;
else if (closeEnough ("exit", args[0], 3)) status = -1;
else if (closeEnough ("quit", args[0], 3)) status = -1;
else if (closeEnough ("help", args[0], 3)) status = cmdHelp ();
else if (closeEnough ("diagnostics", args[0], 3)) status = cmdDiagnostics ();
@ -127,8 +133,6 @@ static int commandLoop (bool autoClear)
// cause the shell to terminate.
}
}
else
status = 1;
return status;
}