Commit 257f838f authored by Kevin Wolf's avatar Kevin Wolf

vterm: Escapesequenz um neue Zeile einzufügen

+ vterm: \033[#L implementiert, um eine neue leere Zeile in den Puffer
  einzufügen. Diese Funktion hätte less gern für das Hochscrollen, bevor
  es das Terminal ohne Warnung akzeptiert.
Signed-off-by: Kevin Wolf's avatarKevin Wolf <kevin@tyndur.org>
parent b854d122
......@@ -37,6 +37,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <rpc.h>
#include <lostio.h>
......@@ -544,3 +545,46 @@ static void output_newline(vterm_output_t* out)
buffer_line_clear(out, out->buffer, out->buffer_pos.line);
}
/**
* An der aktuellen Cursorposition neue Zeilen einfügen
*/
void output_insert_lines(vterm_output_t* out, int num)
{
int first_scrolled, last_scrolled, i;
if (num <= 0) {
return;
}
// FIXME Das ist ziemlich blöd so, aber wir haben weder Anfang noch Ende
// des Ringpuffers, deswegen approximieren wir die Grenze mal mit einem
// Bildschirm über der aktuellen Cursorposition.
first_scrolled = out->buffer_pos.line;
last_scrolled = (first_scrolled - out->screen_height + out->buffer_lines) %
out->buffer_lines;
// Zeilen nach unten verschieben
i = last_scrolled;
while (true) {
int j = (i + out->buffer_lines - num) % out->buffer_lines;
memcpy(&out->buffer[i * out->screen_width],
&out->buffer[j * out->screen_width],
sizeof(*out->buffer) * out->screen_width);
if (j == first_scrolled) {
break;
}
i = (i + out->buffer_lines - 1) % out->buffer_lines;
}
// Zeilen löschen
i = first_scrolled;
while (num--) {
buffer_line_clear(out, out->buffer, i);
i = (i + 1) % out->buffer_lines;
}
out->screen_redraw = true;
}
......@@ -76,6 +76,8 @@ static void vt100_clear_screen(vterminal_t* vterm, bool have_n1, bool have_n2,
int n1, int n2);
static void vt100_clear_line(vterminal_t* vterm, bool have_n1, bool have_n2,
int n1, int n2);
static void vt100_insert_line(vterminal_t* vterm, bool have_n1, bool have_n2,
int n1, int n2);
static void vt100_text_attr(vterminal_t* vterm, bool have_n1, bool have_n2,
int n1, int n2);
......@@ -98,6 +100,8 @@ static struct vt100_sequence_handler handler_list[] = {
{"\033[\1J", vt100_clear_screen},
{"\033[K", vt100_clear_line},
{"\033[\1K", vt100_clear_line},
{"\033[L", vt100_insert_line},
{"\033[\1L", vt100_insert_line},
{"\033[m", vt100_text_attr},
{"\033[\1m", vt100_text_attr},
{"\033[\1;\1m", vt100_text_attr}
......@@ -667,6 +671,16 @@ static void vt100_clear_line(vterminal_t* vterm, bool have_n1, bool have_n2,
out->buffer_pos.column = column;
}
/**
* ESC[#L
* Zeile einfügen.
*/
static void vt100_insert_line(vterminal_t* vterm, bool have_n1, bool have_n2,
int n1, int n2)
{
output_insert_lines(&vterm->output, have_n1 ? n1 : 1);
}
/**
* Farben invertieren
*/
......
......@@ -235,6 +235,9 @@ void output_set_position(vterm_output_t* out, size_t row,
/// entfernt sind.
void output_clear(vterm_output_t* out, size_t count);
/// An der aktuellen Cursorposition neue Zeilen einfügen
void output_insert_lines(vterm_output_t* out, int num);
/// Bildschirmfenster verschieben
void screen_scroll(vterm_output_t* out, int lines);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment