[Toybox] [New Toy] - reset

Isaac Dunham ibid.ag at gmail.com
Sat Apr 12 19:36:33 PDT 2014


On Mon, Apr 07, 2014 at 06:57:19PM +0530, Ashwini Sharma wrote:
> Hi List,
> 
> A tool to reset the terminal.
> This implementation depends on the _stty_ 'sane' settings.
> 
> Is this approach fine, or should the _stty_  __sane__ stuff be done in
> __reset__
> command itself.

<snip>
>   char *args[] = {"stty", "sane", NULL};
> 
>   /* \033c - reset the terminal with default setting
>    * \033(B - set the G0 character set (B=US)
>    * \033[2J - clear the whole screen
>    * \033[0m - Reset all attributes
>    */
>   if (isatty(1)) xprintf("\033c\033(B\033[0m\033[J\033[?25h");
>   fflush(stdout);
>   // set the terminal to sane settings
>   xexec(args);

Ick.
This is the sort of thing OLDTOY() is for; it belongs in an OLDTOY of
stty.
If you would like an example, see toys/posix/id.c; I'd expect the code to be
something like this:

USE_STTY(NEWTOY(stty, ...))
USE_STTY(OLDTOY(reset, stty, NULL, ...))
...
  if (toys.which->name[0] == 'r')
    xprintf("\033c\033(B\033[0m\033[J\033[?25h");
  if ((toys.which->name[0]=='r') || !strcmp(toys.optargs[0], "sane")) {
    //stty sane code goes here
  }

Thanks,
Isaac Dunham

 1397356593.0


More information about the Toybox mailing list