Make the charsets code useable in kittens
This commit is contained in:
parent
6e94dae9cd
commit
de130787f6
26
kitty/charsets.c
generated
26
kitty/charsets.c
generated
@ -5,9 +5,13 @@
|
|||||||
* Distributed under terms of the GPL3 license.
|
* Distributed under terms of the GPL3 license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "data-types.h"
|
|
||||||
// Taken from consolemap.c in the linux vt driver sourcecode
|
// Taken from consolemap.c in the linux vt driver sourcecode
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#define UTF8_ACCEPT 0
|
||||||
|
#define UTF8_REJECT 1
|
||||||
|
|
||||||
static uint32_t charset_translations[5][256] = {
|
static uint32_t charset_translations[5][256] = {
|
||||||
/* 8-bit Latin-1 mapped to Unicode -- trivial mapping */
|
/* 8-bit Latin-1 mapped to Unicode -- trivial mapping */
|
||||||
{
|
{
|
||||||
@ -238,6 +242,26 @@ decode_utf8(uint32_t* state, uint32_t* codep, uint8_t byte) {
|
|||||||
return *state;
|
return *state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
decode_utf8_string(char *src, size_t sz, uint32_t *dest) {
|
||||||
|
// dest must be a zeroed array of size at least sz
|
||||||
|
uint32_t codep = 0, state = 0, prev = UTF8_ACCEPT;
|
||||||
|
size_t i, d;
|
||||||
|
for (i = 0, d = 0; i < sz; i++) {
|
||||||
|
switch(decode_utf8(&state, &codep, src[i])) {
|
||||||
|
case UTF8_ACCEPT:
|
||||||
|
dest[d++] = codep;
|
||||||
|
break;
|
||||||
|
case UTF8_REJECT:
|
||||||
|
state = UTF8_ACCEPT;
|
||||||
|
if (prev != UTF8_ACCEPT && i > 0) i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prev = state;
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
encode_utf8(uint32_t ch, char* dest) {
|
encode_utf8(uint32_t ch, char* dest) {
|
||||||
if (ch < 0x80) {
|
if (ch < 0x80) {
|
||||||
|
|||||||
14
kitty/charsets.h
Normal file
14
kitty/charsets.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
*
|
||||||
|
* Distributed under terms of the GPL3 license.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
uint32_t decode_utf8(uint32_t*, uint32_t*, uint8_t byte);
|
||||||
|
size_t decode_utf8_string(char *src, size_t sz, uint32_t *dest);
|
||||||
|
unsigned int encode_utf8(uint32_t ch, char* dest);
|
||||||
@ -9,6 +9,7 @@
|
|||||||
#include "threading.h"
|
#include "threading.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "fonts.h"
|
#include "fonts.h"
|
||||||
|
#include "charsets.h"
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
|
|||||||
@ -268,8 +268,6 @@ ColorProfile* alloc_color_profile();
|
|||||||
PyObject* create_256_color_table();
|
PyObject* create_256_color_table();
|
||||||
PyObject* parse_bytes_dump(PyObject UNUSED *, PyObject *);
|
PyObject* parse_bytes_dump(PyObject UNUSED *, PyObject *);
|
||||||
PyObject* parse_bytes(PyObject UNUSED *, PyObject *);
|
PyObject* parse_bytes(PyObject UNUSED *, PyObject *);
|
||||||
uint32_t decode_utf8(uint32_t*, uint32_t*, uint8_t byte);
|
|
||||||
unsigned int encode_utf8(uint32_t ch, char* dest);
|
|
||||||
void cursor_reset(Cursor*);
|
void cursor_reset(Cursor*);
|
||||||
Cursor* cursor_copy(Cursor*);
|
Cursor* cursor_copy(Cursor*);
|
||||||
void cursor_copy_to(Cursor *src, Cursor *dest);
|
void cursor_copy_to(Cursor *src, Cursor *dest);
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "data-types.h"
|
#include "data-types.h"
|
||||||
#include "unicode-data.h"
|
#include "unicode-data.h"
|
||||||
#include "lineops.h"
|
#include "lineops.h"
|
||||||
|
#include "charsets.h"
|
||||||
|
|
||||||
extern PyTypeObject Cursor_Type;
|
extern PyTypeObject Cursor_Type;
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "lineops.h"
|
#include "lineops.h"
|
||||||
|
#include "charsets.h"
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "glfw-wrapper.h"
|
#include "glfw-wrapper.h"
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "control-codes.h"
|
#include "control-codes.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
#include "charsets.h"
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
extern PyTypeObject Screen_Type;
|
extern PyTypeObject Screen_Type;
|
||||||
|
|||||||
@ -23,6 +23,7 @@
|
|||||||
#include "modes.h"
|
#include "modes.h"
|
||||||
#include "wcwidth-std.h"
|
#include "wcwidth-std.h"
|
||||||
#include "control-codes.h"
|
#include "control-codes.h"
|
||||||
|
#include "charsets.h"
|
||||||
|
|
||||||
static const ScreenModes empty_modes = {0, .mDECAWM=true, .mDECTCEM=true, .mDECARM=true};
|
static const ScreenModes empty_modes = {0, .mDECAWM=true, .mDECTCEM=true, .mDECARM=true};
|
||||||
static Selection EMPTY_SELECTION = {0};
|
static Selection EMPTY_SELECTION = {0};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user