mirror of
https://github.com/lihop/godot-xterm.git
synced 2025-05-04 20:24:23 +02:00
Add HTML5 support
This commit is contained in:
parent
fbb23661d3
commit
bb8d40df58
18 changed files with 284 additions and 31 deletions
|
@ -46,7 +46,7 @@ opts.Add(EnumVariable(
|
|||
'platform',
|
||||
'Target platform',
|
||||
host_platform,
|
||||
allowed_values=('linux', 'osx', 'windows'),
|
||||
allowed_values=('linux', 'javascript', 'osx', 'windows'),
|
||||
ignorecase=2
|
||||
))
|
||||
opts.Add(EnumVariable(
|
||||
|
@ -76,6 +76,7 @@ if env['platform'] == 'linux':
|
|||
|
||||
env['CC'] = 'gcc'
|
||||
env['CXX'] = 'g++'
|
||||
env['LIBSUFFIX'] = '.a'
|
||||
|
||||
env.Append(CCFLAGS=['-fPIC', '-Wwrite-strings'])
|
||||
env.Append(LINKFLAGS=["-Wl,-R'$$ORIGIN'"])
|
||||
|
@ -92,6 +93,28 @@ if env['platform'] == 'linux':
|
|||
env.Append(CCFLAGS=['-m32'])
|
||||
env.Append(LINKFLAGS=['-m32'])
|
||||
|
||||
# Compile for HTML5.
|
||||
elif env['platform'] == 'javascript':
|
||||
env.Append(CPPDEFINES=['PLATFORM_JS'])
|
||||
|
||||
env['bits'] = '32'
|
||||
env['CC'] = 'emcc'
|
||||
env['CXX'] = 'em++'
|
||||
env['AR'] = 'emar'
|
||||
env['RANLIB'] = 'emranlib'
|
||||
env.Append(CPPFLAGS=['-s', 'SIDE_MODULE=1'])
|
||||
env.Append(LINKFLAGS=['-s', 'SIDE_MODULE=1'])
|
||||
env['SHOBJSUFFIX'] = '.bc'
|
||||
env['SHLIBSUFFIX'] = '.wasm'
|
||||
env['OBJPREFIX'] = ''
|
||||
env['OBJSUFFIX'] = '.bc'
|
||||
env['PROGPREFIX'] = ''
|
||||
env['PROGSUFFIX'] = ''
|
||||
env['LIBSUFFIX'] = '.bc'
|
||||
env['LIBPREFIXES'] = ['$LIBPREFIX']
|
||||
env['LIBSUFFIXES'] = ['$LIBSUFFIX']
|
||||
env.Replace(SHLINKFLAGS='$LINKFLAGS')
|
||||
env.Replace(SHLINKFLAGS='$LINKFLAGS')
|
||||
|
||||
# Compile for OSX.
|
||||
elif env['platform'] == 'osx':
|
||||
|
@ -99,6 +122,7 @@ elif env['platform'] == 'osx':
|
|||
|
||||
env['CC'] = 'clang'
|
||||
env['CXX'] = 'clang++'
|
||||
env['LIBSUFFIX'] = '.a'
|
||||
|
||||
if env['bits'] == '32':
|
||||
raise ValueError(
|
||||
|
@ -121,6 +145,7 @@ elif env['platform'] == 'osx':
|
|||
# Compile for Windows.
|
||||
elif env['platform'] == 'windows':
|
||||
env.Append(CPPDEFINES=['PLATFORM_WINDOWS'])
|
||||
env['LIBSUFFIX'] = '.lib'
|
||||
|
||||
# On Windows using MSVC.
|
||||
if host_platform == 'windows':
|
||||
|
@ -202,33 +227,42 @@ env.Append(LIBPATH=[
|
|||
'external/godot-cpp/bin/',
|
||||
'external/libtsm/build/bin/',
|
||||
])
|
||||
|
||||
env.Append(LIBS=[
|
||||
'libgodot-cpp.{}.{}.{}'.format(
|
||||
env.File('external/godot-cpp/bin/libgodot-cpp.{}.{}.{}{}'.format(
|
||||
env['platform'],
|
||||
env['target'],
|
||||
env['bits']
|
||||
),
|
||||
'libtsm.{}.{}.{}'.format(
|
||||
'wasm' if env['platform'] == 'javascript' else env['bits'],
|
||||
env['LIBSUFFIX'],
|
||||
)),
|
||||
env.File('external/libtsm/build/bin/libtsm.{}.{}.{}{}'.format(
|
||||
env['platform'],
|
||||
env['target'],
|
||||
env['bits']
|
||||
),
|
||||
env['bits'],
|
||||
env['LIBSUFFIX'],
|
||||
)),
|
||||
])
|
||||
|
||||
sources = []
|
||||
sources.append('src/libgodotxtermnative.cpp')
|
||||
sources.append('src/terminal.cpp')
|
||||
|
||||
# Psuedoterminal not supported on windows yet.
|
||||
if env['platform'] != 'windows':
|
||||
# Psuedoterminal not supported on windows (yet) or HTML5.
|
||||
if env['platform'] != 'windows' and env['platform'] != 'javascript':
|
||||
sources.append('src/pseudoterminal.cpp')
|
||||
env.Append(LIBS=['util'])
|
||||
|
||||
if env['platform'] == 'linux':
|
||||
libsuffix = "a"
|
||||
suffix = "so"
|
||||
elif env['platform'] == 'javascript':
|
||||
libsuffix = "bc"
|
||||
suffix = "wasm"
|
||||
elif env['platform'] == 'windows':
|
||||
libsuffix = "lib"
|
||||
suffix = "dll"
|
||||
elif env['platform'] == 'osx':
|
||||
libsuffix = "a"
|
||||
suffix = "dylib"
|
||||
|
||||
library = env.SharedLibrary(
|
||||
|
|
|
@ -33,3 +33,7 @@ scons generate_bindings=yes -j$(nproc)
|
|||
# Build libgodot-xterm.
|
||||
cd ${NATIVE_DIR}
|
||||
scons -j$(nproc)
|
||||
|
||||
echo "To Build libgodot-xterm for javascript platform inside a docker container, run:"
|
||||
echo 'UID_GID="$(id -u):$(id -g)" docker-compose run javascript-build'
|
||||
|
||||
|
|
6
addons/godot_xterm/native/docker-compose.yaml
Normal file
6
addons/godot_xterm/native/docker-compose.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
services:
|
||||
javascript-build:
|
||||
build: misc/docker
|
||||
user: ${UID_GID}
|
||||
volumes:
|
||||
- .:/godot
|
2
addons/godot_xterm/native/external/godot-cpp
vendored
2
addons/godot_xterm/native/external/godot-cpp
vendored
|
@ -1 +1 @@
|
|||
Subproject commit b79a3b98b28e18bf981e2e2bd0b60faa23ef85f2
|
||||
Subproject commit b8eebe5eb61f1b22d2d829cccef264138b106cdb
|
|
@ -7,18 +7,18 @@ reloadable=true
|
|||
|
||||
[entry]
|
||||
|
||||
Server.64="res://addons/godot_xterm/native/bin/libgodot-xterm.linux.64.so"
|
||||
X11.64="res://addons/godot_xterm/native/bin/libgodot-xterm.linux.64.so"
|
||||
X11.32="res://addons/godot_xterm/native/bin/libgodot-xterm.linux.32.so"
|
||||
HTML5.wasm32="res://addons/godot_xterm/native/bin/libgodot-xterm.javascript.32.wasm"
|
||||
OSX.64="res://addons/godot_xterm/native/bin/libgodot-xterm.osx.64.dylib"
|
||||
Windows.64="res://addons/godot_xterm/native/bin/libgodot-xterm.windows.64.dll"
|
||||
Windows.32="res://addons/godot_xterm/native/bin/libgodot-xterm.windows.32.dll"
|
||||
OSX.64="res://addons/godot_xterm/native/bin/libgodot-xterm.osx.64.dylib"
|
||||
X11.64="res://addons/godot_xterm/native/bin/libgodot-xterm.linux.64.so"
|
||||
X11.32="res://addons/godot_xterm/native/bin/libgodot-xterm.linux.32.so"
|
||||
|
||||
[dependencies]
|
||||
|
||||
Server.64=[ ]
|
||||
X11.64=[ ]
|
||||
X11.32=[ ]
|
||||
HTML5.wasm32=[ ]
|
||||
OSX.64=[ ]
|
||||
Windows.64=[ ]
|
||||
Windows.32=[ ]
|
||||
OSX.64=[ ]
|
||||
X11.64=[ ]
|
||||
X11.32=[ ]
|
||||
|
|
0
addons/godot_xterm/native/misc/.gdignore
Normal file
0
addons/godot_xterm/native/misc/.gdignore
Normal file
12
addons/godot_xterm/native/misc/docker/Dockerfile
Normal file
12
addons/godot_xterm/native/misc/docker/Dockerfile
Normal file
|
@ -0,0 +1,12 @@
|
|||
FROM ponders/godot-cpp-ci
|
||||
|
||||
RUN git clone https://github.com/emscripten-core/emsdk.git
|
||||
WORKDIR emsdk
|
||||
RUN ./emsdk install 2.0.10
|
||||
RUN ./emsdk activate 2.0.10
|
||||
RUN chmod -R 777 /emsdk
|
||||
WORKDIR /godot
|
||||
RUN apt-get update && apt-get install -y vim
|
||||
COPY ./build.sh /build.sh
|
||||
RUN chmod +x /build.sh
|
||||
CMD /build.sh
|
7
addons/godot_xterm/native/misc/docker/build.sh
Normal file
7
addons/godot_xterm/native/misc/docker/build.sh
Normal file
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
source /emsdk/emsdk_env.sh
|
||||
export EM_CACHE=/godot/.emcache
|
||||
cd /godot/external/godot-cpp
|
||||
scons platform=javascript -j$(nproc)
|
||||
cd /godot
|
||||
scons platform=javascript -j$(nproc)
|
|
@ -11,6 +11,35 @@ const CURSOR_LEFT = "\u001b[D"
|
|||
|
||||
const DEFAULT_FOREGROUND_COLOR = "\u001b[0m"
|
||||
|
||||
class ANSIColor:
|
||||
extends Object
|
||||
# Using ANSIColor constants, rather than Color will respect the
|
||||
# colors of the selected terminal theme. Whereas Color will set
|
||||
# the exact color specified regardless of theme.
|
||||
|
||||
const black = { fg = 30, bg = 40 }
|
||||
const red = {fg = 31, bg = 41 }
|
||||
const green = {fg = 32, bg = 42}
|
||||
const yellow = {fg = 33, bg = 43}
|
||||
const blue = {fg = 34, bg = 44}
|
||||
const magenta = {fg = 35, bg = 45}
|
||||
const cyan = {fg = 36, bg = 46}
|
||||
const white = {fg = 37, bg = 47}
|
||||
const bright_black = {fg = 90, bg = 100}
|
||||
const gray = bright_black
|
||||
const grey = bright_black
|
||||
const bright_red = {fg = 91, bg = 101}
|
||||
const bright_green = {fg = 92, bg = 102}
|
||||
const bright_yellow = {fg = 93, bg = 103}
|
||||
const bright_blue = {fg = 94, bg = 104}
|
||||
const bright_magenta = {fg = 95, bg = 105}
|
||||
const bright_cyan = {fg = 96, bg = 106}
|
||||
const bright_white = {fg = 97, bg = 107}
|
||||
|
||||
func _init():
|
||||
assert(false, "ANSIColor is an abstract class. You should only use the color constants (e.g. ANSIColor.black).")
|
||||
|
||||
|
||||
var terminal
|
||||
|
||||
|
||||
|
@ -44,14 +73,22 @@ func cup(row: int = 0, col: int = 0) -> void:
|
|||
terminal.write("\u001b[%d;%dH" % [row, col])
|
||||
|
||||
|
||||
func setaf(color: Color) -> void:
|
||||
var fg = "\u001b[38;2;%d;%d;%dm" % [color.r8, color.g8, color.b8]
|
||||
terminal.write(fg)
|
||||
func setaf(color) -> void:
|
||||
if color is Color:
|
||||
terminal.write("\u001b[38;2;%d;%d;%dm" % [color.r8, color.g8, color.b8])
|
||||
elif "fg" in color and color.fg is int:
|
||||
terminal.write("\u001b[%dm" % color.fg)
|
||||
else:
|
||||
push_error("Invalid color: %s" % color)
|
||||
|
||||
|
||||
func setab(color: Color) -> void:
|
||||
var bg = "\u001b[48;2;%d;%d;%dm" % [color.r8, color.g8, color.b8]
|
||||
terminal.write(bg)
|
||||
func setab(color) -> void:
|
||||
if color is Color:
|
||||
terminal.write("\u001b[48;2;%d;%d;%dm" % [color.r8, color.g8, color.b8])
|
||||
elif "bg" in color and color.bg is int:
|
||||
terminal.write("\u001b[%dm" % color.bg)
|
||||
else:
|
||||
push_error("Invalid color: %s" % color)
|
||||
|
||||
|
||||
func rev() -> void:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue