blob: 073ba5a6c8670b6906d7bb0331ab48f7f3d8a735 [file] [log] [blame]
Anatolij Gustschin4e92e602018-12-01 10:47:20 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2018
4 * DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
5 *
6 * cls - clear screen command
7 */
8#include <common.h>
9#include <command.h>
10#include <dm.h>
Simon Glassa76b60f2023-03-10 12:47:21 -080011#include <video_console.h>
Anatolij Gustschin4e92e602018-12-01 10:47:20 +010012
Heinrich Schuchardtbfaa51d2022-02-11 18:11:05 +010013#define CSI "\x1b["
14
Simon Glass09140112020-05-10 11:40:03 -060015static int do_video_clear(struct cmd_tbl *cmdtp, int flag, int argc,
Anatolij Gustschin4e92e602018-12-01 10:47:20 +010016 char *const argv[])
17{
Heinrich Schuchardtbfaa51d2022-02-11 18:11:05 +010018 __maybe_unused struct udevice *dev;
Anatolij Gustschin4e92e602018-12-01 10:47:20 +010019
Heinrich Schuchardtbfaa51d2022-02-11 18:11:05 +010020 /* Send clear screen and home */
21 printf(CSI "2J" CSI "1;1H");
Simon Glassa76b60f2023-03-10 12:47:21 -080022 if (IS_ENABLED(CONFIG_VIDEO_ANSI))
23 return 0;
24
25 if (IS_ENABLED(CONFIG_VIDEO)) {
26 if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
Heinrich Schuchardt63de2162022-07-14 08:53:46 +020027 return CMD_RET_FAILURE;
Simon Glassa76b60f2023-03-10 12:47:21 -080028 if (vidconsole_clear_and_reset(dev))
Heinrich Schuchardt63de2162022-07-14 08:53:46 +020029 return CMD_RET_FAILURE;
30 }
Simon Glassa76b60f2023-03-10 12:47:21 -080031
Anatolij Gustschin4e92e602018-12-01 10:47:20 +010032 return CMD_RET_SUCCESS;
33}
34
35U_BOOT_CMD(cls, 1, 1, do_video_clear, "clear screen", "");