Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
princjef committed Jul 24, 2018
1 parent d15aee4 commit b1817a9
Show file tree
Hide file tree
Showing 19 changed files with 2,940 additions and 9 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf

[*.{j,t}s]
max_line_length = 100

[*.md]
trim_trailing_whitespace = false
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Bug report
about: Create a bug report
---

<!-- ⚠️ Please search existing issues to avoid creating duplicates. ⚠️ -->
<!-- Describe the bug here. -->

## Details
- Browser and browser and/or electron version:
- OS version:
- xterm.js version:
- xterm-ligature-support version:

### Steps to reproduce

1.
2.
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Feature request
about: Suggest a feature or enhancement
---

<!-- ⚠️ Please search existing issues to avoid creating duplicates. ⚠️ -->
<!-- Describe the enhancement here. -->
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Question
about: The issue tracker is not for questions. Please ask questions on https://stackoverflow.com/questions/tagged/xtermjs or https://gitter.im/sourcelair/xterm.js.
---

🛑 The issue tracker is not for questions 🛑

If you have a question, please ask it on https://stackoverflow.com/questions/tagged/xtermjs or https://gitter.im/sourcelair/xterm.js.
21 changes: 13 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
node_modules/
.nyc_output/
coverage/

lib/

*.tgz
npm-debug.log*
node_modules/
.nyc_output/
coverage/

lib/
fonts/

.env
.vscode/
*.swp
*.tgz
npm-debug.log*
yarn-error.log*
33 changes: 33 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Blacklist - exclude everything except npm defaults such as LICENSE, etc
*
!*/

# Whitelist - entries to be included must be negated with "!"
!*.js
!*.json

# Whitelist - lib/
!lib/**/*.d.ts

!lib/**/*.js
!lib/**/*.js.map

# Whitelist - src/
!src/**/*.ts
!src/**/*.d.ts

!src/**/*.js
!src/**/*.js.map

# Blacklist - (normal behavior) these will override any whitelist
*.test.ts
*.test.d.ts
*.test.js
*.test.js.map

docs/
/.idea/
.vscode/
coverage/
.nyc_output/
fonts/
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Jeff Principe <princjef@gmail.com>
73 changes: 73 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race,
religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting [@Tyriar](https://twitter.com/Tyriar) or [@pariskasid](https://twitter.com/pariskasid) on Twitter. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org
51 changes: 51 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# How to contribute to xterm-ligature-support

- [Opening issues for bug reports or feature requests](#opening-issues)
- [Contributing code](#contributing-code)

## Opening issues

The preferred way to report bugs or request features is to use
[GitHub issues](http://github.com/xtermjs/xterm-ligature-support/issues). Before
opening an issue, read these pointers.

### Opening issues effectively

- Include information about **the browser in which the problem occurred**. Even
if you tested several browsers, and the problem occurred in all of them,
mention this fact in the bug report. Also include browser version numbers and
the operating system that you're on.

- Mention which release of xterm.js and xterm-ligature-support you're using.
Preferably, try also with the current HEAD of the master branch, to ensure the
problem has not already been fixed.

- Mention precisely what went wrong. What did you expect to happen? What
happened instead? Describe the exact steps a maintainer has to take to make
the problem occur.

- Be polite. Issues with an indignant or belligerent tone tend to be moved to
the bottom of the pile.

## Contributing code

- Make sure you have a [GitHub account](https://github.com/join)
- Fork [xterm-ligature-support](https://github.com/xtermjs/xterm-ligature-support/)
([how to fork a repo](https://help.github.com/articles/fork-a-repo))
- Make your changes
- If your changes are easy to test or likely to regress, add tests. Tests go into corresponding `.test.ts` files.
- Follow the general code style of the rest of the project (see below).
- Submit a pull request
([how to create a pull request](https://help.github.com/articles/fork-a-repo)).
Don't put more than one feature/fix in a single pull request.

By contributing code to xterm-ligature-support you

- agree to license the contributed code under xterm-ligature-support's [MIT
license](LICENSE).

- confirm that you have the right to contribute and license the code
in question. (Either you hold all rights on the code, or the rights
holder has explicitly granted the right to use it like this,
through a compatible open source license or through a direct
agreement with you.)
96 changes: 95 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,95 @@
# xterm-ligature-support
# xterm-ligature-support

Add support for programming ligatures to [xterm.js][] when running in
environments with access to [Node.js][] APIs (such as [Electron][]).

## Requirements

* [Node.js][] 8.x or higher (present in [Electron][] 1.8.3 or higher)
* [xterm.js][] 3.6.0 or higher using the default canvas renderer

## Usage

Install in your project by running:

```
npm install xterm-ligature-support
```

Then, modify the location where you initialize the terminal to enable ligature
support after opening. If you enable ligatures prior to opening the terminal,
they will not function properly.

Your code should look something like this:

```js
import { Terminal } from 'xterm';
import * as ligatures from 'xterm-ligature-support';

Terminal.applyAddon(ligatures);

const terminal = new Terminal();
terminal.open(document.getElementById('terminal-mount'));
terminal.enableLigatures();
```

### Importing in TypeScript

If you use TypeScript, you will need to cast the terminal variable as `any` when
you enable ligatures because TypeScript does not know that the addon is
available on the terminal object. It will look like this:

```ts
(terminal as any).enableLigatures()
```

Alternatively, you can import the addon directly as a function and pass the
terminal as an argument:

```js
import { Terminal } from 'xterm';
import { enableLigatures } from 'xterm-ligature-support';

const terminal = new Terminal();
terminal.open(document.getElementById('terminal-mount'));
enableLigatures(terminal);
```

## How It Works

In a browser environment, font ligature information is read directly by the web
browser and used to render text correctly without any intervention from the
developer. As of version 3, xterm.js uses the canvas to render characters
individually, resulting in a significant performance boost. However, this means
that it can no longer lean on the browser to determine when to draw font
ligatures.

This package locates the font file on disk for the font currently in use by the
terminal and parses the ligature information out of it (via the
[font-ligatures][] package). As text is rendered in xterm.js, this package
annotates it with the locations of ligatures, allowing xterm.js to render it
correctly.

Since this package depends on being able to find and resolve a system font from
disk, it has to have system access that isn't available in the web browser. As a
result, this package is mainly useful in environments that combine browser and
Node.js runtimes (such as [Electron][]).

## Fonts

This package makes use of the following fonts for testing:

* [Fira Code][] - [Licensed under the OFL][Fira Code License] by Nikita
Prokopov, Mozilla Foundation with reserved names Fira Code, Fira Mono, and
Fira Sans
* [Iosevka][] - [Licensed under the OFL][Iosevka License] by Belleve Invis with
reserved name Iosevka

[xterm.js]: https://github.com/xtermjs/xterm.js
[Electron]: https://electronjs.org/
[Node.js]: https://nodejs.org/
[font-ligatures]: https://github.com/princjef/font-ligatures
[Fira Code]: https://github.com/tonsky/FiraCode
[Fira Code License]: https://github.com/tonsky/FiraCode/blob/master/LICENSE
[Iosevka]: https://github.com/be5invis/Iosevka
[Iosevka License]: https://github.com/be5invis/Iosevka/blob/master/LICENSE.md
53 changes: 53 additions & 0 deletions bin/download-fonts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const fs = require('fs');
const path = require('path');
const util = require('util');

const axios = require('axios').default;
const mkdirp = require('mkdirp');
const yauzl = require('yauzl');

const urls = {
fira: 'https://github.com/tonsky/FiraCode/raw/master/distr/otf/FiraCode-Regular.otf',
iosevka: 'https://github.com/be5invis/Iosevka/releases/download/v1.14.3/01-iosevka-1.14.3.zip'
};

const writeFile = util.promisify(fs.writeFile);
const fontsFolder = path.join(__dirname, '../fonts');

async function download() {
await mkdirp(fontsFolder);

console.log('Downloading Fira Code...');
await writeFile(
path.join(fontsFolder, 'firaCode.otf'),
(await axios.get(urls.fira, { responseType: 'arraybuffer' })).data
);

console.log('Downloading Iosevka...');
const iosevkaContents = (await axios.get(urls.iosevka, { responseType: 'arraybuffer' })).data;
const iosevkaZipfile = await util.promisify(yauzl.fromBuffer)(iosevkaContents);
await new Promise((resolve, reject) => {
iosevkaZipfile.on('entry', entry => {
if (entry.fileName === 'ttf/iosevka-regular.ttf') {
iosevkaZipfile.openReadStream(entry, (err, stream) => {
if (err) {
return reject(err);
}

const writeStream = fs.createWriteStream(path.join(fontsFolder, 'iosevka.ttf'));
stream.pipe(writeStream);
writeStream.on('close', () => resolve());
});
}
});
});

console.log('Loaded all fonts for testing')
}

download();

process.on('unhandledRejection', e => {
console.error(e);
process.exit(1);
});
1 change: 1 addition & 0 deletions definitions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'postcss-value-parser';
Loading

0 comments on commit b1817a9

Please sign in to comment.