c-cube / printbox

print nested boxes, lists, arrays, tables in several formats
https://c-cube.github.io/printbox/
BSD 2-Clause "Simplified" License
77 stars 10 forks source link

basic styling + center #8

Closed c-cube closed 4 years ago

c-cube commented 4 years ago

cc @grayswandyr please give it a try. It only works on the text part (line,lines,text)

2019-11-11-163938_822x247_scrot

grayswandyr commented 4 years ago

Hi, I will try tool into it this week, I will update you.

c-cube commented 4 years ago

preview of the "center" feature in this PR (along with bugfixes on master):

+---------------------------------------+
|the center of the triangle is        | |
|-------------------------------------+-|
|                                     | |
|                                     | |
|                                     | |
|                                     | |
|                                     | |
|                                     | |
|                                     |t|
|             lil' ol' me             |a|
|                                     |l|
|                                     |l|
|                                     | |
|                                     | |
|                                     | |
|                                     | |
|                                     | |
|                                     | |
|-------------------------------------+-|
|                    i'm aligned right| |
|-------------------------------------+-|
|loooooooooooooooooooooooooooooooooong| |
+---------------------------------------+

+----------+
|name1| foo|
|-----+----|
|    1|true|
+----------+
+-----------------------------+
|a |looooooooooooooooooooooooo|
|  |oonng                     |
|--+--------------------------|
|bx|                     +---+|
|  |                     |x|y||
|  |                     |-+-||
|  |                     |1|2||
|  |                     +---+|
+-----------------------------+
+------------------------------------+
|nice unicode! 💪                    |
|------------------------------------|
|+----------------------------------+|
||oï ωεird nums:|+-----------------+||
||Ï€/2           ||+---------------+|||
||Ï„/4           |||+-------------+||||
||--------------||||sum=Σ_i a·xᵢ²|||||
||              ||||—————        |||||
||              ||||1+1          |||||
||  0           ||||-------------|||||
||  `+- 1       ||||           Ōₒ|||||
||   +- ω       ||||           À |||||
||      `+- ω²  |||+-------------+||||
||              ||+---------------+|||
||              |+-----------------+||
|+----------------------------------+|
+------------------------------------+
c-cube commented 4 years ago

should be all good. @grayswandyr did you have time to take a look? :)

grayswandyr commented 4 years ago

I started but I'll only be able to to do it during this week-end. If it's not too long for you...

c-cube commented 4 years ago

That's ok, there's no hurry, and @Gbury is also reviewing the rendering code :)

grayswandyr commented 4 years ago

I have to adapt my code because I used to massage a string array before converting it into a grid. I need to refactor the code to be able to use the styling options (as a t is abstract, I can't apply styling options if the underlying string is equal to some thing).

c-cube commented 4 years ago

Note that there's now grid_l if you prefer lists :-) The API is a bit richer now.

grayswandyr commented 4 years ago

Hi from what I tested (in particular applying font styles and init_grid), everything was OK. Cool. Thanks!