haskell-boxes / boxes Goto Github PK
View Code? Open in Web Editor NEWA pretty-printing library for laying out text in two dimensions, using a simple box model.
License: Other
A pretty-printing library for laying out text in two dimensions, using a simple box model.
License: Other
<>
in Boxes shadows the usual semigroup operation, while functioning in a compatible way. (I am ignoring the internal hierarchical representation for now. Be it necessary, we can perform simplification when concatenating.) There is also nullBox
that we can make neutral element.
Surely this will simplify the usage of this package in the modern ecosystem.
I can take a shot at making the necessary adjustments.
Hello,
Thanks for sharing boxes.
Just want to check if @rustydc boxes code can be packaged as a text-boxes or such package?
Thanks
Support by various terminals, etc., is likely limited, but it's worth looking into. There are languages that run right to left; on their own, these should pose no challenge (right and left just swap), but mixing them with left to right will be somewhat challenging. There are also languages that are written primarily from top to bottom, then from left to right or right to left. These would likely be much harder to mix with LTR/RTL in this form, but it may not be entirely necessary, as these languages sometimes/often can be written LTR or RTL.
λ rows "x\ny"
1
I think there should be as many rows in the text
box as there are lines in the text, and as many columns as there are characters in the longest of lines.
text
simply measures the length of the string for the column count, and there is always just one row.
Currently, boxes
is not included in any Stackage snapshots:
https://www.stackage.org/package/boxes
This means (among other things) that packages which depend upon boxes
can't be built with the new stack
build tool:
https://github.com/commercialhaskell/stack
Including a package in Stackage is up to the package owner:
https://github.com/fpco/stackage/#get-your-package-included
The suggested approach seems to be to get the package building with Travis (to make sure it builds with latest dependencies, etc.), and then submit a PR against stackage.
It would be great it boxes
can be added to Stackage.
I have vertically stacked text boxes of differing widths. When rendered they are all right padded with white spaces. A single box of large width causes lots of padded small boxes. The padding allows additional line breaks in a terminal if it is too narrow. Although this behavior is correct it can be annoying.
How about an alternative rendering function that emits only the spaces that are necessary for formatting? Maybe it should even be a rendering function that allows formatting options that can be extended in the future.
using modified function from #5
but para left 50
instead of text
formatTable :: [Alignment] -> Int -> [[String]] -> Box
formatTable als sep cols = punctuateH top sep' $ map (uncurry singleCol) colal
where als' = cycle als
cols' = transpose cols
colal = zip als' cols'
sep' = emptyBox 0 sep
singleCol :: Alignment -> [String] -> Box
singleCol al = vcat al . map (para left 50 {- note this -})
main = do
putStrLn $ render $ formatTable [ left, left ] 2
[ [ "HELLO", "1111111111 11111111 1111111 1111111111 11111111 1111111 1111111111 11111111 1111111", "222222222 22222222 2222222222 222222222 22222222 2222222222" ]
, [ "HELLO", "333333333 33333333 3333333333 333333333 33333333 3333333333", "444444444 44444444 4444444444 444444444 44444444 4444444444" ]
, [ "HELLO", "555555555 55555555 5555555555 555555555 55555555 5555555555", "666666666 66666666 6666666666 666666666 66666666 6666666666" ]
]
outputs
HELLO 1111111111 11111111 1111111 1111111111 11111111 222222222 22222222 2222222222 222222222 22222222
HELLO 1111111 1111111111 11111111 1111111 2222222222
HELLO 333333333 33333333 3333333333 333333333 33333333 444444444 44444444 4444444444 444444444 44444444
3333333333 4444444444
555555555 55555555 5555555555 555555555 55555555 666666666 66666666 6666666666 666666666 66666666
5555555555 6666666666
but expected
HELLO 1111111111 11111111 1111111 1111111111 11111111 222222222 22222222 2222222222 222222222 22222222
1111111 1111111111 11111111 1111111 2222222222
HELLO 333333333 33333333 3333333333 333333333 33333333 444444444 44444444 4444444444 444444444 44444444
3333333333 4444444444
HELLO 555555555 55555555 5555555555 555555555 55555555 666666666 66666666 6666666666 666666666 66666666
5555555555 6666666666
We need to set up a .travis.yml
file to get Travis to test things automatically.
GHC 8.4.1-alpha1 was announced. While testing Agda with this version of GHC, I got the following error on boxes (master branch):
$ cabal install
...
Text/PrettyPrint/Boxes.hs:33:7: error:
Ambiguous occurrence ‘<>’
It could refer to either ‘Prelude.<>’,
imported from ‘Prelude’ at Text/PrettyPrint/Boxes.hs:82:1-28
(and originally defined in ‘GHC.Base’)
or ‘Text.PrettyPrint.Boxes.<>’,
defined at Text/PrettyPrint/Boxes.hs:183:3
|
33 | , (<>)
| ^^^^
Failed to install boxes-0.1.4
Blocking agda/agda#2878.
We're using cabal, so we should use it to run the tests too.
Agda is by far the most important package depending on this one; I want to be aware of any breakage in Agda builds induced by future changes here. I don't know how to set that up, and I don't know if it's possible to do it cheaply enough, but it would be very nice.
The boxes library doesn't support GHC 8.2.1 because the split library doesn't (see http://hub.darcs.net/byorgey/split/issue/7).
Hi,
I think the package documentation (as shown on hackage) and the haddock of the module could use some example of what kind of output your tool produces.
Greetings,
Joachim
I had to disable all but one of the QuickCheck properties to avoid using more thyme than I had available and far too many rams. I suspect the Arbitrary
instances aren't quite right, but I'm not sure.
Please replace
git clone git://github.com/treeowl/boxes.git
by
git clone https://github.com/treeowl/boxes.git
in boxes.cabal
.
#1 suggests a Text
interface, but we might also want to look into things like nroff, LaTeX, PostScript, and (though this may be trying to fit a square peg in a round hole) HTML/CSS.
The hackage version of this package currently doesn't include the update to split 0.2.*. Could you please upload a new version with the dependency update included?
I like to format text containing ANSI escape sequences for adding color to texts.
Built-in support for ANSI sequences might be too complex and too unflexible.
Maybe we can implement it using zero-width boxes that contain escape sequences that have zero width on the screen. However, it could be difficult to align escape sequences to the corresponding text.
Alternatively, maybe Box
can be generalized to element types other than Char
. We could then decorate Char
values and convert to ANSI sequences after layout by boxes
.
The title says it all. Nevertheless, an example:
λ printBox $ frame "^_^"
+---+
|^_^|
+---+
Of course, we may use fancier ASCII line art too.
I also propose that there is a similar function for a double frame.
Eventually we could render tables like this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.