Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
feat: added url
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed May 9, 2018
1 parent cdf7457 commit 74e3455
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 5 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ await cli.prompt('What is your password?', {type: 'hide'})

![prompt demo](assets/prompt.gif)

# cli.url(text, uri)

Create a hyperlink (if supported in the terminal)

```typescript
await cli.prompt('sometext', 'https://google.com')
// shows sometext as a hyperlink in supported terminals
// shows https://google.com in unsupported terminals
```

![url demo](assets/url.gif)

# cli.action

Shows a spinner
Expand Down
Binary file added assets/url.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ux from '../src'

ux.url('sometext', 'https://google.com')
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
"clean-stack": "^1.3.0",
"extract-stack": "^1.0.0",
"fs-extra": "^6.0.0",
"hyperlinker": "^1.0.0",
"indent-string": "^3.2.0",
"lodash": "^4.17.10",
"password-prompt": "^1.0.5",
"semver": "^5.5.0",
"strip-ansi": "^4.0.0",
"supports-color": "^5.4.0"
"supports-color": "^5.4.0",
"supports-hyperlinks": "^1.0.1"
},
"devDependencies": {
"@oclif/errors": "^1.0.9",
Expand Down
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ export const cli = {
log(format: string, ...args: string[]) {
this.info(format, ...args)
},

url(text: string, uri: string, params = {}) {
const supports = require('supports-hyperlinks')
if (supports.stdout) {
const hyperlinker = require('hyperlinker')
this.log(hyperlinker(text, uri, params))
} else {
this.log(uri)
}
}
}
export default cli

Expand Down
14 changes: 14 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ux from '../src'

import {expect, fancy} from './fancy'

process.env.FORCE_HYPERLINK = '1'

describe('prompt', () => {
fancy
.stdout()
.do(() => ux.url('sometext', 'https://google.com'))
.it('renders hyperlink', async ({stdout}) => {
expect(stdout).to.equal('ttps://google.com\u0007sometext\n')
})
})
19 changes: 15 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@ husky@^0.14.3:
normalize-path "^1.0.0"
strip-indent "^2.0.0"

hyperlinker@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/hyperlinker/-/hyperlinker-1.0.0.tgz#23dc9e38a206b208ee49bc2d6c8ef47027df0c0e"

iconv-lite@^0.4.17:
version "0.4.19"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
Expand Down Expand Up @@ -1240,6 +1244,12 @@ supports-color@^3.2.3:
dependencies:
has-flag "^1.0.0"

supports-color@^5.0.0, supports-color@^5.4.0:
version "5.4.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54"
dependencies:
has-flag "^3.0.0"

supports-color@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.2.0.tgz#b0d5333b1184dd3666cbe5aa0b45c5ac7ac17a4a"
Expand All @@ -1252,11 +1262,12 @@ supports-color@^5.3.0:
dependencies:
has-flag "^3.0.0"

supports-color@^5.4.0:
version "5.4.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54"
supports-hyperlinks@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/supports-hyperlinks/-/supports-hyperlinks-1.0.1.tgz#71daedf36cc1060ac5100c351bb3da48c29c0ef7"
dependencies:
has-flag "^3.0.0"
has-flag "^2.0.0"
supports-color "^5.0.0"

[email protected]:
version "4.0.2"
Expand Down

0 comments on commit 74e3455

Please sign in to comment.