mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-05 04:34:23 +02:00
Convert from GDNative to GDExtension
Work in progress.
This commit is contained in:
parent
6b47d35835
commit
44f7e3801c
25 changed files with 408 additions and 304 deletions
|
@ -1,23 +1,23 @@
|
|||
// SPDX-FileCopyrightText: 2021-2022 Leroy Hopson <godot-xterm@leroy.geek.nz>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "libuv_utils.h"
|
||||
#include <godot_cpp/classes/global_constants.hpp>
|
||||
#include <uv.h>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void LibuvUtils::_register_methods() {
|
||||
register_method("_init", &LibuvUtils::_init);
|
||||
void LibuvUtils::_bind_methods() {
|
||||
ClassDB::bind_static_method("LibuvUtils", D_METHOD("get_os_environ"), &LibuvUtils::get_os_environ);
|
||||
ClassDB::bind_static_method("LibuvUtils", D_METHOD("get_os_release"), &LibuvUtils::get_os_release);
|
||||
ClassDB::bind_static_method("LibuvUtils", D_METHOD("get_cwd"), &LibuvUtils::get_cwd);
|
||||
|
||||
register_method("get_os_environ", &LibuvUtils::get_os_environ);
|
||||
register_method("get_os_release", &LibuvUtils::get_os_release);
|
||||
register_method("get_cwd", &LibuvUtils::get_cwd);
|
||||
|
||||
register_method("kill", &LibuvUtils::kill);
|
||||
ClassDB::bind_static_method("LibuvUtils", D_METHOD("kill", "pid", "signum"), &LibuvUtils::kill);
|
||||
}
|
||||
|
||||
LibuvUtils::LibuvUtils() {}
|
||||
LibuvUtils::~LibuvUtils() {}
|
||||
|
||||
void LibuvUtils::_init() {}
|
||||
|
||||
Dictionary LibuvUtils::get_os_environ() {
|
||||
Dictionary result;
|
||||
|
||||
|
@ -63,50 +63,50 @@ String LibuvUtils::get_cwd() {
|
|||
return result;
|
||||
}
|
||||
|
||||
godot_error LibuvUtils::kill(int pid, int signum) {
|
||||
Error LibuvUtils::kill(int pid, int signum) {
|
||||
RETURN_UV_ERR(uv_kill(pid, signum));
|
||||
}
|
||||
|
||||
godot_error LibuvUtils::translate_uv_errno(int uv_err) {
|
||||
Error LibuvUtils::translate_uv_errno(int uv_err) {
|
||||
if (uv_err >= 0)
|
||||
return GODOT_OK;
|
||||
return OK;
|
||||
|
||||
// Rough translation of libuv error to godot error.
|
||||
// Not necessarily accurate.
|
||||
|
||||
switch (uv_err) {
|
||||
case UV_EEXIST: // file already exists
|
||||
return GODOT_ERR_ALREADY_EXISTS;
|
||||
return ERR_ALREADY_EXISTS;
|
||||
|
||||
case UV_EADDRINUSE: // address already in use
|
||||
return GODOT_ERR_ALREADY_IN_USE;
|
||||
return ERR_ALREADY_IN_USE;
|
||||
|
||||
case UV_EBUSY: // resource busy or locked
|
||||
case UV_ETXTBSY: // text file is busy
|
||||
return GODOT_ERR_BUSY;
|
||||
return ERR_BUSY;
|
||||
|
||||
case UV_ECONNREFUSED: // connection refused
|
||||
return GODOT_ERR_CANT_CONNECT;
|
||||
return ERR_CANT_CONNECT;
|
||||
|
||||
case UV_ECONNABORTED: // software caused connection abort
|
||||
case UV_ECONNRESET: // connection reset by peer
|
||||
case UV_EISCONN: // socket is already connected
|
||||
case UV_ENOTCONN: // socket is not connected
|
||||
return GODOT_ERR_CONNECTION_ERROR;
|
||||
return ERR_CONNECTION_ERROR;
|
||||
|
||||
case UV_ENODEV: // no such device
|
||||
case UV_ENXIO: // no such device or address
|
||||
case UV_ESRCH: // no such process
|
||||
return GODOT_ERR_DOES_NOT_EXIST;
|
||||
return ERR_DOES_NOT_EXIST;
|
||||
|
||||
case UV_EROFS: // read-only file system
|
||||
return GODOT_ERR_FILE_CANT_WRITE;
|
||||
return ERR_FILE_CANT_WRITE;
|
||||
|
||||
case UV_EOF: // end of file
|
||||
return GODOT_ERR_FILE_EOF;
|
||||
return ERR_FILE_EOF;
|
||||
|
||||
case UV_ENOENT: // no such file or directory
|
||||
return GODOT_ERR_FILE_NOT_FOUND;
|
||||
return ERR_FILE_NOT_FOUND;
|
||||
|
||||
case UV_EAI_BADFLAGS: // bad ai_flags value
|
||||
case UV_EAI_BADHINTS: // invalid value for hints
|
||||
|
@ -115,13 +115,13 @@ godot_error LibuvUtils::translate_uv_errno(int uv_err) {
|
|||
case UV_EINVAL: // invalid argument
|
||||
case UV_ENOTTY: // inappropriate ioctl for device
|
||||
case UV_EPROTOTYPE: // protocol wrong type for socket
|
||||
return GODOT_ERR_INVALID_PARAMETER; // Parameter passed is invalid
|
||||
return ERR_INVALID_PARAMETER; // Parameter passed is invalid
|
||||
|
||||
case UV_ENOSYS: // function not implemented
|
||||
return GODOT_ERR_METHOD_NOT_FOUND;
|
||||
return ERR_METHOD_NOT_FOUND;
|
||||
|
||||
case UV_EAI_MEMORY: // out of memory
|
||||
return GODOT_ERR_OUT_OF_MEMORY;
|
||||
return ERR_OUT_OF_MEMORY;
|
||||
|
||||
case UV_E2BIG: // argument list too long
|
||||
case UV_EFBIG: // file too large
|
||||
|
@ -129,15 +129,15 @@ godot_error LibuvUtils::translate_uv_errno(int uv_err) {
|
|||
case UV_ENAMETOOLONG: // name too long
|
||||
case UV_EOVERFLOW: // value too large for defined data type
|
||||
case UV_ERANGE: // result too large
|
||||
return GODOT_ERR_PARAMETER_RANGE_ERROR; // Parameter given out of range
|
||||
return ERR_PARAMETER_RANGE_ERROR; // Parameter given out of range
|
||||
|
||||
case UV_ETIMEDOUT:
|
||||
return GODOT_ERR_TIMEOUT; // connection timed out
|
||||
return ERR_TIMEOUT; // connection timed out
|
||||
|
||||
case UV_EACCES: // permission denied
|
||||
case UV_EPERM: // operation not permitted
|
||||
case UV_EXDEV: // cross-device link not permitted
|
||||
return GODOT_ERR_UNAUTHORIZED;
|
||||
return ERR_UNAUTHORIZED;
|
||||
|
||||
case UV_EADDRNOTAVAIL: // address not available
|
||||
case UV_EAFNOSUPPORT: // address family not supported
|
||||
|
@ -150,12 +150,12 @@ godot_error LibuvUtils::translate_uv_errno(int uv_err) {
|
|||
case UV_ENOTSUP: // operation not supported on socket
|
||||
case UV_EPROTONOSUPPORT: // protocol not supported
|
||||
case UV_ESOCKTNOSUPPORT: // socket type not supported
|
||||
return GODOT_ERR_UNAVAILABLE; // What is requested is
|
||||
return ERR_UNAVAILABLE; // What is requested is
|
||||
// unsupported/unavailable
|
||||
|
||||
case UV_EAI_NODATA: // no address
|
||||
case UV_EDESTADDRREQ: // destination address required
|
||||
return GODOT_ERR_UNCONFIGURED;
|
||||
return ERR_UNCONFIGURED;
|
||||
|
||||
case UV_EAI_AGAIN: // temporary failure
|
||||
case UV_EAI_CANCELED: // request canceled
|
||||
|
@ -191,6 +191,6 @@ godot_error LibuvUtils::translate_uv_errno(int uv_err) {
|
|||
case UV_ESPIPE: // invalid seek
|
||||
case UV_UNKNOWN: // unknown error
|
||||
default:
|
||||
return GODOT_FAILED; // Generic fail error
|
||||
return FAILED; // Generic fail error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef GODOT_XTERM_UV_UTILS_H
|
||||
#define GODOT_XTERM_UV_UTILS_H
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <godot_cpp/classes/ref_counted.hpp>
|
||||
#include <uv.h>
|
||||
|
||||
#define UV_ERR_PRINT(uv_err) \
|
||||
|
@ -21,27 +21,26 @@
|
|||
|
||||
namespace godot {
|
||||
|
||||
class LibuvUtils : public Reference {
|
||||
GODOT_CLASS(LibuvUtils, Reference)
|
||||
class LibuvUtils : public RefCounted {
|
||||
GDCLASS(LibuvUtils, RefCounted)
|
||||
|
||||
public:
|
||||
static void _register_methods();
|
||||
|
||||
LibuvUtils();
|
||||
~LibuvUtils();
|
||||
|
||||
void _init();
|
||||
static Dictionary get_os_environ();
|
||||
static String get_os_release();
|
||||
static String get_cwd();
|
||||
|
||||
Dictionary get_os_environ();
|
||||
String get_os_release();
|
||||
String get_cwd();
|
||||
|
||||
godot_error kill(int pid, int signum);
|
||||
static Error kill(int pid, int signum);
|
||||
|
||||
public:
|
||||
static godot_error translate_uv_errno(int uv_err);
|
||||
static Error translate_uv_errno(int uv_err);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // GODOT_XTERM_UV_UTILS_H
|
||||
#endif // GODOT_XTERM_UV_UTILS_H
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include "pty.h"
|
||||
#include "libuv_utils.h"
|
||||
#include <FuncRef.hpp>
|
||||
#include <godot_cpp/variant/callable.hpp>
|
||||
#include <uv.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -89,7 +89,7 @@ using namespace godot;
|
|||
*/
|
||||
|
||||
struct pty_baton {
|
||||
Ref<FuncRef> cb;
|
||||
Callable cb;
|
||||
int exit_code;
|
||||
int signal_code;
|
||||
pid_t pid;
|
||||
|
@ -119,11 +119,11 @@ static void pty_after_waitpid(uv_async_t *);
|
|||
|
||||
static void pty_after_close(uv_handle_t *);
|
||||
|
||||
Array PTYUnix::fork(String p_file, int _ignored, PoolStringArray p_args,
|
||||
PoolStringArray p_env, String p_cwd, int p_cols, int p_rows,
|
||||
int p_uid, int p_gid, bool p_utf8, Ref<FuncRef> p_on_exit) {
|
||||
Array PTYUnix::fork(String p_file, int _ignored, PackedStringArray p_args,
|
||||
PackedStringArray p_env, String p_cwd, int p_cols, int p_rows,
|
||||
int p_uid, int p_gid, bool p_utf8, Callable p_on_exit) {
|
||||
// file
|
||||
char *file = p_file.alloc_c_string();
|
||||
char *file = strdup(p_file.utf8().get_data());
|
||||
|
||||
// args
|
||||
int i = 0;
|
||||
|
@ -133,7 +133,7 @@ Array PTYUnix::fork(String p_file, int _ignored, PoolStringArray p_args,
|
|||
argv[0] = strdup(file);
|
||||
argv[argl - 1] = NULL;
|
||||
for (; i < argc; i++) {
|
||||
char *arg = p_args[i].alloc_c_string();
|
||||
char *arg = strdup(p_args[i].utf8().get_data());
|
||||
argv[i + 1] = strdup(arg);
|
||||
}
|
||||
|
||||
|
@ -143,12 +143,12 @@ Array PTYUnix::fork(String p_file, int _ignored, PoolStringArray p_args,
|
|||
char **env = new char *[envc + 1];
|
||||
env[envc] = NULL;
|
||||
for (; i < envc; i++) {
|
||||
char *pairs = p_env[i].alloc_c_string();
|
||||
char *pairs = strdup(p_env[i].utf8().get_data());
|
||||
env[i] = strdup(pairs);
|
||||
}
|
||||
|
||||
// cwd
|
||||
char *cwd = strdup(p_cwd.alloc_c_string());
|
||||
char *cwd = strdup(p_cwd.utf8().get_data());
|
||||
|
||||
// size
|
||||
struct winsize winp;
|
||||
|
@ -240,7 +240,7 @@ Array PTYUnix::fork(String p_file, int _ignored, PoolStringArray p_args,
|
|||
switch (pid) {
|
||||
case -1:
|
||||
ERR_PRINT("forkpty(3) failed.");
|
||||
return Array::make(GODOT_FAILED);
|
||||
return Array::make(FAILED);
|
||||
case 0:
|
||||
if (strlen(cwd)) {
|
||||
if (chdir(cwd) == -1) {
|
||||
|
@ -267,10 +267,10 @@ Array PTYUnix::fork(String p_file, int _ignored, PoolStringArray p_args,
|
|||
default:
|
||||
if (pty_nonblock(master) == -1) {
|
||||
ERR_PRINT("Could not set master fd to nonblocking.");
|
||||
return Array::make(GODOT_FAILED);
|
||||
return Array::make(FAILED);
|
||||
}
|
||||
|
||||
Dictionary result = Dictionary::make();
|
||||
Dictionary result;
|
||||
result["fd"] = (int)master;
|
||||
result["pid"] = (int)pid;
|
||||
result["pty"] = ptsname(master);
|
||||
|
@ -286,10 +286,10 @@ Array PTYUnix::fork(String p_file, int _ignored, PoolStringArray p_args,
|
|||
|
||||
uv_thread_create(&baton->tid, pty_waitpid, static_cast<void *>(baton));
|
||||
|
||||
return Array::make(GODOT_OK, result);
|
||||
return Array::make(OK, result);
|
||||
}
|
||||
|
||||
return Array::make(GODOT_FAILED);
|
||||
return Array::make(FAILED);
|
||||
}
|
||||
|
||||
Array PTYUnix::open(int p_cols, int p_rows) {
|
||||
|
@ -306,28 +306,28 @@ Array PTYUnix::open(int p_cols, int p_rows) {
|
|||
|
||||
if (ret == -1) {
|
||||
ERR_PRINT("openpty(3) failed.");
|
||||
return Array::make(GODOT_FAILED);
|
||||
return Array::make(FAILED);
|
||||
}
|
||||
|
||||
if (pty_nonblock(master) == -1) {
|
||||
ERR_PRINT("Could not set master fd to nonblocking.");
|
||||
return Array::make(GODOT_FAILED);
|
||||
return Array::make(FAILED);
|
||||
}
|
||||
|
||||
if (pty_nonblock(slave) == -1) {
|
||||
ERR_PRINT("Could not set slave fd to nonblocking.");
|
||||
return Array::make(GODOT_FAILED);
|
||||
return Array::make(FAILED);
|
||||
}
|
||||
|
||||
Dictionary dict = Dictionary::make();
|
||||
Dictionary dict;
|
||||
dict["master"] = master;
|
||||
dict["slave"] = slave;
|
||||
dict["pty"] = ptsname(master);
|
||||
|
||||
return Array::make(GODOT_OK, dict);
|
||||
return Array::make(OK, dict);
|
||||
}
|
||||
|
||||
godot_error PTYUnix::resize(int p_fd, int p_cols, int p_rows) {
|
||||
Error PTYUnix::resize(int p_fd, int p_cols, int p_rows) {
|
||||
int fd = p_fd;
|
||||
|
||||
struct winsize winp;
|
||||
|
@ -348,10 +348,10 @@ godot_error PTYUnix::resize(int p_fd, int p_cols, int p_rows) {
|
|||
RETURN_UV_ERR(UV_ENOTTY);
|
||||
}
|
||||
ERR_PRINT("ioctl(2) failed");
|
||||
return GODOT_FAILED;
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
return GODOT_OK;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -360,7 +360,7 @@ godot_error PTYUnix::resize(int p_fd, int p_cols, int p_rows) {
|
|||
String PTYUnix::process(int p_fd, String p_tty) {
|
||||
int fd = p_fd;
|
||||
|
||||
char *tty = p_tty.alloc_c_string();
|
||||
char *tty = strdup(p_tty.utf8().get_data());
|
||||
char *name = pty_getproc(fd, tty);
|
||||
std::free(tty);
|
||||
|
||||
|
@ -445,9 +445,9 @@ static void pty_after_waitpid(uv_async_t *async) {
|
|||
|
||||
Array argv = Array::make(baton->exit_code, baton->signal_code);
|
||||
|
||||
if (baton->cb != nullptr && baton->cb->is_valid()) {
|
||||
baton->cb->call_funcv(argv);
|
||||
baton->cb = (Ref<FuncRef>)nullptr;
|
||||
if (baton->cb != nullptr && baton->cb.is_valid()) {
|
||||
baton->cb.callv(argv);
|
||||
baton->cb = (Variant)nullptr;
|
||||
}
|
||||
|
||||
uv_close((uv_handle_t *)async, pty_after_close);
|
||||
|
@ -663,12 +663,12 @@ static pid_t pty_forkpty(int *amaster, char *name, const struct termios *termp,
|
|||
* Init
|
||||
*/
|
||||
|
||||
void PTYUnix::_register_methods() {
|
||||
register_method("_init", &PTYUnix::_init);
|
||||
register_method("fork", &PTYUnix::fork);
|
||||
register_method("open", &PTYUnix::open);
|
||||
register_method("resize", &PTYUnix::resize);
|
||||
register_method("process", &PTYUnix::process);
|
||||
void PTYUnix::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_init"), &PTYUnix::_init);
|
||||
ClassDB::bind_method(D_METHOD("fork"), &PTYUnix::fork);
|
||||
ClassDB::bind_method(D_METHOD("open"), &PTYUnix::open);
|
||||
ClassDB::bind_method(D_METHOD("resize"), &PTYUnix::resize);
|
||||
ClassDB::bind_method(D_METHOD("process"), &PTYUnix::process);
|
||||
}
|
||||
|
||||
void PTYUnix::_init() {}
|
||||
void PTYUnix::_init() {}
|
||||
|
|
|
@ -1,29 +1,32 @@
|
|||
// Copyright (c) 2021, Leroy Hopson (MIT License).
|
||||
// SPDX-FileCopyrightText: 2021-2022 Leroy Hopson <godot-xterm@leroy.geek.nz>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#ifndef GODOT_XTERM_PTY_H
|
||||
#define GODOT_XTERM_PTY_H
|
||||
|
||||
#include <FuncRef.hpp>
|
||||
#include <Godot.hpp>
|
||||
#include <godot_cpp/classes/ref_counted.hpp>
|
||||
#include <godot_cpp/variant/callable.hpp>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class PTYUnix : public Reference {
|
||||
GODOT_CLASS(PTYUnix, Reference)
|
||||
class PTYUnix : public RefCounted {
|
||||
GDCLASS(PTYUnix, RefCounted)
|
||||
|
||||
public:
|
||||
Array fork(String file,
|
||||
int _ignored, /* FIXME: For some reason Pipe throws
|
||||
ENOTSOCK in read callback if args (or another non-empty,
|
||||
non-zero) value is in this position. */
|
||||
PoolStringArray args, PoolStringArray env, String cwd, int cols,
|
||||
int rows, int uid, int gid, bool utf8, Ref<FuncRef> on_exit);
|
||||
PackedStringArray args, PackedStringArray env, String cwd, int cols,
|
||||
int rows, int uid, int gid, bool utf8, Callable on_exit);
|
||||
Array open(int cols, int rows);
|
||||
godot_error resize(int fd, int cols, int rows);
|
||||
Error resize(int fd, int cols, int rows);
|
||||
String process(int fd, String tty);
|
||||
|
||||
void _init();
|
||||
static void _register_methods();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
// Copyright (c) 2021, Leroy Hopson (MIT License).
|
||||
// SPDX-FileCopyrightText: 2021 Leroy Hopson <godot-xterm@leroy.geek.nz>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#ifndef GODOT_XTERM_CONPTY_H
|
||||
#define GODOT_XTERM_CONPTY_H
|
||||
|
||||
#include <FuncRef.hpp>
|
||||
#include <Godot.hpp>
|
||||
#include <godot_cpp/classes/ref_counted.hpp>
|
||||
#include <godot_cpp/variant/callable.hpp>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class ConPTY : public Reference {
|
||||
GODOT_CLASS(ConPTY, Reference)
|
||||
class ConPTY : public RefCounted {
|
||||
GDCLASS(ConPTY, RefCounted)
|
||||
|
||||
public:
|
||||
// Array fork(String file,
|
||||
|
@ -25,9 +26,11 @@ public:
|
|||
// String process(int fd, String tty);
|
||||
|
||||
void _init();
|
||||
static void _register_methods();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // GODOT_XTERM_CONPTY_H
|
||||
#endif // GODOT_XTERM_CONPTY_H
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
|
||||
#include "pipe.h"
|
||||
#include "libuv_utils.h"
|
||||
#include <Dictionary.hpp>
|
||||
#include <InputEventKey.hpp>
|
||||
#include <OS.hpp>
|
||||
#include <ResourceLoader.hpp>
|
||||
#include <Theme.hpp>
|
||||
#include <Timer.hpp>
|
||||
#include <godot_cpp/variant/dictionary.hpp>
|
||||
#include <godot_cpp/variant/packed_byte_array.hpp>
|
||||
#include <godot_cpp/classes/global_constants.hpp>
|
||||
#include <godot_cpp/classes/input_event_key.hpp>
|
||||
#include <godot_cpp/classes/os.hpp>
|
||||
#include <godot_cpp/classes/resource_loader.hpp>
|
||||
#include <godot_cpp/classes/theme.hpp>
|
||||
#include <godot_cpp/classes/timer.hpp>
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
@ -19,17 +21,16 @@
|
|||
|
||||
using namespace godot;
|
||||
|
||||
void Pipe::_register_methods() {
|
||||
register_method("_init", &Pipe::_init);
|
||||
void Pipe::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_init"), &Pipe::_init);
|
||||
|
||||
register_method("poll", &Pipe::_poll_connection);
|
||||
register_method("open", &Pipe::open);
|
||||
register_method("write", &Pipe::write);
|
||||
register_method("get_status", &Pipe::get_status);
|
||||
register_method("close", &Pipe::close);
|
||||
ClassDB::bind_method(D_METHOD("poll"), &Pipe::_poll_connection);
|
||||
ClassDB::bind_method(D_METHOD("open"), &Pipe::open);
|
||||
ClassDB::bind_method(D_METHOD("write"), &Pipe::write);
|
||||
ClassDB::bind_method(D_METHOD("get_status"), &Pipe::get_status);
|
||||
ClassDB::bind_method(D_METHOD("close"), &Pipe::close);
|
||||
|
||||
register_signal<Pipe>("data_received", "data",
|
||||
GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY);
|
||||
ADD_SIGNAL(MethodInfo("data_received", PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data")));
|
||||
}
|
||||
|
||||
Pipe::Pipe() {}
|
||||
|
@ -47,7 +48,7 @@ void _write_cb(uv_write_t *req, int status);
|
|||
|
||||
void _alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
||||
|
||||
godot_error Pipe::open(int fd, bool ipc = false) {
|
||||
Error Pipe::open(int fd, bool ipc = false) {
|
||||
RETURN_IF_UV_ERR(uv_pipe_init(uv_default_loop(), &handle, ipc));
|
||||
|
||||
handle.data = this;
|
||||
|
@ -58,7 +59,7 @@ godot_error Pipe::open(int fd, bool ipc = false) {
|
|||
uv_read_start((uv_stream_t *)&handle, _alloc_buffer, _read_cb));
|
||||
|
||||
status = 1;
|
||||
return GODOT_OK;
|
||||
return OK;
|
||||
}
|
||||
|
||||
void Pipe::close() {
|
||||
|
@ -66,8 +67,8 @@ void Pipe::close() {
|
|||
uv_run(uv_default_loop(), UV_RUN_NOWAIT);
|
||||
}
|
||||
|
||||
godot_error Pipe::write(PoolByteArray data) {
|
||||
char *s = (char *)data.read().ptr();
|
||||
Error Pipe::write(PackedByteArray data) {
|
||||
char *s = (char *)data.ptr();
|
||||
ULONG len = data.size();
|
||||
|
||||
uv_buf_t buf;
|
||||
|
@ -80,7 +81,7 @@ godot_error Pipe::write(PoolByteArray data) {
|
|||
uv_write(req, (uv_stream_t *)&handle, &buf, 1, _write_cb);
|
||||
uv_run(uv_default_loop(), UV_RUN_NOWAIT);
|
||||
|
||||
return GODOT_OK;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Pipe::get_status() {
|
||||
|
@ -116,9 +117,9 @@ void _read_cb(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) {
|
|||
return;
|
||||
}
|
||||
|
||||
PoolByteArray data;
|
||||
PackedByteArray data;
|
||||
data.resize(nread);
|
||||
{ memcpy(data.write().ptr(), buf->base, nread); }
|
||||
{ memcpy(data.ptrw(), buf->base, nread); }
|
||||
std::free((char *)buf->base);
|
||||
|
||||
pipe->emit_signal("data_received", data);
|
||||
|
|
|
@ -1,32 +1,31 @@
|
|||
// Copyright (c) 2021, Leroy Hopson (MIT License).
|
||||
// SPDX-FileCopyrightText: 2021-2022 Leroy Hopson <godot-xterm@leroy.geek.nz>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#ifndef GODOT_XTERM_PIPE_H
|
||||
#define GODOT_XTERM_PIPE_H
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <Reference.hpp>
|
||||
#include <godot_cpp/classes/ref_counted.hpp>
|
||||
#include <godot_cpp/variant/packed_byte_array.hpp>
|
||||
#include <uv.h>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Pipe : public Reference {
|
||||
GODOT_CLASS(Pipe, Reference)
|
||||
class Pipe : public RefCounted {
|
||||
GDCLASS(Pipe, RefCounted)
|
||||
|
||||
public:
|
||||
uv_pipe_t handle;
|
||||
|
||||
static void _register_methods();
|
||||
|
||||
Pipe();
|
||||
~Pipe();
|
||||
|
||||
void _init();
|
||||
|
||||
godot_error open(int fd, bool ipc);
|
||||
Error open(int fd, bool ipc);
|
||||
void close();
|
||||
int get_status();
|
||||
|
||||
godot_error write(PoolByteArray data);
|
||||
Error write(PackedByteArray data);
|
||||
|
||||
void pause();
|
||||
void resume();
|
||||
|
@ -34,10 +33,13 @@ public:
|
|||
public:
|
||||
int status;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
void _poll_connection();
|
||||
|
||||
static godot_error _translate_error(int err);
|
||||
static Error _translate_error(int err);
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
|
60
addons/godot_xterm/native/src/register_types.cpp
Normal file
60
addons/godot_xterm/native/src/register_types.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) 2022, Leroy Hopson (MIT License).
|
||||
|
||||
#include "register_types.h"
|
||||
|
||||
#include <gdextension_interface.h>
|
||||
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
#include <godot_cpp/core/defs.hpp>
|
||||
#include <godot_cpp/godot.hpp>
|
||||
|
||||
#include "terminal.h"
|
||||
|
||||
#if !defined(_PTY_DISABLED)
|
||||
#include "libuv_utils.h"
|
||||
#include "pipe.h"
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
#include "node_pty/unix/pty.h"
|
||||
#endif
|
||||
#if defined(__WIN32)
|
||||
//#include "node_pty/win/conpty.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void initialize_godot_xterm_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ClassDB::register_class<Terminal>();
|
||||
#if !defined(_PTY_DISABLED)
|
||||
ClassDB::register_class<Pipe>();
|
||||
ClassDB::register_class<LibuvUtils>();
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
ClassDB::register_class<PTYUnix>();
|
||||
#endif
|
||||
#if defined(__WIN32)
|
||||
//ClassDB::register_class<ConPTY>();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void uninitialize_godot_xterm_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
// Initialization
|
||||
GDExtensionBool GDE_EXPORT godot_xterm_library_init(const GDExtensionInterface *p_interface, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
|
||||
godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
|
||||
|
||||
init_obj.register_initializer(initialize_godot_xterm_module);
|
||||
init_obj.register_terminator(uninitialize_godot_xterm_module);
|
||||
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
|
||||
|
||||
return init_obj.init();
|
||||
}
|
11
addons/godot_xterm/native/src/register_types.h
Normal file
11
addons/godot_xterm/native/src/register_types.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef GODOT_XTERM_REGISTER_TYPES_H
|
||||
#define GODOT_XTERM_REGISTER_TYPES_H
|
||||
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void initialize_godot_xterm_module(ModuleInitializationLevel p_level);
|
||||
void uninitialize_godot_xterm_module(ModuleInitializationLevel p_level);
|
||||
|
||||
#endif // GODOT_XTERM_REGISTER_TYPES_H
|
|
@ -1,19 +1,19 @@
|
|||
// Copyright (c) 2021, Leroy Hopson (MIT License).
|
||||
|
||||
#include "terminal.h"
|
||||
#include <Dictionary.hpp>
|
||||
#include <InputEventKey.hpp>
|
||||
#include <InputEventMouseButton.hpp>
|
||||
#include <OS.hpp>
|
||||
#include <ResourceLoader.hpp>
|
||||
#include <Theme.hpp>
|
||||
#include <godot_cpp/variant/dictionary.hpp>
|
||||
#include <godot_cpp/classes/input_event_key.hpp>
|
||||
#include <godot_cpp/classes/input_event_mouse_button.hpp>
|
||||
#include <godot_cpp/classes/os.hpp>
|
||||
#include <godot_cpp/classes/resource_loader.hpp>
|
||||
#include <godot_cpp/classes/theme.hpp>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <xkbcommon/xkbcommon-keysyms.h>
|
||||
|
||||
// For _populate_key_list(), see below.
|
||||
#if !defined(__EMSCRIPTEN__) && !defined(__APPLE__)
|
||||
#include <GlobalConstants.hpp>
|
||||
#include <godot_cpp/classes/global_constants.hpp>
|
||||
#endif
|
||||
|
||||
using namespace godot;
|
||||
|
@ -23,22 +23,8 @@ void Terminal::_populate_key_list() {
|
|||
if (!_key_list.empty())
|
||||
return;
|
||||
|
||||
// The following error is thrown on the javascript platform when using
|
||||
// GlobalConstants from the header: abort(Assertion failed: bad export type for
|
||||
// `_ZN5godot15GlobalConstants8KEY_KP_0E`: undefined). Build with -s
|
||||
// ASSERTIONS=1 for more info.
|
||||
#if !defined(__EMSCRIPTEN__) && !defined(__APPLE__)
|
||||
#define GLOBAL_CONSTANT(VAR) GlobalConstants::VAR
|
||||
#else
|
||||
#define GLOBAL_CONSTANT(VAR) get_constant(#VAR)
|
||||
const godot_dictionary _constants = godot::api->godot_get_global_constants();
|
||||
const Dictionary *constants = (Dictionary *)&_constants;
|
||||
|
||||
auto get_constant = [constants](std::string name) -> int64_t {
|
||||
godot::Variant key = (godot::Variant)(godot::String(name.c_str()));
|
||||
return constants->operator[](key);
|
||||
};
|
||||
#endif
|
||||
// TODO: Remove GLOBAL_CONSTANT macro.
|
||||
#define GLOBAL_CONSTANT(VAR) VAR
|
||||
|
||||
// Godot does not have seperate scancodes for keypad keys when NumLock is off.
|
||||
// We can check the unicode value to determine whether it is off and set the
|
||||
|
@ -226,9 +212,9 @@ static void write_cb(struct tsm_vte *vte, const char *u8, size_t len,
|
|||
void *data) {
|
||||
Terminal *term = static_cast<Terminal *>(data);
|
||||
|
||||
PoolByteArray bytes = PoolByteArray();
|
||||
PackedByteArray bytes;
|
||||
bytes.resize(len);
|
||||
{ memcpy(bytes.write().ptr(), u8, len); }
|
||||
{ memcpy(bytes.ptrw(), u8, len); }
|
||||
|
||||
if (len > 0) {
|
||||
if (term->input_event_key.is_valid()) {
|
||||
|
@ -276,51 +262,53 @@ static void bell_cb(tsm_vte *_vte, void *data) {
|
|||
terminal->emit_signal("bell");
|
||||
}
|
||||
|
||||
void Terminal::_register_methods() {
|
||||
register_method("_init", &Terminal::_init);
|
||||
register_method("_ready", &Terminal::_ready);
|
||||
register_method("_notification", &Terminal::_notification);
|
||||
register_method("_gui_input", &Terminal::_gui_input);
|
||||
register_method("_draw", &Terminal::_draw);
|
||||
void Terminal::_bind_methods() {
|
||||
//ClassDB::bind_method(D_METHOD("_ready"), &Terminal::_ready);
|
||||
ClassDB::bind_method(D_METHOD("_notification"), &Terminal::_notification);
|
||||
ClassDB::bind_method(D_METHOD("__gui_input"), &Terminal::_gui_input);
|
||||
//ClassDB::bind_method(D_METHOD("_draw"), &Terminal::_draw);
|
||||
|
||||
register_method("write", &Terminal::write);
|
||||
ClassDB::bind_method(D_METHOD("write"), &Terminal::write);
|
||||
|
||||
register_method("sb_up", &Terminal::sb_up);
|
||||
register_method("sb_down", &Terminal::sb_down);
|
||||
register_method("sb_reset", &Terminal::sb_reset);
|
||||
register_method("clear_sb", &Terminal::clear_sb);
|
||||
ClassDB::bind_method(D_METHOD("sb_up"), &Terminal::sb_up);
|
||||
ClassDB::bind_method(D_METHOD("sb_down"), &Terminal::sb_down);
|
||||
ClassDB::bind_method(D_METHOD("sb_reset"), &Terminal::sb_reset);
|
||||
ClassDB::bind_method(D_METHOD("clear_sb"), &Terminal::clear_sb);
|
||||
|
||||
register_method("start_selection", &Terminal::start_selection);
|
||||
register_method("select_to_pointer", &Terminal::select_to_pointer);
|
||||
register_method("reset_selection", &Terminal::reset_selection);
|
||||
register_method("copy_selection", &Terminal::copy_selection);
|
||||
register_method("copy_all", &Terminal::copy_all);
|
||||
ClassDB::bind_method(D_METHOD("start_selection"), &Terminal::start_selection);
|
||||
ClassDB::bind_method(D_METHOD("select_to_pointer"), &Terminal::select_to_pointer);
|
||||
ClassDB::bind_method(D_METHOD("reset_selection"), &Terminal::reset_selection);
|
||||
ClassDB::bind_method(D_METHOD("copy_selection"), &Terminal::copy_selection);
|
||||
ClassDB::bind_method(D_METHOD("copy_all"), &Terminal::copy_all);
|
||||
|
||||
register_method("_update_theme", &Terminal::update_theme);
|
||||
register_method("_update_size", &Terminal::update_theme);
|
||||
ClassDB::bind_method(D_METHOD("_update_theme"), &Terminal::update_theme);
|
||||
ClassDB::bind_method(D_METHOD("_update_size"), &Terminal::update_theme);
|
||||
|
||||
register_property<Terminal, Vector2>("cell_size", &Terminal::cell_size,
|
||||
Vector2(0, 0));
|
||||
register_property<Terminal, int>("rows", &Terminal::rows, 24);
|
||||
register_property<Terminal, int>("cols", &Terminal::cols, 80);
|
||||
register_property<Terminal, int>("update_mode", &Terminal::update_mode,
|
||||
UpdateMode::AUTO);
|
||||
ClassDB::bind_method(D_METHOD("get_cell_size"), &Terminal::get_cell_size);
|
||||
ClassDB::bind_method(D_METHOD("get_rows"), &Terminal::get_rows);
|
||||
ClassDB::bind_method(D_METHOD("get_cols"), &Terminal::get_cols);
|
||||
ClassDB::bind_method(D_METHOD("get_update_mode"), &Terminal::get_update_mode);
|
||||
ClassDB::bind_method(D_METHOD("set_update_mode", "update_mode"), &Terminal::set_update_mode);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "update_mode"), "set_update_mode", "get_update_mode");
|
||||
|
||||
register_signal<Terminal>("data_sent", "data",
|
||||
GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY);
|
||||
register_signal<Terminal>("key_pressed", "data",
|
||||
GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY, "event",
|
||||
GODOT_VARIANT_TYPE_OBJECT);
|
||||
register_signal<Terminal>("size_changed", "new_size",
|
||||
GODOT_VARIANT_TYPE_VECTOR2);
|
||||
register_signal<Terminal>("bell", Dictionary());
|
||||
ADD_SIGNAL(MethodInfo("data_sent", PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data")));
|
||||
ADD_SIGNAL(MethodInfo("key_pressed", PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data"),
|
||||
PropertyInfo(Variant::OBJECT, "event")));
|
||||
ADD_SIGNAL(MethodInfo("size_changed", PropertyInfo(Variant::VECTOR2, "new_size")));
|
||||
ADD_SIGNAL(MethodInfo("bell"));
|
||||
}
|
||||
|
||||
Terminal::Terminal() {}
|
||||
|
||||
Terminal::~Terminal() {}
|
||||
|
||||
void Terminal::_init() {
|
||||
// TODO: Investigate using UPDATE_MODE enum instead of int.
|
||||
int Terminal::get_update_mode() { return update_mode; }
|
||||
void Terminal::set_update_mode(int p_update_mode) { update_mode = p_update_mode; };
|
||||
|
||||
Vector2 Terminal::get_cell_size() { return cell_size; }
|
||||
int Terminal::get_rows() { return rows; }
|
||||
int Terminal::get_cols() { return cols; }
|
||||
|
||||
Terminal::Terminal() {
|
||||
framebuffer_age = 0;
|
||||
update_mode = UpdateMode::AUTO;
|
||||
|
||||
|
@ -358,16 +346,16 @@ void Terminal::_gui_input(Variant event) {
|
|||
return;
|
||||
}
|
||||
|
||||
int64_t scancode = k->get_scancode();
|
||||
int64_t scancode = k->get_keycode();
|
||||
int64_t unicode = k->get_unicode();
|
||||
uint32_t ascii = unicode <= 127 ? unicode : 0;
|
||||
|
||||
unsigned int mods = 0;
|
||||
if (k->get_alt())
|
||||
if (k->is_alt_pressed())
|
||||
mods |= TSM_ALT_MASK;
|
||||
if (k->get_control())
|
||||
if (k->is_ctrl_pressed())
|
||||
mods |= TSM_CONTROL_MASK;
|
||||
if (k->get_shift())
|
||||
if (k->is_shift_pressed())
|
||||
mods |= TSM_SHIFT_MASK;
|
||||
|
||||
uint32_t keysym = mapkey({unicode, scancode});
|
||||
|
@ -418,8 +406,8 @@ void Terminal::update_theme() {
|
|||
Color default_color) -> void {
|
||||
Color c;
|
||||
|
||||
c = has_color(theme_color, "Terminal") ? get_color(theme_color, "Terminal")
|
||||
: has_color_override(theme_color) ? get_color(theme_color, "")
|
||||
c = has_theme_color(theme_color, "Terminal") ? get_theme_color(theme_color, "Terminal")
|
||||
: has_theme_color_override(theme_color) ? get_theme_color(theme_color, "")
|
||||
: (default_theme != nullptr &&
|
||||
default_theme->has_color(theme_color, "Terminal"))
|
||||
? default_theme->get_color(theme_color, "Terminal")
|
||||
|
@ -488,17 +476,17 @@ void Terminal::update_theme() {
|
|||
auto load_font = [this, default_theme](String font_style) -> void {
|
||||
Ref<Font> fontref;
|
||||
|
||||
if (has_font(font_style, "Terminal")) {
|
||||
fontref = get_font(font_style, "Terminal");
|
||||
} else if (has_font_override(font_style)) {
|
||||
fontref = get_font(font_style, "");
|
||||
} else if (has_font("regular", "Terminal")) {
|
||||
fontref = get_font("regular", "Terminal");
|
||||
if (has_theme_font(font_style, "Terminal")) {
|
||||
fontref = get_theme_font(font_style, "Terminal");
|
||||
} else if (has_theme_font_override(font_style)) {
|
||||
fontref = get_theme_font(font_style, "");
|
||||
} else if (has_theme_font("regular", "Terminal")) {
|
||||
fontref = get_theme_font("regular", "Terminal");
|
||||
} else if (default_theme != nullptr &&
|
||||
default_theme->has_font("regular", "Terminal")) {
|
||||
fontref = default_theme->get_font("regular", "Terminal");
|
||||
} else {
|
||||
fontref = get_font("");
|
||||
fontref = get_theme_font("");
|
||||
}
|
||||
|
||||
fontmap.insert(std::pair<String, Ref<Font>>(font_style, fontref));
|
||||
|
@ -523,7 +511,7 @@ void Terminal::draw_foreground(int row, int col, char *ch,
|
|||
const tsm_screen_attr *attr, Color fgcolor) {
|
||||
/* Set the font */
|
||||
|
||||
Ref<Font> fontref = get_font("");
|
||||
Ref<Font> fontref = get_theme_font("");
|
||||
|
||||
if (attr->bold && attr->italic) {
|
||||
fontref = fontmap["bold_italic"];
|
||||
|
@ -543,10 +531,10 @@ void Terminal::draw_foreground(int row, int col, char *ch,
|
|||
int font_height = fontref.ptr()->get_height();
|
||||
Vector2 foreground_pos =
|
||||
Vector2(col * cell_size.x, row * cell_size.y + font_height / 1.25);
|
||||
draw_string(fontref, foreground_pos, ch, fgcolor);
|
||||
draw_string(fontref, foreground_pos, ch, HORIZONTAL_ALIGNMENT_LEFT, -1, 16, fgcolor); // FIXME
|
||||
|
||||
if (attr->underline)
|
||||
draw_string(fontref, foreground_pos, "_", fgcolor);
|
||||
draw_string(fontref, foreground_pos, "_", HORIZONTAL_ALIGNMENT_LEFT, -1, 16, fgcolor); // FIXME
|
||||
}
|
||||
|
||||
std::pair<Color, Color> Terminal::get_cell_colors(const tsm_screen_attr *attr) {
|
||||
|
@ -596,10 +584,10 @@ void Terminal::update_size() {
|
|||
Ref<Font> fontref;
|
||||
if (fontmap.count("regular"))
|
||||
fontref = fontmap["regular"];
|
||||
else if (has_font("regular", "Terminal"))
|
||||
fontref = get_font("regular", "Terminal");
|
||||
else if (has_theme_font("regular", "Terminal"))
|
||||
fontref = get_theme_font("regular", "Terminal");
|
||||
else
|
||||
fontref = get_font("");
|
||||
fontref = get_theme_font("");
|
||||
|
||||
cell_size = fontref->get_string_size("W");
|
||||
|
||||
|
@ -611,43 +599,43 @@ void Terminal::update_size() {
|
|||
emit_signal("size_changed", Vector2(cols, rows));
|
||||
}
|
||||
|
||||
void Terminal::write(PoolByteArray data) {
|
||||
tsm_vte_input(vte, (char *)data.read().ptr(), data.size());
|
||||
void Terminal::write(PackedByteArray data) {
|
||||
tsm_vte_input(vte, (char *)data.ptr(), data.size());
|
||||
}
|
||||
|
||||
void Terminal::sb_up(int num) {
|
||||
tsm_screen_sb_up(screen, num);
|
||||
update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void Terminal::sb_down(int num) {
|
||||
tsm_screen_sb_down(screen, num);
|
||||
update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void Terminal::sb_reset() {
|
||||
tsm_screen_sb_reset(screen);
|
||||
update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void Terminal::clear_sb() {
|
||||
tsm_screen_clear_sb(screen);
|
||||
update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void Terminal::start_selection(Vector2 position) {
|
||||
tsm_screen_selection_start(screen, position.x, position.y);
|
||||
update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void Terminal::select_to_pointer(Vector2 position) {
|
||||
tsm_screen_selection_target(screen, position.x, position.y);
|
||||
update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void Terminal::reset_selection() {
|
||||
tsm_screen_selection_reset(screen);
|
||||
update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
String Terminal::copy_selection() {
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
// Copyright (c) 2021, Leroy Hopson (MIT License).
|
||||
// SPDX-FileCopyrightText: 2021-2022 Leroy Hopson <godot-xterm@leroy.geek.nz>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#ifndef TERMINAL_H
|
||||
#define TERMINAL_H
|
||||
|
||||
#include <Control.hpp>
|
||||
#include <Font.hpp>
|
||||
#include <Godot.hpp>
|
||||
#include <godot_cpp/classes/control.hpp>
|
||||
#include <godot_cpp/classes/font.hpp>
|
||||
#include <godot_cpp/classes/input_event_key.hpp>
|
||||
#include <godot_cpp/variant/packed_byte_array.hpp>
|
||||
#include <libtsm.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
@ -13,12 +15,14 @@
|
|||
namespace godot {
|
||||
|
||||
class Terminal : public Control {
|
||||
GODOT_CLASS(Terminal, Control)
|
||||
GDCLASS(Terminal, Control)
|
||||
|
||||
public:
|
||||
Ref<InputEventKey> input_event_key;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
tsm_screen *screen;
|
||||
tsm_vte *vte;
|
||||
|
||||
|
@ -42,18 +46,15 @@ public:
|
|||
Color fgcol);
|
||||
|
||||
public:
|
||||
static void _register_methods();
|
||||
|
||||
Terminal();
|
||||
~Terminal();
|
||||
|
||||
void _init();
|
||||
void _ready();
|
||||
void _notification(int what);
|
||||
void _gui_input(Variant event);
|
||||
void _draw();
|
||||
|
||||
void write(PoolByteArray data);
|
||||
void write(PackedByteArray data);
|
||||
|
||||
void sb_up(int num);
|
||||
void sb_down(int num);
|
||||
|
@ -72,11 +73,16 @@ public:
|
|||
ALL,
|
||||
ALL_NEXT_FRAME,
|
||||
};
|
||||
int update_mode = UpdateMode::AUTO;
|
||||
int get_update_mode();
|
||||
void set_update_mode(int update_mode);
|
||||
|
||||
Vector2 cell_size;
|
||||
int rows;
|
||||
int cols;
|
||||
int update_mode;
|
||||
Vector2 cell_size = Vector2(0, 0);
|
||||
Vector2 get_cell_size();
|
||||
int rows = 24;
|
||||
int get_rows();
|
||||
int cols = 80;
|
||||
int get_cols();
|
||||
|
||||
uint8_t color_palette[TSM_COLOR_NUM][3];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue