|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From a30f1425133d2b64a1c3f0113a710528872a3cbb Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
From: David Herrmann <dh.herrmann@gmail.com>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Date: Wed, 1 Oct 2014 11:27:46 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Subject: [PATCH] terminal: add term.h header for library users
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Like all the other parts of libsystemd-terminal, split API of
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
term-internal.h into term.h so we can use it from systemd-consoled.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
Makefile.am | 1 +
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/libsystemd-terminal/term-internal.h | 132 +----------------------------
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/libsystemd-terminal/term.h | 146 ++++++++++++++++++++++++++++++++
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
3 files changed, 148 insertions(+), 131 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
create mode 100644 src/libsystemd-terminal/term.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/Makefile.am b/Makefile.am
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 5fa4e4a5e8..503302851b 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/Makefile.am
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/Makefile.am
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -3051,6 +3051,7 @@ libsystemd_terminal_la_SOURCES = \
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/libsystemd-terminal/sysview.h \
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/libsystemd-terminal/sysview-internal.h \
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/libsystemd-terminal/sysview.c \
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ src/libsystemd-terminal/term.h \
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/libsystemd-terminal/term-internal.h \
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/libsystemd-terminal/term-charset.c \
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
src/libsystemd-terminal/term-page.c \
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/libsystemd-terminal/term-internal.h b/src/libsystemd-terminal/term-internal.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 345996b943..f0f4432c80 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- a/src/libsystemd-terminal/term-internal.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/libsystemd-terminal/term-internal.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -24,26 +24,20 @@
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
#include <stdbool.h>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
#include <stdint.h>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
#include <stdlib.h>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+#include "term.h"
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
#include "util.h"
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
typedef struct term_char term_char_t;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
typedef struct term_charbuf term_charbuf_t;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-typedef struct term_color term_color;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-typedef struct term_attr term_attr;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
typedef struct term_cell term_cell;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
typedef struct term_line term_line;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
typedef struct term_page term_page;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
typedef struct term_history term_history;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-typedef struct term_utf8 term_utf8;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-typedef struct term_seq term_seq;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-typedef struct term_parser term_parser;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
typedef uint32_t term_charset[96];
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-typedef struct term_screen term_screen;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* Miscellaneous
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* Sundry things and external helpers.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -55,24 +49,6 @@ int mk_wcswidth(const wchar_t *str, size_t len);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
int mk_wcswidth_cjk(const wchar_t *str, size_t len);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * Ageing
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * Redrawing terminals is quite expensive. Therefore, we avoid redrawing on
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * each single modification and mark modified cells instead. This way, we know
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * which cells to redraw on the next frame. However, a single DIRTY flag is not
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * enough for double/triple buffered screens, hence, we use an AGE field for
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * each cell. If the cell is modified, we simply increase the age by one. Each
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * framebuffer can then remember its last rendered age and request an update of
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * all newer cells.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * TERM_AGE_NULL is special. If used as cell age, the cell must always be
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * redrawn (forced update). If used as framebuffer age, all cells are drawn.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * This way, we can allow integer wrap-arounds.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-typedef uint64_t term_age_t;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-#define TERM_AGE_NULL 0
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* Characters
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* Each cell in a terminal page contains only a single character. This is
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* usually a single UCS-4 value. However, Unicode allows combining-characters,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -143,68 +119,6 @@ static inline void term_char_freep(term_char_t *p) {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * Attributes
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * Each cell in a terminal page can have its own set of attributes. These alter
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * the behavior of the renderer for this single cell. We use term_attr to
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * specify attributes.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * The only non-obvious field is "ccode" for foreground and background colors.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * This field contains the terminal color-code in case no full RGB information
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * was given by the host. It is also required for dynamic color palettes. If it
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * is set to TERM_CCODE_RGB, the "red", "green" and "blue" fields contain the
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * full RGB color.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-enum {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- /* special color-codes */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_DEFAULT, /* default foreground/background color */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_256, /* 256color code */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_RGB, /* color is specified as RGB */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- /* dark color-codes */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_BLACK,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_RED,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_GREEN,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_YELLOW,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_BLUE,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_MAGENTA,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_CYAN,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_WHITE, /* technically: light grey */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- /* light color-codes */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_LIGHT_BLACK = TERM_CCODE_BLACK + 8, /* technically: dark grey */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_LIGHT_RED = TERM_CCODE_RED + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_LIGHT_GREEN = TERM_CCODE_GREEN + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_LIGHT_YELLOW = TERM_CCODE_YELLOW + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_LIGHT_BLUE = TERM_CCODE_BLUE + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_LIGHT_MAGENTA = TERM_CCODE_MAGENTA + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_LIGHT_CYAN = TERM_CCODE_CYAN + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_LIGHT_WHITE = TERM_CCODE_WHITE + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- TERM_CCODE_CNT,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-struct term_color {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- uint8_t ccode;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- uint8_t c256;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- uint8_t red;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- uint8_t green;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- uint8_t blue;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-struct term_attr {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- term_color fg; /* foreground color */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- term_color bg; /* background color */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- unsigned int bold : 1; /* bold font */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- unsigned int italic : 1; /* italic font */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- unsigned int underline : 1; /* underline text */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- unsigned int inverse : 1; /* inverse fg/bg */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- unsigned int protect : 1; /* protect from erase */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- unsigned int blink : 1; /* blink text */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- unsigned int hidden : 1; /* hidden */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* Cells
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* The term_cell structure respresents a single cell in a terminal page. It
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* contains the stored character, the age of the cell and all its attributes.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -344,26 +258,6 @@ term_line *term_history_pop(term_history *history, unsigned int reserve_width, c
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
unsigned int term_history_peek(term_history *history, unsigned int max, unsigned int reserve_width, const term_attr *attr, term_age_t age);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * UTF-8
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * The UTF-decoder and encoder are adjusted for terminals and provide proper
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * fallbacks for invalid UTF-8. In terminals it's quite usual to use fallbacks
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * instead of rejecting invalid input. This way, old legacy applications still
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- * work (this is especially important for 7bit/ASCII DEC modes).
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-struct term_utf8 {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- uint32_t chars[5];
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- uint32_t ucs4;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- unsigned int i_bytes : 3;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- unsigned int n_bytes : 3;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
- unsigned int valid : 1;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-size_t term_utf8_encode(char *out_utf8, uint32_t g);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-const uint32_t *term_utf8_decode(term_utf8 *p, size_t *out_len, char c);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* Parsers
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* The term_parser object parses control-sequences for both host and terminal
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* side. Based on this parser, there is a set of command-parsers that take a
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -680,13 +574,6 @@ struct term_parser {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
bool is_host : 1;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-int term_parser_new(term_parser **out, bool host);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-term_parser *term_parser_free(term_parser *parser);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-int term_parser_feed(term_parser *parser, const term_seq **seq_out, uint32_t raw);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-#define _term_parser_free_ _cleanup_(term_parser_freep)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-DEFINE_TRIVIAL_CLEANUP_FUNC(term_parser*, term_parser_free);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* Screens
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
* A term_screen object represents the terminal-side of the communication. It
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -713,9 +600,6 @@ enum {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
TERM_CONFORMANCE_LEVEL_CNT,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-typedef int (*term_screen_write_fn) (term_screen *screen, void *userdata, const void *buf, size_t size);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-typedef int (*term_screen_cmd_fn) (term_screen *screen, void *userdata, unsigned int cmd, const term_seq *seq);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
struct term_screen {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
unsigned long ref;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
term_age_t age;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -766,17 +650,3 @@ struct term_screen {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
unsigned int flags;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
} saved;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-int term_screen_new(term_screen **out, term_screen_write_fn write_fn, void *write_fn_data, term_screen_cmd_fn cmd_fn, void *cmd_fn_data);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-term_screen *term_screen_ref(term_screen *screen);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-term_screen *term_screen_unref(term_screen *screen);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-DEFINE_TRIVIAL_CLEANUP_FUNC(term_screen*, term_screen_unref);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-int term_screen_feed_text(term_screen *screen, const uint8_t *in, size_t size);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-int term_screen_feed_keyboard(term_screen *screen, uint32_t keysym, uint32_t ascii, uint32_t ucs4, unsigned int mods);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-int term_screen_resize(term_screen *screen, unsigned int width, unsigned int height);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-void term_screen_soft_reset(term_screen *screen);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-void term_screen_hard_reset(term_screen *screen);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
-int term_screen_set_answerback(term_screen *screen, const char *answerback);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
diff --git a/src/libsystemd-terminal/term.h b/src/libsystemd-terminal/term.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
new file mode 100644
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
index 0000000000..2f2bb479cb
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
--- /dev/null
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+++ b/src/libsystemd-terminal/term.h
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
@@ -0,0 +1,146 @@
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+/***
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ This file is part of systemd.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ systemd is free software; you can redistribute it and/or modify it
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ under the terms of the GNU Lesser General Public License as published by
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ the Free Software Foundation; either version 2.1 of the License, or
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ (at your option) any later version.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ systemd is distributed in the hope that it will be useful, but
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ Lesser General Public License for more details.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ You should have received a copy of the GNU Lesser General Public License
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+***/
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+#pragma once
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+#include <stdbool.h>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+#include <stdint.h>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+#include <stdlib.h>
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+#include "util.h"
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+typedef struct term_color term_color;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+typedef struct term_attr term_attr;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+typedef struct term_utf8 term_utf8;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+typedef struct term_seq term_seq;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+typedef struct term_parser term_parser;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+typedef struct term_screen term_screen;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ * Ageing
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+typedef uint64_t term_age_t;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+#define TERM_AGE_NULL 0
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ * Attributes
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+enum {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ /* special color-codes */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_DEFAULT, /* default foreground/background color */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_256, /* 256color code */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_RGB, /* color is specified as RGB */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ /* dark color-codes */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_BLACK,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_RED,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_GREEN,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_YELLOW,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_BLUE,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_MAGENTA,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_CYAN,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_WHITE, /* technically: light grey */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ /* light color-codes */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_LIGHT_BLACK = TERM_CCODE_BLACK + 8, /* technically: dark grey */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_LIGHT_RED = TERM_CCODE_RED + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_LIGHT_GREEN = TERM_CCODE_GREEN + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_LIGHT_YELLOW = TERM_CCODE_YELLOW + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_LIGHT_BLUE = TERM_CCODE_BLUE + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_LIGHT_MAGENTA = TERM_CCODE_MAGENTA + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_LIGHT_CYAN = TERM_CCODE_CYAN + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_LIGHT_WHITE = TERM_CCODE_WHITE + 8,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ TERM_CCODE_CNT,
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+struct term_color {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ uint8_t ccode;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ uint8_t c256;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ uint8_t red;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ uint8_t green;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ uint8_t blue;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+struct term_attr {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ term_color fg; /* foreground color */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ term_color bg; /* background color */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ unsigned int bold : 1; /* bold font */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ unsigned int italic : 1; /* italic font */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ unsigned int underline : 1; /* underline text */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ unsigned int inverse : 1; /* inverse fg/bg */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ unsigned int protect : 1; /* protect from erase */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ unsigned int blink : 1; /* blink text */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ unsigned int hidden : 1; /* hidden */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ * UTF-8
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+struct term_utf8 {
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ uint32_t chars[5];
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ uint32_t ucs4;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ unsigned int i_bytes : 3;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ unsigned int n_bytes : 3;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ unsigned int valid : 1;
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+};
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+size_t term_utf8_encode(char *out_utf8, uint32_t g);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+const uint32_t *term_utf8_decode(term_utf8 *p, size_t *out_len, char c);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ * Parsers
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int term_parser_new(term_parser **out, bool host);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+term_parser *term_parser_free(term_parser *parser);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int term_parser_feed(term_parser *parser, const term_seq **seq_out, uint32_t raw);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+#define _term_parser_free_ _cleanup_(term_parser_freep)
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+DEFINE_TRIVIAL_CLEANUP_FUNC(term_parser*, term_parser_free);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+/*
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ * Screens
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+ */
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+typedef int (*term_screen_write_fn) (term_screen *screen, void *userdata, const void *buf, size_t size);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+typedef int (*term_screen_cmd_fn) (term_screen *screen, void *userdata, unsigned int cmd, const term_seq *seq);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int term_screen_new(term_screen **out, term_screen_write_fn write_fn, void *write_fn_data, term_screen_cmd_fn cmd_fn, void *cmd_fn_data);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+term_screen *term_screen_ref(term_screen *screen);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+term_screen *term_screen_unref(term_screen *screen);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+DEFINE_TRIVIAL_CLEANUP_FUNC(term_screen*, term_screen_unref);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int term_screen_feed_text(term_screen *screen, const uint8_t *in, size_t size);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int term_screen_feed_keyboard(term_screen *screen, uint32_t keysym, uint32_t ascii, uint32_t ucs4, unsigned int mods);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int term_screen_resize(term_screen *screen, unsigned int width, unsigned int height);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+void term_screen_soft_reset(term_screen *screen);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+void term_screen_hard_reset(term_screen *screen);
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
62fe94 |
+int term_screen_set_answerback(term_screen *screen, const char *answerback);
|