Comments (2)
Options:
- Embed a static array of emojis within the smartwrap module, and then refuse to wrap them.
- Create option to set an array of character combinations that cannot be split, then pass that array to smartwrap.
Preferred option:
2.
from tty-table.
Doesn't the spread op [..."ccc 😀😃😄😁 eee"]
idom correctly show where you can't split?
I implemented a string truncate using it that appears to always split chars in the right place.
// eslint-disable-next-line no-control-regex
const ansiMatcher = new RegExp("([^\u001B\u009B]*)([\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))|$)", "g")
/**
* split a unicode string into code points
* @param {string} s - string with unicode
* @return {Array<string>} - array of code points
*/
const splitUnicode = s => [...s]
/**
* truncate a unicode string that may contain ansi and/or multi-column unicode characters
* @param {string} s - string with unicode and/or multi-column unicode characters
* @param {number} length - width in terminal char column
* @return {string}
*/
Format.truncate = (s, length) => {
let total = 0
return s.replace(ansiMatcher, function (match, content, ansi) {
if (total === length || 0) {
// skip all visible content
return ansi
}
let contentLength = Wcwidth(content)
if (contentLength <= length - total) {
// pass all visible content
total += contentLength
return content + ansi
}
// partial chunk
let chars = splitUnicode(content)
while (Wcwidth(chars.join("")) > length - total) {
chars.pop()
}
content = chars.join("")
// set total so the rest of content is skipped
total = length
return content + ansi
})
}
-Mike
from tty-table.
Related Issues (20)
- unexpected random newlines HOT 1
- Unable to completely remove border and header HOT 1
- Options 'truncate' doesn't play well with Chinese HOT 3
- Access to entire row within formatter function HOT 2
- rendering issue if truncate is true and first header cell needs truncation HOT 1
- Resize code has several issues HOT 6
- infinite loop in line wrapping HOT 2
- Update README.md to display browser example with colors.
- Embedded ansi HOT 2
- Version 2.8.12 breaks backwards compatibility with version 2.8.11 HOT 5
- npm test OR node examples/cli-test.js fails HOT 1
- getAvailableWidth() should work without a width HOT 1
- Automatic width not correct when using formatter HOT 1
- Footer align does not work HOT 1
- Using a falsy value like 0 in a cell displays nothing HOT 1
- Installation error HOT 2
- Column misaligned for wide tables (high number of columns) and narrow screen HOT 1
- Smartwrap deprecation warning HOT 3
- RangeError is thrown when the column width is float HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tty-table.