Anatolij Gustschin | 4e92e60 | 2018-12-01 10:47:20 +0100 | [diff] [blame] | 1 | // 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 Glass | a76b60f | 2023-03-10 12:47:21 -0800 | [diff] [blame] | 11 | #include <video_console.h> |
Anatolij Gustschin | 4e92e60 | 2018-12-01 10:47:20 +0100 | [diff] [blame] | 12 | |
Heinrich Schuchardt | bfaa51d | 2022-02-11 18:11:05 +0100 | [diff] [blame] | 13 | #define CSI "\x1b[" |
| 14 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 15 | static int do_video_clear(struct cmd_tbl *cmdtp, int flag, int argc, |
Anatolij Gustschin | 4e92e60 | 2018-12-01 10:47:20 +0100 | [diff] [blame] | 16 | char *const argv[]) |
| 17 | { |
Heinrich Schuchardt | bfaa51d | 2022-02-11 18:11:05 +0100 | [diff] [blame] | 18 | __maybe_unused struct udevice *dev; |
Anatolij Gustschin | 4e92e60 | 2018-12-01 10:47:20 +0100 | [diff] [blame] | 19 | |
Simon Glass | 61a6210 | 2023-03-10 12:47:23 -0800 | [diff] [blame] | 20 | /* |
| 21 | * Send clear screen and home |
| 22 | * |
| 23 | * FIXME(Heinrich Schuchardt <xypron.glpk@gmx.de>): This should go |
| 24 | * through an API and only be written to serial terminals, not video |
| 25 | * displays |
| 26 | */ |
Heinrich Schuchardt | bfaa51d | 2022-02-11 18:11:05 +0100 | [diff] [blame] | 27 | printf(CSI "2J" CSI "1;1H"); |
Simon Glass | a76b60f | 2023-03-10 12:47:21 -0800 | [diff] [blame] | 28 | if (IS_ENABLED(CONFIG_VIDEO_ANSI)) |
| 29 | return 0; |
| 30 | |
| 31 | if (IS_ENABLED(CONFIG_VIDEO)) { |
| 32 | if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) |
Heinrich Schuchardt | 63de216 | 2022-07-14 08:53:46 +0200 | [diff] [blame] | 33 | return CMD_RET_FAILURE; |
Simon Glass | a76b60f | 2023-03-10 12:47:21 -0800 | [diff] [blame] | 34 | if (vidconsole_clear_and_reset(dev)) |
Heinrich Schuchardt | 63de216 | 2022-07-14 08:53:46 +0200 | [diff] [blame] | 35 | return CMD_RET_FAILURE; |
| 36 | } |
Simon Glass | a76b60f | 2023-03-10 12:47:21 -0800 | [diff] [blame] | 37 | |
Anatolij Gustschin | 4e92e60 | 2018-12-01 10:47:20 +0100 | [diff] [blame] | 38 | return CMD_RET_SUCCESS; |
| 39 | } |
| 40 | |
| 41 | U_BOOT_CMD(cls, 1, 1, do_video_clear, "clear screen", ""); |