From: Simon Glass <sjg@chromium.org>
Keep track of the current character index in the current CLI entry. This
corresponds to the cursor position and is numbered from zero.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
drivers/video/vidconsole-uclass.c | 4 ++++
include/video_console.h | 8 ++++++++
2 files changed, 12 insertions(+)
@@ -79,6 +79,9 @@ static int vidconsole_back(struct udevice *dev)
if (priv->ycur < 0)
priv->ycur = 0;
}
+ assert(priv->cli_index);
+ cli_index_adjust(priv, -1);
+
return video_sync(dev->parent, false);
}
@@ -455,6 +458,7 @@ static int vidconsole_output_glyph(struct udevice *dev, int ch)
priv->last_ch = ch;
if (priv->xcur_frac >= priv->xsize_frac)
vidconsole_newline(dev);
+ cli_index_adjust(priv, 1);
return 0;
}
@@ -70,6 +70,7 @@ struct vidconsole_cursor {
* @xsize_frac: Width of the display in fractional units
* @xstart_frac: Left margin for the text console in fractional units
* @last_ch: Last character written to the text console on this line
+ * @cli_index: Character index into the CLI text (0=start)
* @escape: TRUE if currently accumulating an ANSI escape sequence
* @escape_len: Length of accumulated escape sequence so far
* @col_saved: Saved X position, in fractional units (VID_TO_POS(x))
@@ -91,6 +92,7 @@ struct vidconsole_priv {
int xsize_frac;
int xstart_frac;
int last_ch;
+ int cli_index;
/*
* ANSI escape sequences are accumulated character by character,
* starting after the ESC char (0x1b) until the entire sequence
@@ -474,6 +476,12 @@ static inline int vidconsole_set_cursor_visible(struct udevice *dev,
}
#endif /* CONFIG_CURSOR */
+static inline void cli_index_adjust(struct vidconsole_priv *priv, int by)
+{
+ if (CONFIG_IS_ENABLED(CURSOR))
+ priv->cli_index += by;
+}
+
/**
* vidconsole_push_colour() - Temporarily change the font colour
*