Skip to content

Commit 69968d4

Browse files
committedNov 4, 2021
Update readme
1 parent bcc718d commit 69968d4

File tree

5 files changed

+116
-18
lines changed

5 files changed

+116
-18
lines changed
 

‎media/bytetree.png

-8.51 KB
Binary file not shown.

‎media/truwrap.png

-30 KB
Binary file not shown.

‎readme.md

+58-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
[![Inch.io](https://inch-ci.org/github/thebespokepixel/truwrap.svg?branch=master\&style=shields "Inch.io")](https://inch-ci.org/github/thebespokepixel/truwrap "Inch.io") [![Twitter](https://img.shields.io/twitter/follow/thebespokepixel?style=social "Twitter")](https://twitter.com/thebespokepixel "Twitter") 
2020

2121

22+
> **v4 Breaking change** The CLI command has been seperated into it's own repo [`truwrap-cli`][2]
23+
2224
Many current tty text wrapping solutions have issues with the 'long' and currently 'non-standard' RGB SGR codes (i.e `^[[38;2;204;51;66m`). This meant that, while it's possible to have wonderful, rich, full gamut colours and the aesthetic data visualisations it entails, it comes at the price of painful typography and corrupted console displays as text is broken up, unnaturally wrapped and becoming unreadable as the SGR codes are dashed against the rocks of 1980's shortsightedness, confusing your terminal and ever so slightly breaking the heart of design aware coders and administrators everywhere.
2325

2426
_Clearly this is unnacceptable!_
@@ -27,11 +29,7 @@ Previously, the only solution was to take a last, long whistful look at how grea
2729

2830
But weep no more!
2931

30-
Developed as part of our internal data visualisation system, where having the fidelity of 24 bit colour and embedded images (currently OS X iTerm 3 only) was a huge advantage.
31-
32-
Usable within your own node.js cli projects and an npm module or directly from the command line as a shell scripting command.
33-
34-
![Screengrab][grab]
32+
Developed as part of our internal data visualisation system, where having the fidelity of 24 bit colour and embedded images (currently macOS iTerm only) was a huge advantage.
3533

3634
## Usage
3735

@@ -55,12 +53,63 @@ var contentWidth = writer.getWidth()
5553

5654
writer.write("Some text to write...", "...and some more.")
5755
writer.write("A new paragraph, if not implicitly present.")
58-
writer.end()
56+
writer.end() // Close the stream
57+
```
58+
As `outStream` was specified, wrapped output is written directly to the stream.
59+
60+
### Images
61+
62+
```js
63+
import {truwrap, createImage} from '@thebespokepixel/truwrap'
64+
65+
const image = createImage({
66+
name: 'test',
67+
file: join(dirname(fileURLToPath(import.meta.url)), '../media/test.png'),
68+
height: 1,
69+
})
70+
71+
var renderer = truwrap({
72+
mode: 'container'
73+
})
74+
75+
truwrap.write(image.render({
76+
nobreak: false,
77+
align: 1
78+
}))
79+
80+
console.log(truwrap.end())
5981
```
6082
61-
### Advanced use
83+
As no `outStream` was specified `truwrap.end()` returns the wrapped text.
84+
85+
### Panels
86+
87+
```js
88+
import {truwrap, parsePanel} from '@thebespokepixel/truwrap'
89+
90+
var writer = truwrap({
91+
left: 2,
92+
right: 2,
93+
mode: 'soft',
94+
outStream: process.stderr
95+
})
6296

63-
To add. Containers, Tables, Panels and Images.
97+
const panelSource = parsePanel(
98+
'One|Two|Three|Four', //Input text with column delimiters
99+
'|', // Column delimiter
100+
writer.getWidth() // Total width (chars) to make columns across
101+
)
102+
103+
const panelOptions = {
104+
maxLineWidth: writer.getWidth(), // Maximum line width
105+
showHeaders: false, // Show colum headers
106+
truncate: false, // Truncate columns if too wide
107+
config: panelSource.configuration // Get config information from parsePanel()
108+
}
109+
110+
writer.panel(panelSource.content, panelOptions)
111+
writer.end() //Close stream
112+
```
64113
65114
### Related
66115
@@ -71,4 +120,4 @@ For advanced 24bit colour handling see [thebespokepixel/trucolor](https://github
71120
Full documentation can be found at [https://thebespokepixel.github.io/truwrap/][1]
72121
73122
[1]: https://thebespokepixel.github.io/truwrap/
74-
[grab]: https://raw.githubusercontent.com/thebespokepixel/truwrap/master/media/truwrap.png
123+
[2]: https://github.com/thebespokepixel/truwrap-cli

‎src/docs/example.md

+54-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,63 @@ var contentWidth = writer.getWidth()
1818

1919
writer.write("Some text to write...", "...and some more.")
2020
writer.write("A new paragraph, if not implicitly present.")
21-
writer.end()
21+
writer.end() // Close the stream
2222
```
23+
As `outStream` was specified, wrapped output is written directly to the stream.
2324

24-
### Advanced use
25+
### Images
2526

26-
To add. Containers, Tables, Panels and Images.
27+
```js
28+
import {truwrap, createImage} from '@thebespokepixel/truwrap'
29+
30+
const image = createImage({
31+
name: 'test',
32+
file: join(dirname(fileURLToPath(import.meta.url)), '../media/test.png'),
33+
height: 1,
34+
})
35+
36+
var renderer = truwrap({
37+
mode: 'container'
38+
})
39+
40+
truwrap.write(image.render({
41+
nobreak: false,
42+
align: 1
43+
}))
44+
45+
console.log(truwrap.end())
46+
```
47+
48+
As no `outStream` was specified `truwrap.end()` returns the wrapped text.
49+
50+
### Panels
51+
52+
```js
53+
import {truwrap, parsePanel} from '@thebespokepixel/truwrap'
54+
55+
var writer = truwrap({
56+
left: 2,
57+
right: 2,
58+
mode: 'soft',
59+
outStream: process.stderr
60+
})
61+
62+
const panelSource = parsePanel(
63+
'One|Two|Three|Four', //Input text with column delimiters
64+
'|', // Column delimiter
65+
writer.getWidth() // Total width (chars) to make columns across
66+
)
67+
68+
const panelOptions = {
69+
maxLineWidth: writer.getWidth(), // Maximum line width
70+
showHeaders: false, // Show colum headers
71+
truncate: false, // Truncate columns if too wide
72+
config: panelSource.configuration // Get config information from parsePanel()
73+
}
74+
75+
writer.panel(panelSource.content, panelOptions)
76+
writer.end() //Close stream
77+
```
2778
2879
### Related
2980

‎src/docs/readme.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
${badges}
66

7+
> **v4 Breaking change** The CLI command has been seperated into it's own repo [`truwrap-cli`][2]
8+
79
Many current tty text wrapping solutions have issues with the 'long' and currently 'non-standard' RGB SGR codes (i.e `^[[38;2;204;51;66m`). This meant that, while it's possible to have wonderful, rich, full gamut colours and the aesthetic data visualisations it entails, it comes at the price of painful typography and corrupted console displays as text is broken up, unnaturally wrapped and becoming unreadable as the SGR codes are dashed against the rocks of 1980's shortsightedness, confusing your terminal and ever so slightly breaking the heart of design aware coders and administrators everywhere.
810

911
_Clearly this is unnacceptable!_
@@ -12,11 +14,7 @@ Previously, the only solution was to take a last, long whistful look at how grea
1214

1315
But weep no more!
1416

15-
Developed as part of our internal data visualisation system, where having the fidelity of 24 bit colour and embedded images (currently OS X iTerm 3 only) was a huge advantage.
16-
17-
Usable within your own node.js cli projects and an npm module or directly from the command line as a shell scripting command.
18-
19-
![Screengrab][grab]
17+
Developed as part of our internal data visualisation system, where having the fidelity of 24 bit colour and embedded images (currently macOS iTerm only) was a huge advantage.
2018

2119
## Usage
2220

@@ -26,4 +24,4 @@ ${usage}
2624
Full documentation can be found at [https://thebespokepixel.github.io/truwrap/][1]
2725

2826
[1]: https://thebespokepixel.github.io/truwrap/
29-
[grab]: https://raw.githubusercontent.com/thebespokepixel/truwrap/master/media/truwrap.png
27+
[2]: https://github.com/thebespokepixel/truwrap-cli

0 commit comments

Comments
 (0)
Please sign in to comment.