mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-22 01:30:25 +01:00
Basics working, added pseudoterminal
This commit is contained in:
parent
f6bd5a11c8
commit
1187c9b7a3
41 changed files with 1107 additions and 32 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "addons/godot_xterm_native/godot-cpp"]
|
||||
path = addons/godot_xterm_native/godot-cpp
|
||||
url = https://github.com/GodotNativeTools/godot-cpp
|
5
LICENSE
5
LICENSE
|
@ -1,9 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020, The GodotXterm authors (https://github.com/lihop/godot-xterm)
|
||||
Copyright (c) 2017-2019, The xterm.js authors (https://github.com/xtermjs/xterm.js)
|
||||
Copyright (c) 2014-2016, SourceLair Private Company (https://www.sourcelair.com)
|
||||
Copyright (c) 2012-2013, Christopher Jeffrey (https://github.com/chjj/)
|
||||
Copyright (c) 2020 Leroy Hopson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
31
README.md
31
README.md
|
@ -1,38 +1,17 @@
|
|||
<img align="left" width="64" height="64" src="icon.png">
|
||||
|
||||
# GodotXterm
|
||||
# Godot Xterm Native
|
||||
|
||||
[![Build Status](https://travis-ci.org/lihop/godot-xterm.svg?branch=master)](https://travis-ci.org/lihop/godot-xterm)
|
||||
![Version](https://img.shields.io/badge/version-0.1.0-orange.svg)
|
||||
![Godot Version](https://img.shields.io/badge/godot-3.2+-blue.svg)
|
||||
![License](https://img.shields.io/badge/license-MIT-green.svg)
|
||||
|
||||
|
||||
**NOTE: The GDScript version of this project turned out to be very buggy and performed poorly. I have had much more success with a gdnative implementation using [libtsm](https://github.com/Aetf/libtsm) which can be viewed in the [native branch](https://github.com/lihop/godot-xterm/tree/native) of this repo.**
|
||||
|
||||
Xterm for Godot. This is still very much a work in progress.
|
||||
Most of the credit goes to the authors of [xterm.js](https://github.com/xtermjs/xterm.js) as most of this code was taken from that project and translated to GDScript.
|
||||
|
||||
## Demo
|
||||
|
||||
If you are running Linux and have `which`, `bash` and `socat` installed you can run the main scene (`demo.tscn`) and it will try
|
||||
to connect the Terminal node to your system.
|
||||
|
||||
Otherwise you can check out the gif below:
|
||||
|
||||
<img src="demo.gif">
|
||||
|
||||
## Testing
|
||||
|
||||
This project uses the awesome [Gut](https://github.com/bitwes/Gut) (Godot Unit Testing) plugin for testing.
|
||||
You can run the tests by playing the test scene at `res://test/test.tscn` and clicking run.
|
||||
|
||||
## License
|
||||
|
||||
If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license.
|
||||
You are also implicitly verifying that all code is your original work, or unoriginal work which is published under a compatible license or waiver.
|
||||
|
||||
Copyright (c) 2020, [The GodotXterm authors](https://github.com/lihop/godot-xterm/graphs/contributors) (MIT License)<br>
|
||||
Copyright (c) 2017-2019, [The xterm.js authors](https://github.com/xtermjs/xterm.js/graphs/contributors) (MIT License)<br>
|
||||
Copyright (c) 2014-2017, SourceLair, Private Company ([www.sourcelair.com](https://www.sourcelair.com/home)) (MIT License)<br>
|
||||
Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
|
||||
Copyright (c) 2020 Leroy Hopson (MIT License)
|
||||
|
||||
The fonts used in this project are published under a seperate license.
|
||||
See: [addons/godot_xterm_native/fonts/LICENSE](addons/godot_xterm_native/fonts/LICENSE).
|
||||
|
|
BIN
addons/godot_xterm_native/.sconsign.dblite
Normal file
BIN
addons/godot_xterm_native/.sconsign.dblite
Normal file
Binary file not shown.
14
addons/godot_xterm_native/.vscode/c_cpp_properties.json
vendored
Normal file
14
addons/godot_xterm_native/.vscode/c_cpp_properties.json
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": ["${workspaceFolder}/**"],
|
||||
"defines": [],
|
||||
"compilerPath": "/nix/store/l2sqva7kzr8y68lji2aajk2s8017jyq4-gcc-wrapper-8.3.0/bin/gcc",
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "clang-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
1
addons/godot_xterm_native/.vscode/include/vterm.h
vendored
Symbolic link
1
addons/godot_xterm_native/.vscode/include/vterm.h
vendored
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/c4l4iva7dm7fpfx8y3jb6hdzlsm1cvmj-libvterm-neovim-0.1.3/include/vterm.h
|
1
addons/godot_xterm_native/.vscode/include/vterm_keycodes.h
vendored
Symbolic link
1
addons/godot_xterm_native/.vscode/include/vterm_keycodes.h
vendored
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/c4l4iva7dm7fpfx8y3jb6hdzlsm1cvmj-libvterm-neovim-0.1.3/include/vterm_keycodes.h
|
50
addons/godot_xterm_native/.vscode/settings.json
vendored
Normal file
50
addons/godot_xterm_native/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"fstream": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"filesystem": "cpp"
|
||||
},
|
||||
"nixEnvSelector.nixShellConfig": "${workspaceRoot}/default.nix"
|
||||
}
|
16
addons/godot_xterm_native/.vscode/tasks.json
vendored
Normal file
16
addons/godot_xterm_native/.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "echo",
|
||||
"type": "shell",
|
||||
"command": "nix-shell --run 'scons platform=linux -j12'",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
1
addons/godot_xterm_native/LICENSE
Symbolic link
1
addons/godot_xterm_native/LICENSE
Symbolic link
|
@ -0,0 +1 @@
|
|||
LICENSE
|
115
addons/godot_xterm_native/SConstruct
Normal file
115
addons/godot_xterm_native/SConstruct
Normal file
|
@ -0,0 +1,115 @@
|
|||
#!python
|
||||
import os, subprocess
|
||||
|
||||
opts = Variables([], ARGUMENTS)
|
||||
|
||||
# Gets the standard flags CC, CCX, etc.
|
||||
env = DefaultEnvironment()
|
||||
|
||||
# Define our options
|
||||
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release']))
|
||||
opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx']))
|
||||
opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx']))
|
||||
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
|
||||
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/'))
|
||||
opts.Add(PathVariable('target_name', 'The library name.', 'libgodotxtermnative', PathVariable.PathAccept))
|
||||
|
||||
# Local dependency paths, adapt them to your setup
|
||||
godot_headers_path = "godot-cpp/godot_headers/"
|
||||
cpp_bindings_path = "godot-cpp/"
|
||||
cpp_library = "libgodot-cpp"
|
||||
|
||||
# only support 64 at this time..
|
||||
bits = 64
|
||||
|
||||
# Updates the environment with the option variables.
|
||||
opts.Update(env)
|
||||
|
||||
# Process some arguments
|
||||
if env['use_llvm']:
|
||||
env['CC'] = 'clang'
|
||||
env['CXX'] = 'clang++'
|
||||
else:
|
||||
env['CC'] = '/home/leroy/.nix-profile/bin/gcc'
|
||||
env['CXX'] = '/home/leroy/.nix-profile/bin/g++'
|
||||
|
||||
if env['p'] != '':
|
||||
env['platform'] = env['p']
|
||||
|
||||
if env['platform'] == '':
|
||||
print("No valid target platform selected.")
|
||||
quit();
|
||||
|
||||
# For the reference:
|
||||
# - CCFLAGS are compilation flags shared between C and C++
|
||||
# - CFLAGS are for C-specific compilation flags
|
||||
# - CXXFLAGS are for C++-specific compilation flags
|
||||
# - CPPFLAGS are for pre-processor flags
|
||||
# - CPPDEFINES are for pre-processor defines
|
||||
# - LINKFLAGS are for linking flags
|
||||
|
||||
# Check our platform specifics
|
||||
if env['platform'] == "osx":
|
||||
env['target_path'] += 'osx/'
|
||||
cpp_library += '.osx'
|
||||
env.Append(CCFLAGS=['-arch', 'x86_64'])
|
||||
env.Append(CXXFLAGS=['-std=c++17'])
|
||||
env.Append(LINKFLAGS=['-arch', 'x86_64'])
|
||||
if env['target'] in ('debug', 'd'):
|
||||
env.Append(CCFLAGS=['-g', '-O2'])
|
||||
else:
|
||||
env.Append(CCFLAGS=['-g', '-O3'])
|
||||
|
||||
elif env['platform'] in ('x11', 'linux'):
|
||||
env['target_path'] += 'x11/'
|
||||
cpp_library += '.linux'
|
||||
env.Append(CCFLAGS=['-fPIC', '-shared'])
|
||||
env.Append(CCFLAGS=os.environ['NIX_CFLAGS_COMPILE'])
|
||||
env.Append(CXXFLAGS=['-std=c++17', '-shared', '-pthread'])
|
||||
if env['target'] in ('debug', 'd'):
|
||||
env.Append(CCFLAGS=['-g3', '-Og'])
|
||||
else:
|
||||
env.Append(CCFLAGS=['-g', '-O3'])
|
||||
|
||||
elif env['platform'] == "windows":
|
||||
env['target_path'] += 'win64/'
|
||||
cpp_library += '.windows'
|
||||
# This makes sure to keep the session environment variables on windows,
|
||||
# that way you can run scons in a vs 2017 prompt and it will find all the required tools
|
||||
env.Append(ENV=os.environ)
|
||||
|
||||
env.Append(CPPDEFINES=['WIN32', '_WIN32', '_WINDOWS', '_CRT_SECURE_NO_WARNINGS'])
|
||||
env.Append(CCFLAGS=['-W3', '-GR'])
|
||||
if env['target'] in ('debug', 'd'):
|
||||
env.Append(CPPDEFINES=['_DEBUG'])
|
||||
env.Append(CCFLAGS=['-EHsc', '-MDd', '-ZI'])
|
||||
env.Append(LINKFLAGS=['-DEBUG'])
|
||||
else:
|
||||
env.Append(CPPDEFINES=['NDEBUG'])
|
||||
env.Append(CCFLAGS=['-O2', '-EHsc', '-MD'])
|
||||
|
||||
if env['target'] in ('debug', 'd'):
|
||||
cpp_library += '.debug'
|
||||
else:
|
||||
cpp_library += '.release'
|
||||
|
||||
cpp_library += '.' + str(bits)
|
||||
|
||||
# make sure our binding library is properly includes
|
||||
env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
|
||||
env.Append(LIBPATH=[cpp_bindings_path + 'bin/'] + os.environ['LD_LIBRARY_PATH'].split(':'))
|
||||
env.Append(LIBS=[cpp_library, 'tsm'])
|
||||
|
||||
# tweak this if you want to use different folders, or more folders, to store your source code in.
|
||||
env.Append(CPPPATH=['src/'])
|
||||
sources = []
|
||||
sources.append(Glob('src/*.c'))
|
||||
sources.append(Glob('src/*.cpp'))
|
||||
|
||||
|
||||
library = env.SharedLibrary(target=env['target_path'] + env['target_name'] , source=sources)
|
||||
|
||||
Default(library)
|
||||
|
||||
# Generates help for the -h scons option.
|
||||
Help(opts.GenerateHelpText(env))
|
BIN
addons/godot_xterm_native/bin/x11/libgodotxtermnative.so
Executable file
BIN
addons/godot_xterm_native/bin/x11/libgodotxtermnative.so
Executable file
Binary file not shown.
20
addons/godot_xterm_native/default.nix
Normal file
20
addons/godot_xterm_native/default.nix
Normal file
|
@ -0,0 +1,20 @@
|
|||
with import /home/leroy/nixpkgs { overlays = [ (import ./overlay.nix) ]; };
|
||||
stdenv.mkDerivation rec {
|
||||
name = "systemnauts";
|
||||
|
||||
buildInputs = [
|
||||
gcc
|
||||
scons
|
||||
libaudit
|
||||
libvterm
|
||||
libtsm
|
||||
];
|
||||
|
||||
enablePrallelBuilding = true;
|
||||
|
||||
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
|
||||
libaudit
|
||||
libvterm
|
||||
libtsm
|
||||
];
|
||||
}
|
BIN
addons/godot_xterm_native/fonts/Cousine-Bold.ttf
Normal file
BIN
addons/godot_xterm_native/fonts/Cousine-Bold.ttf
Normal file
Binary file not shown.
BIN
addons/godot_xterm_native/fonts/Cousine-BoldItalic.ttf
Normal file
BIN
addons/godot_xterm_native/fonts/Cousine-BoldItalic.ttf
Normal file
Binary file not shown.
BIN
addons/godot_xterm_native/fonts/Cousine-Italic.ttf
Normal file
BIN
addons/godot_xterm_native/fonts/Cousine-Italic.ttf
Normal file
Binary file not shown.
BIN
addons/godot_xterm_native/fonts/Cousine-Regular.ttf
Normal file
BIN
addons/godot_xterm_native/fonts/Cousine-Regular.ttf
Normal file
Binary file not shown.
202
addons/godot_xterm_native/fonts/LICENSE.txt
Normal file
202
addons/godot_xterm_native/fonts/LICENSE.txt
Normal file
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
1
addons/godot_xterm_native/godot-cpp
Submodule
1
addons/godot_xterm_native/godot-cpp
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 9eceb16f0553884094d0f659461649be5d333866
|
16
addons/godot_xterm_native/godotxtermnative.gdnlib
Normal file
16
addons/godot_xterm_native/godotxtermnative.gdnlib
Normal file
|
@ -0,0 +1,16 @@
|
|||
[general]
|
||||
|
||||
singleton=false
|
||||
load_once=true
|
||||
symbol_prefix="godot_"
|
||||
reloadable=true
|
||||
|
||||
[entry]
|
||||
|
||||
X11.64="res://addons/godot_xterm_native/bin/x11/libgodotxtermnative.so"
|
||||
Server.64="res://addons/godot_xterm_native/bin/x11/libgodotxtermnative.so"
|
||||
|
||||
[dependencies]
|
||||
|
||||
X11.64=[ ]
|
||||
Server.64=[ ]
|
19
addons/godot_xterm_native/overlay.nix
Normal file
19
addons/godot_xterm_native/overlay.nix
Normal file
|
@ -0,0 +1,19 @@
|
|||
self: super:
|
||||
{
|
||||
libtsm = super.libtsm.overrideAttrs (oldAttrs: {
|
||||
src = super.fetchFromGitHub {
|
||||
owner = "Aetf";
|
||||
repo = "libtsm";
|
||||
rev = "a5a9ea0c23b28aa2c9cf889105b75981fdebbc25";
|
||||
sha256 = "0hqb0fjh5cwr2309sy2626ghhbnx7g64s8f3qqyvk7j8aysxgggh";
|
||||
};
|
||||
|
||||
nativeBuildInputs = with super; [ cmake gtk3 cairo pango libxkbcommon pkgconfig ];
|
||||
|
||||
dontDisableStatic = true;
|
||||
});
|
||||
|
||||
libaudit = super.libaudit.overrideAttrs (oldAttrs: { dontDisableStatic = true; });
|
||||
|
||||
libvterm = super.libvterm-neovim.overrideAttrs (oldAttrs: { dontDisableStatic = true; });
|
||||
}
|
|
@ -3,8 +3,15 @@ extends EditorPlugin
|
|||
|
||||
|
||||
func _enter_tree():
|
||||
pass
|
||||
var terminal_script = preload("res://addons/godot_xterm_native/terminal.gdns")
|
||||
var terminal_icon = preload("res://addons/godot_xterm_native/terminal_icon.svg")
|
||||
add_custom_type("Terminal", "Control", terminal_script, terminal_icon)
|
||||
|
||||
var pseudoterminal_script = preload("res://addons/godot_xterm_native/pseudoterminal.gdns")
|
||||
var pseudoterminal_icon = preload("res://addons/godot_xterm_native/pseudoterminal_icon.svg")
|
||||
add_custom_type("Pseudoterminal", "Node", pseudoterminal_script, pseudoterminal_icon)
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
pass
|
||||
remove_custom_type("Terminal")
|
||||
remove_custom_type("Psuedoterminal")
|
||||
|
|
8
addons/godot_xterm_native/pseudoterminal.gdns
Normal file
8
addons/godot_xterm_native/pseudoterminal.gdns
Normal file
|
@ -0,0 +1,8 @@
|
|||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_xterm_native/godotxtermnative.gdnlib" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
resource_name = "Terminal"
|
||||
class_name = "Pseudoterminal"
|
||||
library = ExtResource( 1 )
|
51
addons/godot_xterm_native/pseudoterminal_icon.svg
Normal file
51
addons/godot_xterm_native/pseudoterminal_icon.svg
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
id="svg4716"
|
||||
version="1.1"
|
||||
width="16"
|
||||
viewBox="0 0 16 16"
|
||||
height="16">
|
||||
<metadata
|
||||
id="metadata4722">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs
|
||||
id="defs4720">
|
||||
<clipPath
|
||||
id="clipPath826"
|
||||
clipPathUnits="userSpaceOnUse">
|
||||
<use
|
||||
height="100%"
|
||||
width="100%"
|
||||
id="use828"
|
||||
xlink:href="#g822"
|
||||
y="0"
|
||||
x="0" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
<g
|
||||
clip-path="url(#clipPath826)"
|
||||
id="g824">
|
||||
<g
|
||||
id="g822">
|
||||
<path
|
||||
style="fill:#e0e0e0;fill-opacity:0.99607999"
|
||||
d="M 4,1 1,5 H 3 V 8 H 5 V 5 h 2 z m 7,0 V 4 H 9 l 3,4 3,-4 H 13 V 1 Z m -2,9 v 1 h 1 v 4 h 1 v -4 h 1 v -1 z m -4,0 v 2 1 2 H 6 V 13 H 7 8 V 12 10 H 6 Z m 1,1 h 1 v 1 H 6 Z"
|
||||
id="path4714" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.3 KiB |
34
addons/godot_xterm_native/pseudoterminal_icon.svg.import
Normal file
34
addons/godot_xterm_native/pseudoterminal_icon.svg.import
Normal file
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/pseudoterminal_icon.svg-11c935c96560f4f752005a829ae0b2b7.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/godot_xterm_native/pseudoterminal_icon.svg"
|
||||
dest_files=[ "res://.import/pseudoterminal_icon.svg-11c935c96560f4f752005a829ae0b2b7.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
21
addons/godot_xterm_native/src/libgodotxtermnative.cpp
Normal file
21
addons/godot_xterm_native/src/libgodotxtermnative.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "terminal.h"
|
||||
#include "pseudoterminal.h"
|
||||
|
||||
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o)
|
||||
{
|
||||
godot::Godot::gdnative_init(o);
|
||||
}
|
||||
|
||||
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o)
|
||||
{
|
||||
godot::Godot::gdnative_terminate(o);
|
||||
}
|
||||
|
||||
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
|
||||
{
|
||||
godot::Godot::nativescript_init(handle);
|
||||
|
||||
godot::register_class<godot::Terminal>();
|
||||
|
||||
godot::register_class<godot::Pseudoterminal>();
|
||||
}
|
BIN
addons/godot_xterm_native/src/libgodotxtermnative.os
Normal file
BIN
addons/godot_xterm_native/src/libgodotxtermnative.os
Normal file
Binary file not shown.
34
addons/godot_xterm_native/src/pseudoterminal.cpp
Normal file
34
addons/godot_xterm_native/src/pseudoterminal.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include "pseudoterminal.h"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void Pseudoterminal::_register_methods()
|
||||
{
|
||||
|
||||
register_method("_init", &Pseudoterminal::_init);
|
||||
register_method("_ready", &Pseudoterminal::_ready);
|
||||
|
||||
register_method("put_data", &Pseudoterminal::put_data);
|
||||
|
||||
register_signal<Pseudoterminal>((char *)"data_received", "data", GODOT_VARIANT_TYPE_POOL_BYTE_ARRAY);
|
||||
}
|
||||
|
||||
Pseudoterminal::Pseudoterminal()
|
||||
{
|
||||
}
|
||||
|
||||
Pseudoterminal::~Pseudoterminal()
|
||||
{
|
||||
}
|
||||
|
||||
void Pseudoterminal::_init()
|
||||
{
|
||||
}
|
||||
|
||||
void Pseudoterminal::_ready()
|
||||
{
|
||||
}
|
||||
|
||||
void Pseudoterminal::put_data(PoolByteArray data)
|
||||
{
|
||||
}
|
27
addons/godot_xterm_native/src/pseudoterminal.h
Normal file
27
addons/godot_xterm_native/src/pseudoterminal.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef PSEUDOTERMINAL_H
|
||||
#define PSEUDOTERMINAL_H
|
||||
|
||||
#include <Godot.hpp>
|
||||
#include <Node.hpp>
|
||||
|
||||
namespace godot
|
||||
{
|
||||
|
||||
class Pseudoterminal : public Node
|
||||
{
|
||||
GODOT_CLASS(Pseudoterminal, Node)
|
||||
|
||||
public:
|
||||
static void _register_methods();
|
||||
|
||||
Pseudoterminal();
|
||||
~Pseudoterminal();
|
||||
|
||||
void _init();
|
||||
void _ready();
|
||||
|
||||
void put_data(PoolByteArray data);
|
||||
};
|
||||
} // namespace godot
|
||||
|
||||
#endif // PSEUDOTERMINAL_H
|
BIN
addons/godot_xterm_native/src/pseudoterminal.os
Normal file
BIN
addons/godot_xterm_native/src/pseudoterminal.os
Normal file
Binary file not shown.
290
addons/godot_xterm_native/src/terminal.cpp
Normal file
290
addons/godot_xterm_native/src/terminal.cpp
Normal file
|
@ -0,0 +1,290 @@
|
|||
#include "terminal.h"
|
||||
#include <Theme.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
// Use xterm default for default color palette.
|
||||
const uint8_t Terminal::default_color_palette[TSM_COLOR_NUM][3] = {
|
||||
[TSM_COLOR_BLACK] = { 0x00, 0x00, 0x00 },
|
||||
[TSM_COLOR_RED] = { 0x80, 0x00, 0x00 },
|
||||
[TSM_COLOR_GREEN] = { 0x00, 0x80, 0x00 },
|
||||
[TSM_COLOR_YELLOW] = { 0x80, 0x80, 0x00 },
|
||||
[TSM_COLOR_BLUE] = { 0x00, 0x00, 0x80 },
|
||||
[TSM_COLOR_MAGENTA] = { 0x80, 0x00, 0x80 },
|
||||
[TSM_COLOR_CYAN] = { 0x00, 0x80, 0x80 },
|
||||
[TSM_COLOR_LIGHT_GREY] = { 0xc0, 0xc0, 0xc0 },
|
||||
[TSM_COLOR_DARK_GREY] = { 0x80, 0x80, 0x80 },
|
||||
[TSM_COLOR_LIGHT_RED] = { 0xff, 0x00, 0x00 },
|
||||
[TSM_COLOR_LIGHT_GREEN] = { 0x00, 0xff, 0x00 },
|
||||
[TSM_COLOR_LIGHT_YELLOW] = { 0xff, 0xff, 0x00 },
|
||||
[TSM_COLOR_LIGHT_BLUE] = { 0x00, 0x00, 0xff },
|
||||
[TSM_COLOR_LIGHT_MAGENTA] = { 0xff, 0x00, 0xff },
|
||||
[TSM_COLOR_LIGHT_CYAN] = { 0x00, 0xff, 0xff },
|
||||
[TSM_COLOR_WHITE] = { 0xff, 0xff, 0xff },
|
||||
|
||||
[TSM_COLOR_FOREGROUND] = { 0xff, 0xff, 0xff },
|
||||
[TSM_COLOR_BACKGROUND] = { 0x00, 0x00, 0x00 },
|
||||
};
|
||||
|
||||
static struct {
|
||||
Color col;
|
||||
bool is_set;
|
||||
} colours[16];
|
||||
|
||||
static void term_output(const char *s, size_t len, void *user) {
|
||||
}
|
||||
|
||||
static void write_cb(struct tsm_vte *vte, const char *u8, size_t len, void *data) {
|
||||
|
||||
Terminal *term = static_cast<Terminal *>(data);
|
||||
}
|
||||
|
||||
static int text_draw_cb(struct tsm_screen *con,
|
||||
uint64_t id,
|
||||
const uint32_t *ch,
|
||||
size_t len,
|
||||
unsigned int width,
|
||||
unsigned int posx,
|
||||
unsigned int posy,
|
||||
const struct tsm_screen_attr *attr,
|
||||
tsm_age_t age,
|
||||
void *data) {
|
||||
|
||||
Terminal *terminal = static_cast<Terminal *>(data);
|
||||
|
||||
if (age <= terminal->framebuffer_age)
|
||||
return 0;
|
||||
|
||||
size_t ulen;
|
||||
char buf[5] = { 0 };
|
||||
|
||||
if (len > 0) {
|
||||
char *utf8 = tsm_ucs4_to_utf8_alloc(ch, len, &ulen);
|
||||
memcpy(terminal->cells[posy][posx].ch, utf8, ulen);
|
||||
} else {
|
||||
terminal->cells[posy][posx] = {};
|
||||
}
|
||||
|
||||
memcpy(&terminal->cells[posy][posx].attr, attr, sizeof(tsm_screen_attr));
|
||||
|
||||
terminal->update();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Terminal::_register_methods() {
|
||||
|
||||
register_method("_init", &Terminal::_init);
|
||||
register_method("_ready", &Terminal::_ready);
|
||||
register_method("_input", &Terminal::_input);
|
||||
register_method("_draw", &Terminal::_draw);
|
||||
|
||||
register_method("write", &Terminal::write);
|
||||
|
||||
register_property<Terminal, int>("rows", &Terminal::rows, 24);
|
||||
register_property<Terminal, int>("cols", &Terminal::cols, 80);
|
||||
}
|
||||
|
||||
Terminal::Terminal() {
|
||||
}
|
||||
|
||||
Terminal::~Terminal() {
|
||||
}
|
||||
|
||||
void Terminal::_init() {
|
||||
|
||||
rows = 24;
|
||||
cols = 80;
|
||||
|
||||
for (int x = 0; x < rows; x++) {
|
||||
Row row(cols);
|
||||
|
||||
for (int y = 0; y < cols; y++) {
|
||||
row[y] = empty_cell;
|
||||
}
|
||||
|
||||
cells.push_back(row);
|
||||
}
|
||||
|
||||
cell_size = Vector2(12, 21); // TODO: Get proper cell_size based on font.
|
||||
|
||||
sleep = false;
|
||||
|
||||
int ret;
|
||||
|
||||
if (tsm_screen_new(&screen, NULL, NULL)) {
|
||||
ERR_PRINT("Error creating new tsm screen");
|
||||
}
|
||||
tsm_screen_set_max_sb(screen, 1000); // TODO: Use config var for scrollback size.
|
||||
|
||||
if (tsm_vte_new(&vte, screen, write_cb, this, NULL, NULL)) {
|
||||
ERR_PRINT("Error creating new tsm vte");
|
||||
}
|
||||
|
||||
/* Set the color palette */
|
||||
update_color_palette();
|
||||
if (tsm_vte_set_custom_palette(vte, color_palette)) {
|
||||
ERR_PRINT("Error setting custom palette");
|
||||
}
|
||||
if (tsm_vte_set_palette(vte, "custom")) {
|
||||
ERR_PRINT("Error setting palette");
|
||||
}
|
||||
}
|
||||
|
||||
void Terminal::_ready() {
|
||||
}
|
||||
|
||||
void Terminal::_input(Variant event) {
|
||||
}
|
||||
|
||||
void Terminal::_draw() {
|
||||
|
||||
if (sleep)
|
||||
return;
|
||||
|
||||
/* Draw the background */
|
||||
|
||||
// Draw the background first so subsequent rows don't overlap
|
||||
// foreground characters such as y that may extend below the baseline.
|
||||
for (int row = 0; row < rows; row++) {
|
||||
for (int col = 0; col < cols; col++) {
|
||||
draw_background(row, col, get_cell_colors(row, col).first);
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw the foreground */
|
||||
|
||||
for (int row = 0; row < rows; row++) {
|
||||
for (int col = 0; col < cols; col++) {
|
||||
draw_foreground(row, col, get_cell_colors(row, col).second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Terminal::update_color_palette() {
|
||||
|
||||
// Start with a copy of the default color palette
|
||||
memcpy(color_palette, Terminal::default_color_palette, sizeof(Terminal::default_color_palette));
|
||||
|
||||
/* Generate color palette based on theme */
|
||||
|
||||
// Converts a color from the Control's theme to one that can
|
||||
// be used in a tsm color palette.
|
||||
auto set_pallete_color = [this](tsm_vte_color color, String theme_color) -> void {
|
||||
Color c = get_color(theme_color, "Terminal");
|
||||
uint32_t argb32 = c.to_ARGB32();
|
||||
|
||||
color_palette[color][0] = (argb32 >> (8 * 0)) & 0xff;
|
||||
color_palette[color][1] = (argb32 >> (8 * 1)) & 0xff;
|
||||
color_palette[color][2] = (argb32 >> (8 * 2)) & 0xff;
|
||||
};
|
||||
|
||||
set_pallete_color(TSM_COLOR_BLACK, "Black");
|
||||
set_pallete_color(TSM_COLOR_RED, "Red");
|
||||
set_pallete_color(TSM_COLOR_GREEN, "Green");
|
||||
set_pallete_color(TSM_COLOR_YELLOW, "Yellow");
|
||||
set_pallete_color(TSM_COLOR_BLUE, "Blue");
|
||||
set_pallete_color(TSM_COLOR_MAGENTA, "Magenta");
|
||||
set_pallete_color(TSM_COLOR_CYAN, "Cyan");
|
||||
set_pallete_color(TSM_COLOR_LIGHT_GREY, "Light Grey");
|
||||
set_pallete_color(TSM_COLOR_DARK_GREY, "Dark Grey");
|
||||
set_pallete_color(TSM_COLOR_LIGHT_RED, "Light Red");
|
||||
set_pallete_color(TSM_COLOR_LIGHT_GREEN, "Light Green");
|
||||
set_pallete_color(TSM_COLOR_LIGHT_YELLOW, "Light Yellow");
|
||||
set_pallete_color(TSM_COLOR_LIGHT_BLUE, "Light Blue");
|
||||
set_pallete_color(TSM_COLOR_LIGHT_MAGENTA, "Light Magenta");
|
||||
set_pallete_color(TSM_COLOR_WHITE, "White");
|
||||
|
||||
set_pallete_color(TSM_COLOR_BACKGROUND, "Background");
|
||||
set_pallete_color(TSM_COLOR_FOREGROUND, "Foreground");
|
||||
}
|
||||
|
||||
void Terminal::draw_background(int row, int col, Color bgcolor) {
|
||||
|
||||
/* Draw the background */
|
||||
Vector2 background_pos = Vector2(col * cell_size.x, row * cell_size.y);
|
||||
Rect2 background_rect = Rect2(background_pos, cell_size);
|
||||
draw_rect(background_rect, bgcolor);
|
||||
}
|
||||
|
||||
void Terminal::draw_foreground(int row, int col, Color fgcolor) {
|
||||
|
||||
struct cell cell = cells[row][col];
|
||||
|
||||
/* Set the font */
|
||||
|
||||
Ref<Font> fontref = get_font("");
|
||||
|
||||
if (cell.attr.bold && cell.attr.italic) {
|
||||
fontref = get_font("Bold Italic", "Terminal");
|
||||
} else if (cell.attr.bold) {
|
||||
fontref = get_font("Bold", "Terminal");
|
||||
} else if (cell.attr.italic) {
|
||||
fontref = get_font("Italic", "Terminal");
|
||||
} else {
|
||||
fontref = get_font("Regular", "Terminal");
|
||||
}
|
||||
|
||||
/* Draw the foreground */
|
||||
|
||||
if (cell.ch == nullptr)
|
||||
return; // No foreground to draw
|
||||
|
||||
if (cell.attr.blink)
|
||||
; // TODO: Handle blink
|
||||
|
||||
int font_height = fontref.ptr()->get_height();
|
||||
Vector2 foreground_pos = Vector2(col * cell_size.x, row * cell_size.y + font_height);
|
||||
draw_string(fontref, foreground_pos, cell.ch, fgcolor);
|
||||
|
||||
if (cell.attr.underline)
|
||||
draw_string(fontref, foreground_pos, "_", fgcolor);
|
||||
}
|
||||
|
||||
std::pair<Color, Color> Terminal::get_cell_colors(int row, int col) {
|
||||
struct cell cell = cells[row][col];
|
||||
Color fgcol, bgcol;
|
||||
float fr = 1, fg = 1, fb = 1, br = 0, bg = 0, bb = 0;
|
||||
Ref<Font> fontref = get_font("");
|
||||
|
||||
/* Get foreground color */
|
||||
|
||||
if (cell.attr.fccode && palette.count(cell.attr.fccode)) {
|
||||
fgcol = palette[cell.attr.fccode];
|
||||
} else {
|
||||
fr = (float)cell.attr.fr / 255.0;
|
||||
fg = (float)cell.attr.fg / 255.0;
|
||||
fb = (float)cell.attr.fb / 255.0;
|
||||
fgcol = Color(fr, fg, fb);
|
||||
|
||||
if (cell.attr.fccode) {
|
||||
palette.insert(std::pair<int, Color>(cell.attr.fccode, Color(fr, fg, fb)));
|
||||
}
|
||||
}
|
||||
|
||||
/* Get background color */
|
||||
|
||||
if (cell.attr.bccode && palette.count(cell.attr.bccode)) {
|
||||
bgcol = palette[cell.attr.bccode];
|
||||
} else {
|
||||
br = (float)cell.attr.br / 255.0;
|
||||
bg = (float)cell.attr.bg / 255.0;
|
||||
bb = (float)cell.attr.bb / 255.0;
|
||||
bgcol = Color(br, bg, bb);
|
||||
|
||||
if (cell.attr.bccode) {
|
||||
palette.insert(std::pair<int, Color>(cell.attr.bccode, Color(br, bg, bb)));
|
||||
}
|
||||
}
|
||||
|
||||
if (cell.attr.inverse)
|
||||
std::swap(bgcol, fgcol);
|
||||
|
||||
return std::make_pair(bgcol, fgcol);
|
||||
}
|
||||
|
||||
void Terminal::write(PoolByteArray data) {
|
||||
|
||||
tsm_vte_input(vte, (char *)data.read().ptr(), data.size());
|
||||
framebuffer_age = tsm_screen_draw(screen, text_draw_cb, this);
|
||||
}
|
67
addons/godot_xterm_native/src/terminal.h
Normal file
67
addons/godot_xterm_native/src/terminal.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
#ifndef TERMINAL_H
|
||||
#define TERMINAL_H
|
||||
|
||||
#include <libtsm.h>
|
||||
#include <Control.hpp>
|
||||
#include <Font.hpp>
|
||||
#include <Godot.hpp>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Terminal : public Control {
|
||||
GODOT_CLASS(Terminal, Control)
|
||||
|
||||
public:
|
||||
struct cell {
|
||||
char ch[5];
|
||||
struct tsm_screen_attr attr;
|
||||
} empty_cell = { ch : { 0, 0, 0, 0, 0 }, attr : {} };
|
||||
|
||||
public:
|
||||
typedef std::vector<std::vector<struct cell> > Cells;
|
||||
typedef std::vector<struct cell> Row;
|
||||
|
||||
Cells cells;
|
||||
|
||||
protected:
|
||||
tsm_screen *screen;
|
||||
tsm_vte *vte;
|
||||
|
||||
private:
|
||||
static const uint8_t default_color_palette[TSM_COLOR_NUM][3];
|
||||
|
||||
Vector2 cell_size;
|
||||
std::map<int, Color> palette = {};
|
||||
|
||||
void update_color_palette();
|
||||
std::pair<Color, Color> get_cell_colors(int row, int col);
|
||||
void draw_background(int row, int col, Color bgcol);
|
||||
void draw_foreground(int row, int col, Color fgcol);
|
||||
|
||||
public:
|
||||
static void _register_methods();
|
||||
|
||||
Terminal();
|
||||
~Terminal();
|
||||
|
||||
void _init();
|
||||
void _ready();
|
||||
void _input(Variant event);
|
||||
void _draw();
|
||||
|
||||
void write(PoolByteArray bytes);
|
||||
|
||||
int rows;
|
||||
int cols;
|
||||
|
||||
bool sleep;
|
||||
|
||||
uint8_t color_palette[TSM_COLOR_NUM][3];
|
||||
|
||||
tsm_age_t framebuffer_age;
|
||||
};
|
||||
} // namespace godot
|
||||
|
||||
#endif // TERMINAL_H
|
BIN
addons/godot_xterm_native/src/terminal.os
Normal file
BIN
addons/godot_xterm_native/src/terminal.os
Normal file
Binary file not shown.
8
addons/godot_xterm_native/terminal.gdns
Normal file
8
addons/godot_xterm_native/terminal.gdns
Normal file
|
@ -0,0 +1,8 @@
|
|||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_xterm_native/godotxtermnative.gdnlib" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
resource_name = "Terminal"
|
||||
class_name = "Terminal"
|
||||
library = ExtResource( 1 )
|
14
addons/godot_xterm_native/terminal_icon.svg
Normal file
14
addons/godot_xterm_native/terminal_icon.svg
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<metadata>
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
|
||||
<dc:title/>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<path d="m4.5605 3.9746c-0.074558 0-0.14819 0.029049-0.20508 0.085938l-0.27539 0.27539c-0.11354 0.11358-0.11332 0.29631 0 0.41016l1.8691 1.8789-1.8691 1.8789c-0.11336 0.11385-0.11358 0.29657 0 0.41016l0.27539 0.27539c0.11377 0.11378 0.29833 0.11378 0.41211 0l2.3594-2.3594c0.11378-0.11378 0.11378-0.29834 0-0.41211l-2.3594-2.3574c-0.056882-0.056888-0.13247-0.085938-0.20703-0.085938zm3.2207 4.3984c-0.1609 0-0.29102 0.13012-0.29102 0.29102v0.38867c0 0.1609 0.13012 0.29102 0.29102 0.29102h3.6914c0.1609 0 0.29102-0.13012 0.29102-0.29102v-0.38867c0-0.1609-0.13012-0.29102-0.29102-0.29102z" fill="#a5efac" stroke-width=".012139"/>
|
||||
<path d="m3 1c-1.1046 0-2 0.8954-2 2v10c0 1.1046 0.89543 2 2 2h10c1.1046 0 2-0.8954 2-2v-10c0-1.1046-0.89543-2-2-2zm0 2h10v10h-10z" fill="#a5efac"/>
|
||||
</svg>
|
After Width: | Height: | Size: 1.3 KiB |
34
addons/godot_xterm_native/terminal_icon.svg.import
Normal file
34
addons/godot_xterm_native/terminal_icon.svg.import
Normal file
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/terminal_icon.svg-ab79ba4c14608847c16f36c424b01cf4.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/godot_xterm_native/terminal_icon.svg"
|
||||
dest_files=[ "res://.import/terminal_icon.svg-ab79ba4c14608847c16f36c424b01cf4.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
BIN
addons/godot_xterm_native/themes/default.theme
Normal file
BIN
addons/godot_xterm_native/themes/default.theme
Normal file
Binary file not shown.
|
@ -1,5 +1,7 @@
|
|||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
|
|
24
examples/terminal/Terminal.tscn
Normal file
24
examples/terminal/Terminal.tscn
Normal file
|
@ -0,0 +1,24 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_xterm_native/terminal.gdns" type="Script" id=1]
|
||||
[ext_resource path="res://addons/godot_xterm_native/themes/default.theme" type="Theme" id=2]
|
||||
[ext_resource path="res://addons/godot_xterm_native/pseudoterminal.gdns" type="Script" id=3]
|
||||
[ext_resource path="res://examples/terminal/container.gd" type="Script" id=4]
|
||||
|
||||
[node name="Container" type="Container"]
|
||||
script = ExtResource( 4 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Terminal" type="Control" parent="."]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
theme = ExtResource( 2 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Pseudoterminal" type="Node" parent="."]
|
||||
script = ExtResource( 3 )
|
18
examples/terminal/container.gd
Normal file
18
examples/terminal/container.gd
Normal file
|
@ -0,0 +1,18 @@
|
|||
extends Container
|
||||
# This Container ensures that the terminal always fills
|
||||
# the window and/or screen. It also connects the terminal
|
||||
# to the input/output of the Psuedoterminal.
|
||||
|
||||
|
||||
onready var viewport = get_viewport()
|
||||
|
||||
func _ready():
|
||||
$Pseudoterminal.connect("data_received", $Terminal, "write")
|
||||
|
||||
viewport.connect("size_changed", self, "_resize")
|
||||
_resize()
|
||||
|
||||
|
||||
func _resize():
|
||||
rect_size = viewport.size
|
||||
$Terminal.rect_size = rect_size
|
|
@ -16,6 +16,7 @@ _global_script_class_icons={
|
|||
[application]
|
||||
|
||||
config/name="Godot Xterm Native"
|
||||
run/main_scene="res://examples/terminal/Terminal.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[editor_plugins]
|
||||
|
|
Loading…
Reference in a new issue