-
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
Improved Layering and enabling TS strict #1507
Comments
See this PR for more specifics #1508 |
+1 for getting DOM related stuff strictly separated, it makes it possible to use core parts for offscreen things like an expect lib etc. which also implies that the core parts should be runnable in a pure nodejs env (without any browser engine stuff). This would also help to get it moved into a webworker later on (although this might need further glue code for interaction). I wonder at what level of integration you intend to build the later API - will this become framework like where people can pick & alter stuff and just mount all together or will it still form the current more "monolithic" API? If we go with the framework idea and expose most of the internals we may want to deliver a default "easy to go" preconfigured setup as well (might end up delivering framework parts and a "monolithic" API, so not sure what works best). |
To illustrate the framework/component idea further, take some buffering base class (no DOM) and add the following:
1 + 2 would form an offscreen terminal capable to deal with scripts/apps expecting a terminal without any interaction, with 3 added it would also be able to handle interaction. With 4 it would form a complete terminal with output representation. |
Less API is always better as it means more flexibility for us, having said that we definitely need to add a bunch of buffer APIs as addons rely on them. We'll see what works, this model gives us the flexibility of doing so in the future, my thinking was we provide the |
This is the major win for me, not needing to worry about DOM and being able to do end-to-end tests of the core will be very valuable. |
Nice seeing things getting into shape, I like the proposed design! @jerch
@Tyriar I guess it's because the words |
It's a really cool idea. If this will be really implemented you can easy change render to another one. Cloud 9 terminal for example it's a control sequence parser(seems old xterm) + ice editor(like render). If you really do good xterm.js splitting you can easy, for example, use Monaco editor to render terminal. |
Good idea, I stayed away from frontend/backend because it's not clear what the capitalization should be. Also I like core/ui as it's very clear what that means imo. So let's go with |
@Tyriar Yes, renaming |
To be clear, there's a little missing information in this diagram:
export class Core {
public f() {
// Fire event on Core
this._parser.on('refresh', d => this.emit('refresh', d));
}
} export class UserInterface {
public f() {
// Core communicating with UserInterface
this._core.on('refresh', d => renderer.refresh(d));
}
public x() {
// An example of direct communication to Core inside ui/
this._core.send(this._arrowSequences());
}
} Here's what I see the implementation of import { ICore } from '../common/Types';
import { Core } from '../core/Core';
import { IUserInteface } from '../ui/Types';
import { UserInteface } from '../ui/UserInterface';
export class Terminal {
private _core: ICore;
private _userInteface: IUserInterface;
constructor(opt) {
this._core = new Core(opt);
}
public open(element: HTMLElement) {
this._userInterface = new UserInterface(this._core, element);
}
} Just went through all the files and I think these are the folders we want them in:
Also to clarify this as I confused myself just now, you may ask why not something like this:
The reason is because the eventual goal is to allow core to run in a web worker. That's the sole reason this
|
That's perfect, structuring it this way is definitely the way to go IMHO 👍. It also supports the ideas raised in #1515 very well. |
Part of xtermjs#1507 Part of xtermjs#1319
Part of xtermjs#1507 Part of xtermjs#1319
Belong here as it interacts with DOM Part of xtermjs#1507
We changed plans from moving web worker compatible code to shared/ to enforcing layers using core/, common/, ui/ and public/. This change moves files back from the shared/ dir to clean up the codebase. Part of xtermjs#1507
This also fine tunes some of the data events to not clear selection and scroll to the bottom of the viewport anymore. Part of xtermjs#1507 Fixes xtermjs#2112
Some things to do before this is checked off:
|
Part of xtermjs#2749 Part of xtermjs#1507
Background
While in Prague, @mofux and I got together to discuss a better architecture for xterm.js that could lead to things like pulling all DOM access away from the core, moving parts of xterm.js into a web worker, and swapping out the frontend completely. Notes from this discussion were captured in #1506
Proposal
I propose we split the codebase into distinct parts with very specific roles. This could be done all in the VS Code repo and still result in only a single
xterm
module being published, while also not obstructing a future where we may want to allow swapping parts out.Here is the breakdown:
src/
- Contains all source code as todaybase/
- Contains interfaces for core and frontend to communicate with each other, as well as code that is used between both of themcore/
- This runs in both node.js and browser runtimes. This means far better and easier testing since everything is just node.js without worrying about the DOMui/
- This code runs only in a browser, anything in xterm.js that interacts with the DOM today will move to here. That includes things like mouse wheel handling (and translating), composition helper, textarea, etc.public/
- This provides an implementation of the current day xterm.js API.Dependencies between this folders are strictly enforced:
Notice that
ui
does not depend oncore
, any dependencies betweencore
andui
are pulled into interfaces and placed intobase
.Example file structure
This tree will give you an idea of what lives where:
Composite projects
In TypeScript 3 we will get the ability to build parts of projects independently and depend on them. This would lead to improved build times but also we get the layering enforcement for free as the
tsconfig.json
forcore
for example will not contain thedom
APIs, so any use of them will fail compilation.Absolute imports
We may be able to use absolute imports when these changes happen, whenever I try to do it I run into issues with importing a file from the same folder as an absolute import. See #1314
Plan
This is quite a large shift from the way things are done now and therefore will take a fair bit of time to execute. Luckily it can be done in parts and many in parallel. It may be best to move to this first:
And slowly separate
core
fromui
.The text was updated successfully, but these errors were encountered: