video: Add a way to write a partial string to the console
When writing multiple lines of text we need to be able to control which text goes on each line. Add a new vidconsole_put_stringn() function to help with this. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -508,12 +508,14 @@ int vidconsole_put_char(struct udevice *dev, char ch)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vidconsole_put_string(struct udevice *dev, const char *str)
|
int vidconsole_put_stringn(struct udevice *dev, const char *str, int maxlen)
|
||||||
{
|
{
|
||||||
const char *s;
|
const char *s, *end = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
for (s = str; *s; s++) {
|
if (maxlen != -1)
|
||||||
|
end = str + maxlen;
|
||||||
|
for (s = str; *s && (maxlen == -1 || s < end); s++) {
|
||||||
ret = vidconsole_put_char(dev, *s);
|
ret = vidconsole_put_char(dev, *s);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
@@ -522,6 +524,11 @@ int vidconsole_put_string(struct udevice *dev, const char *str)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vidconsole_put_string(struct udevice *dev, const char *str)
|
||||||
|
{
|
||||||
|
return vidconsole_put_stringn(dev, str, -1);
|
||||||
|
}
|
||||||
|
|
||||||
static void vidconsole_putc(struct stdio_dev *sdev, const char ch)
|
static void vidconsole_putc(struct stdio_dev *sdev, const char ch)
|
||||||
{
|
{
|
||||||
struct udevice *dev = sdev->priv;
|
struct udevice *dev = sdev->priv;
|
||||||
|
@@ -499,6 +499,23 @@ int vidconsole_entry_start(struct udevice *dev);
|
|||||||
*/
|
*/
|
||||||
int vidconsole_put_char(struct udevice *dev, char ch);
|
int vidconsole_put_char(struct udevice *dev, char ch);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vidconsole_put_stringn() - Output part of a string to the current console pos
|
||||||
|
*
|
||||||
|
* Outputs part of a string to the console and advances the cursor. This
|
||||||
|
* function handles wrapping to new lines and scrolling the console. Special
|
||||||
|
* characters are handled also: \n, \r, \b and \t.
|
||||||
|
*
|
||||||
|
* The device always starts with the cursor at position 0,0 (top left). It
|
||||||
|
* can be adjusted manually using vidconsole_position_cursor().
|
||||||
|
*
|
||||||
|
* @dev: Device to adjust
|
||||||
|
* @str: String to write
|
||||||
|
* @maxlen: Maximum chars to output, or -1 for all
|
||||||
|
* Return: 0 if OK, -ve on error
|
||||||
|
*/
|
||||||
|
int vidconsole_put_stringn(struct udevice *dev, const char *str, int maxlen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* vidconsole_put_string() - Output a string to the current console position
|
* vidconsole_put_string() - Output a string to the current console position
|
||||||
*
|
*
|
||||||
|
@@ -607,7 +607,8 @@ static int dm_test_video_truetype(struct unit_test_state *uts)
|
|||||||
ut_assertok(video_get_nologo(uts, &dev));
|
ut_assertok(video_get_nologo(uts, &dev));
|
||||||
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
|
ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
|
||||||
vidconsole_put_string(con, test_string);
|
vidconsole_put_string(con, test_string);
|
||||||
ut_asserteq(12174, compress_frame_buffer(uts, dev, false));
|
vidconsole_put_stringn(con, test_string, 30);
|
||||||
|
ut_asserteq(13184, compress_frame_buffer(uts, dev, false));
|
||||||
ut_assertok(check_copy_frame_buffer(uts, dev));
|
ut_assertok(check_copy_frame_buffer(uts, dev));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user