-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fit to terminal width by calculating string width
- Loading branch information
Showing
13 changed files
with
1,360 additions
and
188 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"bracketSpacing": false, | ||
"printWidth": 80, | ||
"semi": true, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false, | ||
"arrowParens": "always" | ||
} | ||
"bracketSpacing": false, | ||
"printWidth": 320, | ||
"semi": true, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false, | ||
"arrowParens": "always" | ||
} |
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,51 @@ | ||
import {Bench} from 'tinybench'; | ||
import {getStringWidth} from '../dist/string-width.js'; | ||
import fastStringTruncatedWidth from 'fast-string-truncated-width'; | ||
|
||
const fastStringTruncatedWidthOptions = {limit: Infinity, ellipsis: ''}; | ||
|
||
const suites = [ | ||
{ | ||
name: 'Basic ASCII', | ||
input: 'Hello' | ||
}, | ||
{ | ||
name: 'ANSI + ASCII', | ||
input: '\x1b[31mabc\x1b[31m' | ||
}, | ||
{ | ||
name: 'Emoji', | ||
input: '😀🤪🙂↔️🥶☝🏿☝🏿' | ||
}, | ||
{ | ||
name: 'Emoji+ASCII', | ||
input: '😀hello . 🤪🙂↔️🥶was☝🏿☝🏿' | ||
}, | ||
{ | ||
name: 'CJK', | ||
input: '古池や' | ||
} | ||
]; | ||
|
||
for (const suite of suites) { | ||
const bench = new Bench(); | ||
|
||
bench | ||
.add('picospinner getStringWidth()', () => { | ||
for (const suite of suites) { | ||
getStringWidth(suite.input); | ||
} | ||
}) | ||
.add('fast-string-truncated-width', () => { | ||
for (const suite of suites) { | ||
fastStringTruncatedWidth(suite.input, fastStringTruncatedWidthOptions, {}).width; | ||
} | ||
}); | ||
|
||
console.log('Benchmark:', suite.name); | ||
|
||
await bench.warmup(); | ||
await bench.run(); | ||
|
||
console.table(bench.table()); | ||
} |
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 |
---|---|---|
@@ -1,12 +1,21 @@ | ||
import eslint from '@eslint/js'; | ||
import {configs as tseslintConfigs} from 'typescript-eslint'; | ||
import globals from 'globals'; | ||
|
||
const {configs: eslintConfigs} = eslint; | ||
|
||
export default [ | ||
{ | ||
files: ['src/**/*.ts'] | ||
}, | ||
eslintConfigs.recommended, | ||
...tseslintConfigs.strict | ||
...tseslintConfigs.strict, | ||
{ | ||
files: ['src/**/*.ts', '**/*.js'], | ||
rules: { | ||
'no-control-regex': 'off' | ||
}, | ||
languageOptions: { | ||
globals: { | ||
...globals.node | ||
} | ||
} | ||
} | ||
]; |
Oops, something went wrong.