[U-Boot] [PATCH 09/14] New command clear: Clear the ANSI terminal

Marek Vasut
2012-01-25T18:10:03Z

> * Command can be enabled by CONFIG_CMD_CLEAR
> * Added some ANSI escape codes definitions in common.h
>
> Signed-off-by: Pali Roh?r <pali.rohar@gmail.com>
> Cc: Marcel Mol <marcel@mesa.nl>

Do you seriously need a new command for such a simple operation?

M
> ---
> Changes since original version:
> - Renamed command clr to clear
> - Use puts instead printf
> - Move cursor to pos1,1
> - Merged parts of patch "Add some ANSI escape codes definitions in
> common.h"
>
> common/Makefile | 1 +
> common/cmd_clear.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> include/common.h | 7 +++++++
> include/config_cmd_all.h | 1 +
> 4 files changed, 51 insertions(+), 0 deletions(-)
> create mode 100644 common/cmd_clear.c
>
> diff --git a/common/Makefile b/common/Makefile
> index 2d9ae8c..e1efd45 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -69,6 +69,7 @@ COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o
> COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o
> COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o
> COBJS-$(CONFIG_CMD_CACHE) += cmd_cache.o
> +COBJS-$(CONFIG_CMD_CLEAR) += cmd_clear.o
> COBJS-$(CONFIG_CMD_CONSOLE) += cmd_console.o
> COBJS-$(CONFIG_CMD_CPLBINFO) += cmd_cplbinfo.o
> COBJS-$(CONFIG_DATAFLASH_MMC_SELECT) += cmd_dataflash_mmc_mux.o
> diff --git a/common/cmd_clear.c b/common/cmd_clear.c
> new file mode 100644
> index 0000000..597611e
> --- /dev/null
> +++ b/common/cmd_clear.c
> @@ -0,0 +1,42 @@
> +/*
> + * Copyright 2011
> + * Marcel Mol, MESA Consulting, marcel at mesa.nl
> + *
> + * Copyright 2011
> + * Pali Roh?r, pali.rohar at gmail.com
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include <common.h>
> +#include <command.h>
> +
> +static int do_clear(cmd_tbl_t *cmdtp, int flag, int argc, char * const
> argv[]) +{
> + puts(ANSI_CLEAR_CONSOLE);
> + printf(ANSI_CURSOR_POSITION, 1, 1);
> + return 0;
> +}
> +
> +U_BOOT_CMD(
> + clear, CONFIG_SYS_MAXARGS, 1, do_clear,
> + "clear",
> + "\n"
> + " - clear screen and move cursor to top of screen"
> +);
> diff --git a/include/common.h b/include/common.h
> index 3df1def..9c0449e 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -751,6 +751,13 @@ void clear_ctrlc (void); /* clear the Control-C
> condition */ int disable_ctrlc (int); /* 1 to disable, 0 to enable
> Control-C detect */
>
> /*
> + * ANSI terminal
> + */
> +
> +#define ANSI_CURSOR_POSITION "\e[%d;%dH"
> +#define ANSI_CLEAR_CONSOLE "\e[2J"
> +
> +/*
> * STDIO based functions (can always be used)
> */
> /* serial stuff */
> diff --git a/include/config_cmd_all.h b/include/config_cmd_all.h
> index 9716f9c..3f25eba 100644
> --- a/include/config_cmd_all.h
> +++ b/include/config_cmd_all.h
> @@ -23,6 +23,7 @@
> #define CONFIG_CMD_BSP /* Board Specific functions */
> #define CONFIG_CMD_CACHE /* icache, dcache */
> #define CONFIG_CMD_CDP /* Cisco Discovery Protocol */
> +#define CONFIG_CMD_CLEAR /* ANSI clear screen command */
> #define CONFIG_CMD_CONSOLE /* coninfo */
> #define CONFIG_CMD_DATE /* support for RTC, date/time...*/
> #define CONFIG_CMD_DHCP /* DHCP Support */