-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wasm serialize & hook interface #4479
Draft
jerch
wants to merge
14
commits into
xtermjs:master
Choose a base branch
from
jerch:wasm_serialize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
81168ea
initial transfer
jerch dce2d2c
run inwasm late
jerch e4952d4
fix test, disable linter for now
jerch f205855
avoid .. in npm script
jerch ae1343d
add compiled wasm to repo to save CI runtime
jerch 27700c2
add build files
jerch 7a42219
fix benchmark, add force to pack step
jerch 37ede60
make linter happy
jerch 8e51c7e
upgrade inwasm
jerch d20db7f
preserve only needed built files
jerch 8f466fc
use external c file
jerch 334f9f2
use -S flag to avoid sdk pulling in CI steps
jerch 8c15eb2
upgrade inwasm, remove nonsense files in builddir
jerch 840974d
some initial cleanup
jerch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
lib | ||
node_modules | ||
out-benchmark | ||
|
||
# skip inwasm folders | ||
inwasm-sdks/ | ||
inwasm-builds/ | ||
!inwasm-builds/**/final.wat | ||
!inwasm-builds/**/final.wasm | ||
!inwasm-builds/**/definition.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Blacklist - exclude everything except npm defaults such as LICENSE, etc | ||
* | ||
!*/ | ||
|
||
# Whitelist - lib/ | ||
!lib/**/*.d.ts | ||
|
||
!lib/**/*.js | ||
!lib/**/*.js.map | ||
|
||
!lib/**/*.css | ||
|
||
# Whitelist - src/ | ||
!src/**/*.ts | ||
!src/**/*.d.ts | ||
|
||
!src/**/*.js | ||
!src/**/*.js.map | ||
|
||
!src/**/*.css | ||
|
||
# Blacklist - src/ test files | ||
src/**/*.test.ts | ||
src/**/*.test.d.ts | ||
src/**/*.test.js | ||
src/**/*.test.js.map | ||
|
||
# Whitelist - typings/ | ||
!typings/*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## xterm-addon-serialize | ||
|
||
An addon for [xterm.js](https://github.com/xtermjs/xterm.js) that enables xterm.js to serialize a terminal framebuffer into string or html. This addon requires xterm.js v4+. | ||
|
||
⚠️ This is an experimental addon that is still under construction ⚠️ | ||
|
||
### Install | ||
|
||
```bash | ||
npm install --save xterm-addon-serialize | ||
``` | ||
|
||
### Usage | ||
|
||
```ts | ||
import { Terminal } from "xterm"; | ||
import { SerializeAddon } from "xterm-addon-serialize"; | ||
|
||
const terminal = new Terminal(); | ||
const serializeAddon = new SerializeAddon(); | ||
terminal.loadAddon(serializeAddon); | ||
|
||
terminal.write("something...", () => { | ||
console.log(serializeAddon.serialize()); | ||
}); | ||
``` | ||
|
||
See the full [API](https://github.com/xtermjs/xterm.js/blob/master/addons/xterm-addon-serialize/typings/xterm-addon-serialize.d.ts) for more advanced usage. | ||
|
||
### Benchmark | ||
|
||
⚠️ Ensure you have `lolcat`, `hexdump` programs installed in your computer | ||
|
||
```shell | ||
$ git clone https://github.com/xtermjs/xterm.js.git | ||
$ cd xterm.js | ||
$ yarn | ||
$ cd addons/xterm-addon-serialize | ||
$ yarn benchmark && yarn benchmark-baseline | ||
$ # change some code in `xterm-addon-serialize` | ||
$ yarn benchmark-eval | ||
``` |
65 changes: 65 additions & 0 deletions
65
addons/xterm-addon-serialize2/benchmark/Serialize2Addon.benchmark.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) 2019 The xterm.js authors. All rights reserved. | ||
* @license MIT | ||
*/ | ||
|
||
import { perfContext, before, ThroughputRuntimeCase } from 'xterm-benchmark'; | ||
|
||
import { spawn } from 'node-pty'; | ||
import { Utf8ToUtf32, stringFromCodePoint } from 'common/input/TextDecoder'; | ||
import { Terminal } from 'browser/public/Terminal'; | ||
import { Serialize2Addon } from 'Serialize2Addon'; | ||
|
||
class TestTerminal extends Terminal { | ||
public writeSync(data: string): void { | ||
(this as any)._core.writeSync(data); | ||
} | ||
} | ||
|
||
perfContext('Terminal: sh -c "dd if=/dev/urandom count=40 bs=1k | hexdump | lolcat -f"', () => { | ||
let content = ''; | ||
let contentUtf8: Uint8Array; | ||
|
||
before(async () => { | ||
const p = spawn('sh', ['-c', 'dd if=/dev/urandom count=40 bs=1k | hexdump | lolcat -f'], { | ||
name: 'xterm-256color', | ||
cols: 80, | ||
rows: 25, | ||
cwd: process.env.HOME, | ||
env: process.env, | ||
encoding: (null as unknown as string) // needs to be fixed in node-pty | ||
}); | ||
const chunks: Buffer[] = []; | ||
let length = 0; | ||
p.on('data', data => { | ||
chunks.push(data as unknown as Buffer); | ||
length += data.length; | ||
}); | ||
await new Promise<void>(resolve => p.on('exit', () => resolve())); | ||
contentUtf8 = Buffer.concat(chunks, length); | ||
// translate to content string | ||
const buffer = new Uint32Array(contentUtf8.length); | ||
const decoder = new Utf8ToUtf32(); | ||
const codepoints = decoder.decode(contentUtf8, buffer); | ||
for (let i = 0; i < codepoints; ++i) { | ||
content += stringFromCodePoint(buffer[i]); | ||
// peek into content to force flat repr in v8 | ||
if (!(i % 10000000)) { | ||
content[i]; | ||
} | ||
} | ||
}); | ||
|
||
perfContext('serialize', () => { | ||
let terminal: TestTerminal; | ||
const serializeAddon = new Serialize2Addon(); | ||
before(async () => { | ||
terminal = new TestTerminal({ cols: 80, rows: 25, scrollback: 5000 }); | ||
serializeAddon.activate(terminal); | ||
await new Promise<void>(r => terminal.write(content, r)); | ||
}); | ||
new ThroughputRuntimeCase('', () => { | ||
return { payloadSize: serializeAddon.serialize().length }; | ||
}, { fork: false }).showAverageThroughput(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"APP_PATH": ".benchmark", | ||
"evalConfig": { | ||
"tolerance": { | ||
"*": [0.75, 1.5], | ||
"*.dev": [0.01, 1.5], | ||
"*.cv": [0.01, 1.5], | ||
"EscapeSequenceParser.benchmark.js.*.averageThroughput.mean": [0.9, 5] | ||
}, | ||
"skip": [ | ||
"*.median", | ||
"*.runs", | ||
"*.dev", | ||
"*.cv", | ||
"EscapeSequenceParser.benchmark.js.*.averageRuntime", | ||
"Terminal.benchmark.js.*.averageRuntime" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["dom", "es6"], | ||
"outDir": "../out-benchmark", | ||
"types": ["../../../node_modules/@types/node"], | ||
"moduleResolution": "node", | ||
"strict": false, | ||
"target": "es2015", | ||
"module": "commonjs", | ||
"baseUrl": ".", | ||
"paths": { | ||
"common/*": ["../../../src/common/*"], | ||
"browser/*": ["../../../src/browser/*"], | ||
"Serialize2Addon": ["../src/Serialize2Addon"] | ||
} | ||
}, | ||
"include": ["../**/*", "../../../typings/xterm.d.ts"], | ||
"exclude": ["../../../**/*test.ts", "../../**/*api.ts"], | ||
"references": [ | ||
{ "path": "../../../src/common" }, | ||
{ "path": "../../../src/browser" } | ||
] | ||
} |
Binary file added
BIN
+2.23 KB
addons/xterm-addon-serialize2/inwasm-builds/out/serializer.wasm.js/serialize/final.wasm
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "xterm-addon-serialize2", | ||
"version": "0.1.0", | ||
"author": { | ||
"name": "The xterm.js authors", | ||
"url": "https://xtermjs.org/" | ||
}, | ||
"main": "lib/xterm-addon-serialize2.js", | ||
"types": "typings/xterm-addon-serialize2.d.ts", | ||
"repository": "https://github.com/xtermjs/xterm.js", | ||
"license": "MIT", | ||
"keywords": [ | ||
"terminal", | ||
"xterm", | ||
"xterm.js" | ||
], | ||
"scripts": { | ||
"inwasm": "inwasm out/*.wasm.js", | ||
"prepackage": "../../node_modules/.bin/tsc -p . && inwasm -f out/*.wasm.js", | ||
"package": "../../node_modules/.bin/webpack", | ||
"prepublishOnly": "npm run package", | ||
"benchmark": "NODE_PATH=../../out:./out:./out-benchmark/ ../../node_modules/.bin/xterm-benchmark -r 5 -c benchmark/benchmark.json", | ||
"benchmark-baseline": "NODE_PATH=../../out:./out:./out-benchmark/ ../../node_modules/.bin/xterm-benchmark -r 5 -c benchmark/benchmark.json --baseline out-benchmark/benchmark/*benchmark.js", | ||
"benchmark-eval": "NODE_PATH=../../out:./out:./out-benchmark/ ../../node_modules/.bin/xterm-benchmark -r 5 -c benchmark/benchmark.json --eval out-benchmark/benchmark/*benchmark.js" | ||
}, | ||
"peerDependencies": { | ||
"xterm": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"inwasm": "^0.0.13" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v4 -> v5.2+? Should we just remove that line as there's the experimental line + we call it out in the release notes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing. I just copy-cloned from the old addon and did not bother to fix all things yet.