Skip to content
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

Add support for hyperlink #35 #42

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"dependencies": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
"strip-ansi": "^6.0.0",
"terminal-link": "^2.1.1"
},
"devDependencies": {
"ava": "^2.1.0",
Expand Down
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ console.log(wrapAnsi(input, 20));
<img width="331" src="screenshot.png">



## Hyperlink example
```js
const chalk = require('chalk');
const wrapAnsi = require('./index');
const terminalLink = require('terminal-link');

const link = 'https://google.com';
const input = `hi ${terminalLink(link, link, {fallback: text => text})}`;
console.log(wrapAnsi(input, 20));
```

## API

### wrapAnsi(string, columns, options?)
Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from 'ava';
import terminalLink from 'terminal-link';
import chalk from 'chalk';
import hasAnsi from 'has-ansi';
import stripAnsi from 'strip-ansi';
Expand Down Expand Up @@ -153,3 +154,9 @@ test('#39, normalizes newlines', t => {
t.is(wrapAnsi('foobar\r\nfoobar\r\nfoobar\nfoobar', 3, {hard: true}), 'foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar');
t.is(wrapAnsi('foo bar\r\nfoo bar\r\nfoo bar\nfoo bar', 3), 'foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar');
});
test('#35, wraps hyperlinks, preserving clickability in supporting terminals', t => {
const link = 'https://google.com';
const input = `hi http://a.com ${terminalLink(link, link, {fallback: text => text})}`;
const expected = 'hi http://a.com\n\u001B]8;;https://google.com\u0007https://google.c\u001B[28m\n\u001B[8mom\u001B]8;;\u0007';
t.is(wrapAnsi(input, 16, {hard: true}), expected);
});