diff options
Diffstat (limited to 'vendor/tabled/examples')
53 files changed, 3644 insertions, 0 deletions
diff --git a/vendor/tabled/examples/README.md b/vendor/tabled/examples/README.md new file mode 100644 index 000000000..51c9d2e1c --- /dev/null +++ b/vendor/tabled/examples/README.md @@ -0,0 +1,831 @@ +This file contains an overview of examples. + +- `derive` folder contains a list of examples which uses different `#[derive(Tabled)]` attributes. +- `show` folder contains a program which uses different styles and prints the resulting table. +- `terminal_size` folder contains a program which spreads the table to the max terminal width and max terminal height. + You can use which dimension to use via args `--width`, `--height` by default 2 are used. + +Bellow there's a list of results of running some examples. + +## table + +``` +| name | based_on | is_active | is_cool | +|---------|----------|-----------|---------| +| Manjaro | Arch | true | true | +| Arch | | true | true | +| Debian | | true | true | +``` + +## border_text + +``` + Numbers ─┬────┬────┬────┐ +│ 0 │ 1 │ 2 │ 3 │ 4 │ + More numbers ─┼────┼────┤ +│ 5 │ 6 │ 7 │ 8 │ 9 │ +│ 10 │ 11 │ 12 │ 13 │ 14 │ + end. ────┴────┴────┴────┘ +``` + +## builder_index + +``` +┌───────────┬─────────┬──────┬────────┐ +│ │ Manjaro │ Arch │ Debian │ +├───────────┼─────────┼──────┼────────┤ +│ based_on │ Arch │ None │ None │ +├───────────┼─────────┼──────┼────────┤ +│ is_active │ true │ true │ true │ +├───────────┼─────────┼──────┼────────┤ +│ is_cool │ true │ true │ true │ +└───────────┴─────────┴──────┴────────┘ +``` + +## builder + +``` +| https://en.wikipedia.org/wiki/Ocean | +|---------------+---------------------| +| The terms "the ocean" or "the sea" | +| used without specification refer to | +| the interconnected body of salt wa | +| ter covering the majority of the Ea | +| rth's surface | +| =================================== | +| # | Ocean | +| 0 | Atlantic | +| 1 | Pacific | +| 2 | Indian | +| 3 | Southern | +| 4 | Arctic | +``` + +## chess + +<picture> + <source media="(prefers-color-scheme: dark)" srcset="https://github.com/zhiburt/tabled/assets/20165848/f474bc84-5ed4-4f49-b6e9-fc204c3ecd5d"> + <img alt="Preview" src="https://github.com/zhiburt/tabled/assets/20165848/68960bba-c5ba-4e0a-85b4-ba4f36bc0ed0"> +</picture> + +## col_row_macros + +``` ++-------------------------------------------+---------------------------------------------+ +| .---------------------------------------. | ┌────────────────────┬─────┬──────────────┐ | +| | name | age | is_validated | | │ name │ age │ is_validated │ | +| | Jon Doe | 255 | false | | ├────────────────────┼─────┼──────────────┤ | +| | Mark Nelson | 13 | true | | │ Jack Black │ 51 │ false │ | +| | Terminal Monitor | 0 | false | | ├────────────────────┼─────┼──────────────┤ | +| | Adam Blend | 17 | true | | │ Michelle Goldstein │ 44 │ true │ | +| '---------------------------------------' | └────────────────────┴─────┴──────────────┘ | ++-------------------------------------------+---------------------------------------------+ ++-------------------------------------------+ +| .---------------------------------------. | +| | name | age | is_validated | | +| | Jon Doe | 255 | false | | +| | Mark Nelson | 13 | true | | +| | Terminal Monitor | 0 | false | | +| | Adam Blend | 17 | true | | +| '---------------------------------------' | ++-------------------------------------------+ +| .---------------------------------------. | +| | name | age | is_validated | | +| | Jon Doe | 255 | false | | +| | Mark Nelson | 13 | true | | +| | Terminal Monitor | 0 | false | | +| | Adam Blend | 17 | true | | +| '---------------------------------------' | ++-------------------------------------------+ +| .---------------------------------------. | +| | name | age | is_validated | | +| | Jon Doe | 255 | false | | +| | Mark Nelson | 13 | true | | +| | Terminal Monitor | 0 | false | | +| | Adam Blend | 17 | true | | +| '---------------------------------------' | ++-------------------------------------------+ ++-------------------------------------------------------------------------------+ +| +-------+-----+--------------+ ┌────────────────────┬─────┬──────────────┐ | +| | name | age | is_validated | │ name │ age │ is_validated │ | +| +-------+-----+--------------+ ├────────────────────┼─────┼──────────────┤ | +| | Sam | 31 | true | │ Jack Black │ 51 │ false │ | +| +-------+-----+--------------+ ├────────────────────┼─────┼──────────────┤ | +| | Sarah | 26 | true | │ Michelle Goldstein │ 44 │ true │ | +| +-------+-----+--------------+ └────────────────────┴─────┴──────────────┘ | ++-------------------------------------------------------------------------------+ +| .---------------------------------------. | +| | name | age | is_validated | | +| | Jon Doe | 255 | false | | +| | Mark Nelson | 13 | true | | +| | Terminal Monitor | 0 | false | | +| | Adam Blend | 17 | true | | +| '---------------------------------------' | ++-------------------------------------------------------------------------------+ +``` + +## color + +<picture> + <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/zhiburt/tabled/assets/assets/example-color-1-dark.png"> + <img alt="Preview" src="https://raw.githubusercontent.com/zhiburt/tabled/assets/assets/example-color-1-light.png"> +</picture> + +## colored_borders + +<picture> + <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/zhiburt/tabled/assets/assets/example-colored_borders-1-dark.png"> + <img alt="Preview" src="https://raw.githubusercontent.com/zhiburt/tabled/assets/assets/example-colored_borders-1-light.png"> +</picture> + +## colored_padding + +<picture> + <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/zhiburt/tabled/assets/assets/example-padding_color-1-dark.png"> + <img alt="Preview" src="https://raw.githubusercontent.com/zhiburt/tabled/assets/assets/example-padding_color-1-light.png"> +</picture> + +## colorization + +<picture> + <source media="(prefers-color-scheme: dark)" srcset="https://github.com/zhiburt/tabled/assets/20165848/95ef3c5b-a86d-425c-b95a-b689b61734c5"> + <img alt="Preview" src="https://github.com/zhiburt/tabled/assets/20165848/b6b8af0a-7c1f-4656-b880-c8ecd130c5be"> +</picture> + +## column_names + + +<picture> + <source media="(prefers-color-scheme: dark)" srcset="https://github.com/zhiburt/tabled/assets/20165848/82d8e285-3c1b-4dd2-a1f4-45fd49f0dabe"> + <img alt="Preview" src="https://github.com/zhiburt/tabled/assets/20165848/13054c74-0fae-4df1-87e8-60d498d734e4"> +</picture> + +## concat + +``` + temperature_c wind_ms latitude longitude + 16 3000 111.111 333.333 + -20 300 5.111 7282.1 + 40 100 0 0 + 0 0 +``` + +## custom_style + +``` +┌────────────────────┬─────────────────────────────────┐ +│ name │ first_release developer │ +├────────────────────┼─────────────────────────────────┤ +│ Sublime Text 3 │ 2008 Sublime HQ │ +│ Visual Studio Code │ 2015 Microsoft │ +│ Notepad++ │ 2003 Don Ho │ +│ GNU Emacs │ 1984 Richard Stallman │ +│ Neovim │ 2015 Vim community │ +└────────────────────┴─────────────────────────────────┘ +``` + +## disable + +``` +########### +# name # based_on | is_cool | +###########----------|---------| +# Debian # | true | +########### +# Arch # | true | +########### +# Manjaro # Arch | true | +########### +``` + +## expanded_display + +``` +-[ RECORD 0 ]------ +name | Manjaro +based_on | Arch +is_active | true +is_cool | true +-[ RECORD 1 ]------ +name | Arch +based_on | +is_active | true +is_cool | true +-[ RECORD 2 ]------ +name | Debian +based_on | +is_active | true +is_cool | true +``` + +## extract + +``` +┌───────────────┬───────────────────────────┬──────────────────┬────────────────────┐ +│ artist │ name │ released │ level_of_greatness │ +├───────────────┼───────────────────────────┼──────────────────┼────────────────────┤ +│ Pink Floyd │ The Dark Side of the Moon │ 01 March 1973 │ Unparalleled │ +├───────────────┼───────────────────────────┼──────────────────┼────────────────────┤ +│ Fleetwood Mac │ Rumours │ 04 February 1977 │ Outstanding │ +├───────────────┼───────────────────────────┼──────────────────┼────────────────────┤ +│ Led Zeppelin │ Led Zeppelin IV │ 08 November 1971 │ Supreme │ +└───────────────┴───────────────────────────┴──────────────────┴────────────────────┘ + +┼───────────────────────────┼──────────────────┼──────────────┤ +│ The Dark Side of the Moon │ 01 March 1973 │ Unparalleled │ +┼───────────────────────────┼──────────────────┼──────────────┤ +│ Rumours │ 04 February 1977 │ Outstanding │ +┼───────────────────────────┼──────────────────┼──────────────┤ + +┌───────────────────────────┬──────────────────┬───────────────┐ +│ The Dark Side of the Moon │ 01 March 1973 │ Unparalleled │ +├───────────────────────────┼──────────────────┼───────────────┤ +│ Rumours │ 04 February 1977 │ +Outstanding+ │ +└───────────────────────────┴──────────────────┴───────────────┘ +``` + +## format + +``` + 0 | 1 | 2 +---------------------------------------------+--------------------------------+------------------------- + 8ae4e8957caeaa467acbce963701e227af00a1c7... | bypass open-source transmitter | index neural panel + 48c76de71bd685486d97dc8f4f05aa6fcc0c3f86... | program online alarm | copy bluetooth card + 6ffc2a2796229fc7bf59471ad907f58b897005d0... | CSV | reboot mobile capacitor +``` + +## formatting_settings + +``` +╭───────────────────╮ +│ &str │ +├───────────────────┤ +│ │ +│ [ │ +│ "foo", │ +│ { │ +│ "bar": 1, │ +│ "baz": [ │ +│ 2, │ +│ 3 │ +│ ] │ +│ } │ +│ ] │ +╰───────────────────╯ + +╭───────────────────╮ +│ &str │ +├───────────────────┤ +│ │ +│ [ │ +│ "foo", │ +│ { │ +│ "bar": 1, │ +│ "baz": [ │ +│ 2, │ +│ 3 │ +│ ] │ +│ } │ +│ ] │ +╰───────────────────╯ + +╭───────────────────╮ +│ &str │ +├───────────────────┤ +│ [ │ +│ "foo", │ +│ { │ +│ "bar": 1, │ +│ "baz": [ │ +│ 2, │ +│ 3 │ +│ ] │ +│ } │ +│ ] │ +│ │ +╰───────────────────╯ +``` + +## highlight + +``` +************* +* 0 │ 1 │ 2 * +*****───***** +│ A * B * C │ +├───*───*───┤ +│ D * E * F │ +├───*───*───┤ +│ G * H * I │ +└───*****───┘ +``` + +## margin + +``` +vvvvvvvvvvvvvvvvvv +vvvvvvvvvvvvvvvvvv +<<<<=== === ===>>> +<<<< 0 1 2 >>> +<<<<=== === ===>>> +<<<< A B C >>> +<<<< D E F >>> +<<<< G H I >>> +<<<<=== === ===>>> +^^^^^^^^^^^^^^^^^^ +``` + +## nested_table + +``` ++-----------------------------------------------+ +| +---------------------+ | +| | Animal | | +| +---------------------+ | +| | +-----------------+ | | +| | | +age: Int | | | +| | | +gender: String | | | +| | +-----------------+ | | +| | +-----------------+ | | +| | | +isMammal() | | | +| | | +mate() | | | +| | +-----------------+ | | +| +---------------------+ | +| ▲ | +| | | +| | | +| +-----------------------------------+ | +| | Duck | | +| +-----------------------------------+ | +| | +-------------------------------+ | | +| | | +beakColor: String = "yellow" | | | +| | +-------------------------------+ | | +| | +-------------------------------+ | | +| | | +swim() | | | +| | | +quack() | | | +| | +-------------------------------+ | | +| +-----------------------------------+ | ++-----------------------------------------------+ +``` + +## nested_table_2 + +``` +┌───────┬─────────────────────────────────────────────────┬──────────────────────────────────────────────┐ +│ name │ main_os │ switch_os │ +├───────┼─────────────────────────────────────────────────┼──────────────────────────────────────────────┤ +│ Azure │ ╔═════════╦═════════════╦═══════════╦═════════╗ │ ╔═════════╦══════════╦═══════════╦═════════╗ │ +│ │ ║ name ║ based_on ║ is_active ║ is_cool ║ │ ║ name ║ based_on ║ is_active ║ is_cool ║ │ +│ │ ╠═════════╬═════════════╬═══════════╬═════════╣ │ ╠═════════╬══════════╬═══════════╬═════════╣ │ +│ │ ║ Windows ║ Independent ║ true ║ true ║ │ ║ Manjaro ║ Arch ║ true ║ true ║ │ +│ │ ╚═════════╩═════════════╩═══════════╩═════════╝ │ ╚═════════╩══════════╩═══════════╩═════════╝ │ +├───────┼─────────────────────────────────────────────────┼──────────────────────────────────────────────┤ +│ AWS │ ╔════════╦═════════════╦═══════════╦═════════╗ │ ╔══════╦═════════════╦═══════════╦═════════╗ │ +│ │ ║ name ║ based_on ║ is_active ║ is_cool ║ │ ║ name ║ based_on ║ is_active ║ is_cool ║ │ +│ │ ╠════════╬═════════════╬═══════════╬═════════╣ │ ╠══════╬═════════════╬═══════════╬═════════╣ │ +│ │ ║ Debian ║ Independent ║ true ║ true ║ │ ║ Arch ║ Independent ║ true ║ true ║ │ +│ │ ╚════════╩═════════════╩═══════════╩═════════╝ │ ╚══════╩═════════════╩═══════════╩═════════╝ │ +├───────┼─────────────────────────────────────────────────┼──────────────────────────────────────────────┤ +│ GCP │ ╔════════╦═════════════╦═══════════╦═════════╗ │ ╔══════╦═════════════╦═══════════╦═════════╗ │ +│ │ ║ name ║ based_on ║ is_active ║ is_cool ║ │ ║ name ║ based_on ║ is_active ║ is_cool ║ │ +│ │ ╠════════╬═════════════╬═══════════╬═════════╣ │ ╠══════╬═════════════╬═══════════╬═════════╣ │ +│ │ ║ Debian ║ Independent ║ true ║ true ║ │ ║ Arch ║ Independent ║ true ║ true ║ │ +│ │ ╚════════╩═════════════╩═══════════╩═════════╝ │ ╚══════╩═════════════╩═══════════╩═════════╝ │ +└───────┴─────────────────────────────────────────────────┴──────────────────────────────────────────────┘ +``` + +## nested_table_3 + +``` +************************************************* +* Thank You * +************************************************* +| +------------+------------------------------+ | +| | Contributors | | +| +------------+------------------------------+ | +| | author | profile | | +| +------------+------------------------------+ | +| | kozmod | https:/github.com/kozmod | | +| +------------+------------------------------+ | +| | IsaacCloos | https:/github.com/IsaacCloos | | +| +------------+------------------------------+ | +| +-----------+-----------------------------+ | +| | Issuers | | +| +-----------+-----------------------------+ | +| | author | profile | | +| +-----------+-----------------------------+ | +| | aharpervc | https:/github.com/aharpervc | | +| +-----------+-----------------------------+ | ++-----------------------------------------------+ +``` + +## panel + +``` +┌───┬────────────────────────────────────────────────────────────────────┬───┐ +│ S │ Tabled Releases │ S │ +│ o │ │ o │ +│ m │ │ m │ +│ e │ │ e │ +│ ├─────────┬────────────────┬───────────┬─────────────────────────────┤ │ +│ t │ version │ published_date │ is_active │ major_feature │ t │ +│ e │ │ │ │ │ e │ +│ x ├─────────┼────────────────┼───────────┼─────────────────────────────┤ x │ +│ t │ 0.2.1 │ 2021-06-23 │ true │ #[header(inline)] attribute │ t │ +│ │ │ │ │ │ │ +│ g ├─────────┼────────────────┼───────────┼─────────────────────────────┤ g │ +│ o │ 0.2.0 │ 2021-06-19 │ false │ API changes │ o │ +│ e │ │ │ │ │ e │ +│ s ├─────────┼────────────────┼───────────┼─────────────────────────────┤ s │ +│ │ 0.1.4 │ 2021-06-07 │ false │ display_with attribute │ │ +│ h │ │ │ │ │ h │ +│ e ├─────────┴────────────────┴───────────┴─────────────────────────────┤ e │ +│ r │ N - 3 │ r │ +│ e │ │ e │ +└───┴────────────────────────────────────────────────────────────────────┴───┘ +``` + +## print_matrix + +``` +┌────┬────┬────┬────┬────┬────┬────┬────┬────┬─────┐ +│ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 2 │ 4 │ 6 │ 8 │ 10 │ 12 │ 14 │ 16 │ 18 │ 20 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 3 │ 6 │ 9 │ 12 │ 15 │ 18 │ 21 │ 24 │ 27 │ 30 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 4 │ 8 │ 12 │ 16 │ 20 │ 24 │ 28 │ 32 │ 36 │ 40 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 5 │ 10 │ 15 │ 20 │ 25 │ 30 │ 35 │ 40 │ 45 │ 50 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 6 │ 12 │ 18 │ 24 │ 30 │ 36 │ 42 │ 48 │ 54 │ 60 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 7 │ 14 │ 21 │ 28 │ 35 │ 42 │ 49 │ 56 │ 63 │ 70 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 8 │ 16 │ 24 │ 32 │ 40 │ 48 │ 56 │ 64 │ 72 │ 80 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 9 │ 18 │ 27 │ 36 │ 45 │ 54 │ 63 │ 72 │ 81 │ 90 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 10 │ 20 │ 30 │ 40 │ 50 │ 60 │ 70 │ 80 │ 90 │ 100 │ +└────┴────┴────┴────┴────┴────┴────┴────┴────┴─────┘ +``` + +## rotate + +``` ++--------------+------------------------+---------------------------+--------------------------+ +| link | https://getfedora.org/ | https://www.opensuse.org/ | https://endeavouros.com/ | ++--------------+------------------------+---------------------------+--------------------------+ +| destribution | Fedora | OpenSUSE | Endeavouros | ++--------------+------------------------+---------------------------+--------------------------+ +| id | 0 | 2 | 3 | ++--------------+------------------------+---------------------------+--------------------------+ +``` + +## shadow + +``` +┌──┬┐ ╔══╦╗ ╓──┬╖ ╒═╤╕ +│ ││ ║ ║║ ║ │║ │ ││ +├──┼┤ ╠══╬╣ ╟──┼╢ ╞═╪╡ +└──┴┘ ╚══╩╝ ╙──┴╜ ╘═╧╛ +┌──────────────────┐ +│ ╔═══╗ Some text │▒▒ +│ ╚═╦═╝ In the box│▒▒ +╞═╤══╩══╤══════════╡▒▒ +│ ├──┬──┤ │▒▒ +│ └──┴──┘ │▒▒ +└──────────────────┘▒▒ + ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ + ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ +``` + +## span + +``` +┌───────────────────────────────────────────────────────────────────────────────┐ +│ span all 5 columns │ +├───────────────────────────────────────────────────────────────┬───────────────┤ +│ span 4 columns │ just 1 column │ +├───────────────────────────────┬───────────────┬───────────────┼───────────────┤ +│ span 2 columns │ just 1 column │ │ │ +├───────────────┬───────────────┴───────────────┤ just 1 column │ │ +│ just 1 column │ span 2 columns │ span │ just 1 column │ +│ │ span │ 3 │ span │ +├───────────────┤ 2 │ columns │ 4 │ +│ just 1 column │ columns │ │ columns │ +├───────────────┼───────────────┬───────────────┼───────────────┤ │ +│ just 1 column │ just 1 column │ just 1 column │ just 1 column │ │ +└───────────────┴───────────────┴───────────────┴───────────────┴───────────────┘ +``` + +## table_width + +``` +| 0 | 1 | +|------------------|-----------| +| Hello World!!! | 3.3.22.2 | +| Guten Morgen | 1.1.1.1 | +| Добры вечар | 127.0.0.1 | +| Bonjour le monde | | +| Ciao mondo | | + +| 0 | 1 | +|------------|-----| +| Hello W... | ... | +| Guten M... | ... | +| Добры в... | ... | +| Bonjour... | | +| Ciao mondo | | + +| 0 | 1 | +|-------|-----| +| Hello | ... | +| W... | | +| Guten | ... | +| M... | | +| Добры | ... | +| в... | | +| Bonjo | | +| ur... | | +| Ciao | | +| mondo | | + +| 0 | 1 | +|---------------|------------| +| Hello | ... | +| W... | | +| Guten | ... | +| M... | | +| Добры | ... | +| в... | | +| Bonjo | | +| ur... | | +| Ciao | | +| mondo | | +``` + +## table_width_2 + +``` +.----------------------------------------. +| usize | &str | +| 0 | # Changelog | +| 1 | All notable changes to this | +| | projectwill be documented in | +| | thisfile. | +| 2 | The format is based on [Keep a | +| | Changelog](https://keepachange | +| | log.com/en/1.0.0/), | +| 3 | and this project adheres to | +| | [SemanticVersioning](https://s | +| | emver.org/spec/v2.0.0.html). | +| 4 | ## Unreleased | +'-------+--------------------------------' +``` + +## alphabet + +``` ++---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +| a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | ++---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +``` + +## compact_table + +``` +| Debian | | true | +|-------|-----|-----| +| Arch | | true | +| Manjaro | Arch | true | +``` + +## compact_table_2 + +``` + Debian | 1.1.1.1 | true +---------+-----------+------ + Arch | 127.1.1.1 | true + Manjaro | Arch | true +``` + +## extended_display + +``` +-[ RECORD 0 ]------ +name | Manjaro +based_on | Arch +is_active | true +is_cool | true +-[ RECORD 1 ]------ +name | Arch +based_on | +is_active | true +is_cool | true +-[ RECORD 2 ]------ +name | Debian +based_on | +is_active | true +is_cool | true +``` + +## height + +``` +Table + +| &str | i32 | +|-------------|-----| +| Multi | 123 | +| line | | +| string | | +| Single line | 234 | + +Table increase height to 10 + +| &str | i32 | +| | | +| | | +|-------------|-----| +| Multi | 123 | +| line | | +| string | | +| | | +| Single line | 234 | +| | | + +Table decrease height to 4 + +| &str | i32 | +|-------------|-----| +| Multi | 123 | +| Single line | 234 | +Table decrease height to 0 + +|--|--| +``` + +## iter_table + +``` +.----------------------------------------------------------------------------------------. +| 0 | ok | //! The example can be run by this command | +| 1 | ok | //! `cargo run --example iter_table` | +| 2 | ok | | +| 3 | ok | use std::io::BufRead; | +| 4 | ok | | +| 5 | ok | use tabled::{settings::Style, tables::IterTable}; | +| 6 | ok | | +| 7 | ok | fn main() { | +| 8 | ok | let path = file!(); | +| 9 | ok | let file = std::fs::File::open(path).unwrap(); | +| 10 | ok | let reader = std::io::BufReader::new(file); | +| 11 | ok | let iterator = reader.lines().enumerate().map(|(i, line)| match line { | +| 12 | ok | Ok(line) => [i.to_string(), String::from("ok"), line], | +| 13 | ok | Err(err) => [i.to_string(), String::from("error"), err.to_string()], | +| 14 | ok | }); | +| 15 | ok | | +| 16 | ok | let table = IterTable::new(iterator).with(Style::ascii_rounded()); | +| 17 | ok | | +| 18 | ok | table.build(std::io::stdout()).unwrap(); | +| 19 | ok | println!() | +| 20 | ok | } | +'----------------------------------------------------------------------------------------' +``` + +## margin + +``` +vvvvvvvvvvvvvvvvvv +vvvvvvvvvvvvvvvvvv +<<<<=== === ===>>> +<<<< 0 1 2 >>> +<<<<=== === ===>>> +<<<< A B C >>> +<<<< D E F >>> +<<<< G H I >>> +<<<<=== === ===>>> +^^^^^^^^^^^^^^^^^^ +``` + +## matrix + +``` +┌────┬────┬────┬────┬────┬────┬────┬────┬────┬─────┐ +│ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 2 │ 4 │ 6 │ 8 │ 10 │ 12 │ 14 │ 16 │ 18 │ 20 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 3 │ 6 │ 9 │ 12 │ 15 │ 18 │ 21 │ 24 │ 27 │ 30 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 4 │ 8 │ 12 │ 16 │ 20 │ 24 │ 28 │ 32 │ 36 │ 40 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 5 │ 10 │ 15 │ 20 │ 25 │ 30 │ 35 │ 40 │ 45 │ 50 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 6 │ 12 │ 18 │ 24 │ 30 │ 36 │ 42 │ 48 │ 54 │ 60 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 7 │ 14 │ 21 │ 28 │ 35 │ 42 │ 49 │ 56 │ 63 │ 70 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 8 │ 16 │ 24 │ 32 │ 40 │ 48 │ 56 │ 64 │ 72 │ 80 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 9 │ 18 │ 27 │ 36 │ 45 │ 54 │ 63 │ 72 │ 81 │ 90 │ +├────┼────┼────┼────┼────┼────┼────┼────┼────┼─────┤ +│ 10 │ 20 │ 30 │ 40 │ 50 │ 60 │ 70 │ 80 │ 90 │ 100 │ +└────┴────┴────┴────┴────┴────┴────┴────┴────┴─────┘ +``` + +## merge_duplicates + +``` +┌────────────┬─────────┬────────┐ +│ db │ table │ total │ +├────────────┼─────────┼────────┤ +│ database_1 │ table_1 │ 10712 │ +│ ├─────────┼────────┤ +│ │ table_2 │ 57 │ +│ ├─────────┤ │ +│ │ table_3 │ │ +├────────────┼─────────┼────────┤ +│ database_2 │ table_1 │ 72 │ +│ ├─────────┼────────┤ +│ │ table_2 │ 75 │ +├────────────┼─────────┼────────┤ +│ database_3 │ table_1 │ 20 │ +│ ├─────────┼────────┤ +│ │ table_2 │ 21339 │ +│ ├─────────┼────────┤ +│ │ table_3 │ 141723 │ +└────────────┴─────────┴────────┘ +``` + +## merge_duplicates_2 + +``` +╭───────────┬───────────────────────────────────────────────────────────────────────────╮ +│ │ 0 1 2 3 4 5 6 7 │ +├───────────┼───────────────────────────────────────────────────────────────────────────┤ +│ db │ database_1 database_2 database_3 │ +│ origin_db │ database_1 database_3 │ +│ table │ table_1 table_2 table_3 table_1 table_2 table_1 table_2 table_3 │ +│ total │ 10712 57 72 75 20 21339 141723 │ +╰───────────┴───────────────────────────────────────────────────────────────────────────╯ +``` + +## settings_list + +``` ++----------------------+-----------------+--------------------+ +| name | first_release | developer | ++----------------------+-----------------+--------------------+ +| Sublime Text 3 | 2008 | Sublime HQ | ++----------------------+-----------------+--------------------+ +| Visual Studio Code | 2015 | Microsoft | ++----------------------+-----------------+--------------------+ +| Notepad++ | 2003 | Don Ho | ++----------------------+-----------------+--------------------+ +| GNU Emacs | 1984 | Richard Stallman | ++----------------------+-----------------+--------------------+ +| Neovim | 2015 | Vim community | ++----------------------+-----------------+--------------------+ +``` + +## split + +``` +┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ +│ a │ b │ c │ d │ e │ f │ g │ h │ i │ j │ k │ l │ m │ n │ o │ p │ q │ r │ s │ t │ u │ v │ w │ x │ y │ z │ +└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ +┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ ┌───┬───┐ ┌───┬───┐ ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ +│ a │ b │ c │ d │ e │ f │ g │ h │ i │ j │ k │ l │ │ a │ b │ │ a │ b │ │ a │ y │ b │ z │ c │ d │ e │ f │ g │ h │ i │ j │ k │ l │ +├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ ├───┼───┤ ├───┼───┤ ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ +│ m │ n │ o │ p │ q │ r │ s │ t │ u │ v │ w │ x │ │ c │ d │ │ m │ n │ │ m │ │ n │ │ o │ p │ q │ r │ s │ t │ u │ v │ w │ x │ +├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ ├───┼───┤ ├───┼───┤ └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ +│ y │ z │ │ │ │ │ │ │ │ │ │ │ │ e │ f │ │ y │ z │ ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ +└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ ├───┼───┤ ├───┼───┤ │ a │ b │ c │ d │ e │ f │ g │ h │ i │ j │ k │ l │ y │ z │ + │ g │ h │ │ c │ d │ ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ + ├───┼───┤ ├───┼───┤ │ m │ n │ o │ p │ q │ r │ s │ t │ u │ v │ w │ x │ │ │ + │ i │ j │ │ o │ p │ └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ + ├───┼───┤ ├───┼───┤ + │ k │ l │ │ e │ f │ + ├───┼───┤ ├───┼───┤ + │ m │ n │ │ q │ r │ + ├───┼───┤ ├───┼───┤ + │ o │ p │ │ g │ h │ + ├───┼───┤ ├───┼───┤ + │ q │ r │ │ s │ t │ + ├───┼───┤ ├───┼───┤ + │ s │ t │ │ i │ j │ + ├───┼───┤ ├───┼───┤ + │ u │ v │ │ u │ v │ + ├───┼───┤ ├───┼───┤ + │ w │ x │ │ k │ l │ + ├───┼───┤ ├───┼───┤ + │ y │ z │ │ w │ x │ + └───┴───┘ └───┴───┘ +```
\ No newline at end of file diff --git a/vendor/tabled/examples/alphabet.rs b/vendor/tabled/examples/alphabet.rs new file mode 100644 index 000000000..5cc8250ad --- /dev/null +++ b/vendor/tabled/examples/alphabet.rs @@ -0,0 +1,13 @@ +//! This example demonstrates instantiating a [`Table`] from an [`IntoIterator`] compliant object. +//! +//! * Note how [`Range`] [expression syntax](https://doc.rust-lang.org/reference/expressions/range-expr.html) +//! is used to idiomatically represent the English alphabet. + +use std::iter::FromIterator; + +use tabled::Table; + +fn main() { + let table = Table::from_iter(['a'..='z']); + println!("{table}"); +} diff --git a/vendor/tabled/examples/border_text.rs b/vendor/tabled/examples/border_text.rs new file mode 100644 index 000000000..bbdb7673e --- /dev/null +++ b/vendor/tabled/examples/border_text.rs @@ -0,0 +1,44 @@ +//! This example demonstrates inserting text into the borders +//! of a [`Table`] with [`BorderText`]; a powerful labeling tool. +//! +//! * [`BorderText`] currently supports: +//! * Horizontal border placement +//! * Placement starting column offset +//! * Text colorization +//! +//! * Note how the flexibility of [`Style`] is utilized +//! to remove horizontal borders from the table entirely, +//! and then granularly reinserts one for a highly customized +//! visualization. +//! +//! * Note how the [`Rows`] utility object is used to idiomatically +//! reference the first and last rows of a [`Table`] without writing +//! the necessary logic by hand. +//! +//! * 🚀 Combining several easy-to-use tools, +//! to create unique data representations is what makes [`tabled`] great! + +use tabled::{ + settings::{ + object::Rows, + style::{BorderText, HorizontalLine, Style}, + }, + Table, +}; + +fn main() { + let data = [[5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]; + + let table = Table::new(data) + .with( + Style::modern() + .remove_horizontal() + .horizontals([HorizontalLine::new(1, Style::modern().get_horizontal())]), + ) + .with(BorderText::new(" Numbers ").horizontal(Rows::first())) + .with(BorderText::new(" More numbers ").horizontal(1)) + .with(BorderText::new(" end. ").horizontal(Rows::last())) + .to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/builder.rs b/vendor/tabled/examples/builder.rs new file mode 100644 index 000000000..6baf29c24 --- /dev/null +++ b/vendor/tabled/examples/builder.rs @@ -0,0 +1,38 @@ +//! This example demonstrates an alternative method for creating a [`Table`]. +//! [`Builder`] is an efficient implementation of the [builder design pattern](https://en.wikipedia.org/wiki/Builder_pattern). +//! +//! > The intent of the Builder design pattern is to separate the construction of a complex object from its representation. +//! > -- <cite>Wikipedia</cite> +//! +//! * Note how [Builder] can be used to define a table's shape manually +//! and can be populated through iteration if it is mutable. This flexibility +//! is useful when you don't have direct control over the datasets you intend to [table](tabled). + +use tabled::{ + builder::Builder, + settings::{object::Rows, Modify, Panel, Style, Width}, +}; + +fn main() { + let message = r#"The terms "the ocean" or "the sea" used without specification refer to the interconnected body of salt water covering the majority of the Earth's surface"#; + let link = r#"https://en.wikipedia.org/wiki/Ocean"#; + + let oceans = ["Atlantic", "Pacific", "Indian", "Southern", "Arctic"]; + + let mut builder = Builder::default(); + builder.set_header(["#", "Ocean"]); + for (i, ocean) in oceans.iter().enumerate() { + builder.push_record([i.to_string(), ocean.to_string()]); + } + + let table = builder + .build() + .with(Panel::header(message)) + .with(Panel::header(link)) + .with(Panel::horizontal(2, "=".repeat(link.len()))) + .with(Modify::new(Rows::single(1)).with(Width::wrap(link.len()))) + .with(Style::markdown()) + .to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/builder_index.rs b/vendor/tabled/examples/builder_index.rs new file mode 100644 index 000000000..9a53eb566 --- /dev/null +++ b/vendor/tabled/examples/builder_index.rs @@ -0,0 +1,50 @@ +//! This example demonstrates evolving the standard [`Builder`] to an [`IndexBuilder`], +//! and then manipulating the constructing table with a newly prepended index column. +//! +//! * An [`IndexBuilder`] is capable of several useful manipulations, including: +//! * Giving the new index column a name +//! * Transposing the index column around a table +//! * Choosing a location for the new index column besides 0; the default +//! +//! * Note that like with any builder pattern the [`IndexBuilder::build()`] function +//! is necessary to produce a displayable [`Table`]. + +use tabled::{settings::Style, Table, Tabled}; + +#[derive(Tabled)] +struct Distribution { + name: &'static str, + based_on: &'static str, + is_active: bool, + is_cool: bool, +} + +impl Distribution { + fn new(name: &'static str, based_on: &'static str, is_active: bool, is_cool: bool) -> Self { + Self { + name, + based_on, + is_active, + is_cool, + } + } +} + +fn main() { + let data = [ + Distribution::new("Manjaro", "Arch", true, true), + Distribution::new("Arch", "None", true, true), + Distribution::new("Debian", "None", true, true), + ]; + + let mut table = Table::builder(data) + .index() + .column(0) + .name(None) + .transpose() + .build(); + + table.with(Style::modern()); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/chess.rs b/vendor/tabled/examples/chess.rs new file mode 100644 index 000000000..db83218c8 --- /dev/null +++ b/vendor/tabled/examples/chess.rs @@ -0,0 +1,37 @@ +//! This example demonstrates using the [`Color`] [setting](tabled::settings) to +//! stylize text, backgrounds, and borders. +//! +//! * 🚩 This example requires the `color` feature. +//! +//! * Note how [`Format::content()`] is used to break out [`CellOption`] +//! specifications. This is helpful for organizing extensive [`Table`] configurations. + +use std::iter::FromIterator; + +use tabled::{ + builder::Builder, + settings::{style::Style, themes::Colorization, Color}, +}; + +fn main() { + let board = [ + ["♜", "♞", "♝", "♛", "♚", "♝", "♞", "♜"], + ["♟", "♟", "♟", "♟", "♟", "♟", "♟", "♟"], + [" ", " ", " ", " ", " ", " ", " ", " "], + [" ", " ", " ", " ", " ", " ", " ", " "], + [" ", " ", " ", " ", " ", " ", " ", " "], + [" ", " ", " ", " ", " ", " ", " ", " "], + ["♙", "♙", "♙", "♙", "♙", "♙", "♙", "♙"], + ["♖", "♘", "♗", "♕", "♔", "♗", "♘", "♖"], + ]; + + let color_white = Color::BG_WHITE | Color::FG_BLACK; + let color_black = Color::FG_WHITE | Color::BG_BLACK; + + let mut table = Builder::from_iter(board).build(); + table + .with(Style::empty()) + .with(Colorization::chess(color_white, color_black)); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/col_row_macros.rs b/vendor/tabled/examples/col_row_macros.rs new file mode 100644 index 000000000..1a676eb67 --- /dev/null +++ b/vendor/tabled/examples/col_row_macros.rs @@ -0,0 +1,62 @@ +//! This example demonstrates using the [`col!`] and [`row!`] macros to easily +//! organize multiple tables together into a single, new [`Table`] display. +//! +//! * 🚩 This example requires the `macros` feature. +//! +//! * Note how both macros can be used in combination to layer +//! several table arrangements together. +//! +//! * Note how [`col!`] and [`row!`] support idiomatic argument duplication +//! with the familiar `[T; N]` syntax. + +use tabled::{ + col, row, + settings::{Alignment, Style}, + Table, Tabled, +}; + +#[derive(Tabled)] +struct Person { + name: String, + age: u8, + is_validated: bool, +} + +impl Person { + fn new(name: &str, age: u8, is_validated: bool) -> Self { + Self { + name: name.into(), + age, + is_validated, + } + } +} + +fn main() { + let validated = [Person::new("Sam", 31, true), Person::new("Sarah", 26, true)]; + + let not_validated = [ + Person::new("Jack Black", 51, false), + Person::new("Michelle Goldstein", 44, true), + ]; + + let unsure = [ + Person::new("Jon Doe", 255, false), + Person::new("Mark Nelson", 13, true), + Person::new("Terminal Monitor", 0, false), + Person::new("Adam Blend", 17, true), + ]; + + let table_a = Table::new(&validated).with(Style::ascii()).to_string(); + let table_b = Table::new(¬_validated).with(Style::modern()).to_string(); + let table_c = Table::new(&unsure).with(Style::ascii_rounded()).to_string(); + + let row_table = row![table_c, table_b]; + + let col_table = col![table_c; 3]; + + let mut row_col_table = col![row![table_a, table_b].with(Style::empty()), table_c]; + row_col_table.with(Alignment::center()); + + println!("{row_table}\n{col_table}\n{row_col_table}",); +} diff --git a/vendor/tabled/examples/color.rs b/vendor/tabled/examples/color.rs new file mode 100644 index 000000000..b7064b306 --- /dev/null +++ b/vendor/tabled/examples/color.rs @@ -0,0 +1,74 @@ +//! This example demonstrates using the [`Color`] [setting](tabled::settings) to +//! stylize text, backgrounds, and borders. +//! +//! * 🚩 This example requires the `color` feature. +//! +//! * Note how [`Format::content()`] is used to break out [`CellOption`] +//! specifications. This is helpful for organizing extensive [`Table`] configurations. + +use std::convert::TryFrom; + +use owo_colors::OwoColorize; + +use tabled::{ + settings::{ + object::{Columns, Rows}, + style::{BorderColor, Style}, + Color, Format, Modify, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct Bsd { + distribution: &'static str, + year_of_first_release: usize, + is_active: bool, +} + +impl Bsd { + fn new(distribution: &'static str, year_of_first_release: usize, is_active: bool) -> Self { + Self { + distribution, + year_of_first_release, + is_active, + } + } +} + +fn main() { + let data = vec![ + Bsd::new("BSD", 1978, false), + Bsd::new("SunOS", 1982, false), + Bsd::new("NetBSD", 1993, true), + Bsd::new("FreeBSD", 1993, true), + Bsd::new("OpenBSD", 1995, true), + ]; + + let red = Format::content(|s| s.red().on_bright_white().to_string()); + let blue = Format::content(|s| s.blue().to_string()); + let green = Format::content(|s| s.green().to_string()); + + let color_red = Color::try_from(' '.red().to_string()).unwrap(); + let color_purple = Color::try_from(' '.purple().to_string()).unwrap(); + + let yellow_color = Color::try_from(' '.yellow().to_string()).unwrap(); + + let first_row_style = Modify::new(Rows::first()).with( + BorderColor::default() + .bottom(color_red) + .corner_bottom_left(color_purple.clone()) + .corner_bottom_right(color_purple), + ); + + let mut table = Table::new(data); + table + .with(Style::psql()) + .with(yellow_color) + .with(first_row_style) + .with(Modify::new(Columns::single(0)).with(red)) + .with(Modify::new(Columns::single(1)).with(green)) + .with(Modify::new(Columns::single(2)).with(blue)); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/colored_borders.rs b/vendor/tabled/examples/colored_borders.rs new file mode 100644 index 000000000..0bbdb4ac4 --- /dev/null +++ b/vendor/tabled/examples/colored_borders.rs @@ -0,0 +1,65 @@ +//! This example demonstrates using the [`RawStyle`] [setting](tabled::settings) to +//! to granularly specify border colors. +//! +//! * 🚩 This example requires the `color` feature. +//! +//! * Note how [`Color`] containts several helpful, const values covering +//! a basic selection of foreground and background colors. [`Color`] also +//! supports custom colors with [`Color::new()`]. + +use tabled::{ + settings::{ + style::{RawStyle, Style}, + Color, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct CodeEditor { + name: &'static str, + first_release: &'static str, + developer: &'static str, +} + +impl CodeEditor { + fn new(name: &'static str, first_release: &'static str, developer: &'static str) -> Self { + Self { + name, + first_release, + developer, + } + } +} + +fn main() { + let mut style = RawStyle::from(Style::extended()); + style + .set_color_top(Color::FG_RED) + .set_color_bottom(Color::FG_CYAN) + .set_color_left(Color::FG_BLUE) + .set_color_right(Color::FG_GREEN) + .set_color_corner_top_left(Color::FG_BLUE) + .set_color_corner_top_right(Color::FG_RED) + .set_color_corner_bottom_left(Color::FG_CYAN) + .set_color_corner_bottom_right(Color::FG_GREEN) + .set_color_intersection_bottom(Color::FG_CYAN) + .set_color_intersection_top(Color::FG_RED) + .set_color_intersection_right(Color::FG_GREEN) + .set_color_intersection_left(Color::FG_BLUE) + .set_color_intersection(Color::FG_MAGENTA) + .set_color_horizontal(Color::FG_MAGENTA) + .set_color_vertical(Color::FG_MAGENTA); + + let data = [ + CodeEditor::new("Sublime Text 3", "2008", "Sublime HQ"), + CodeEditor::new("Visual Studio Code", "2015", "Microsoft"), + CodeEditor::new("Notepad++", "2003", "Don Ho"), + CodeEditor::new("GNU Emacs", "1984", "Richard Stallman"), + CodeEditor::new("Neovim", "2015", "Vim community"), + ]; + + let table = Table::new(data).with(style).to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/colored_padding.rs b/vendor/tabled/examples/colored_padding.rs new file mode 100644 index 000000000..96a3a717f --- /dev/null +++ b/vendor/tabled/examples/colored_padding.rs @@ -0,0 +1,173 @@ +//! This example demonstrates using the [`Padding::colorize()`] function in several ways +//! to give a [`Table`] display a vibrant asthetic. +//! +//! * 🚩 This example requires the `color` feature. +//! +//! * Note how the [`Color`] [setting](tabled::settings) is used to simplify creating +//! reusable themes for text, backgrounds, padded whitespace, and borders. +//! +//! * Note how a unique color can be set for each direction. + +use std::convert::TryFrom; + +use owo_colors::OwoColorize; + +use tabled::{ + grid::{ + config::{ColoredConfig, Entity}, + dimension::SpannedGridDimension, + records::{ + vec_records::{Cell, VecRecords}, + ExactRecords, PeekableRecords, Records, + }, + util::string::string_width_multiline, + }, + settings::{ + object::{Columns, Object, Rows, Segment}, + Alignment, CellOption, Color, Format, Margin, Modify, Padding, Style, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +#[tabled(rename_all = "PascalCase")] +struct Fundamental { + quantity: &'static str, + symbol: &'static str, + value: &'static str, + unit: &'static str, +} + +impl Fundamental { + fn new( + quantity: &'static str, + symbol: &'static str, + value: &'static str, + unit: &'static str, + ) -> Self { + Self { + quantity, + symbol, + value, + unit, + } + } +} + +fn main() { + // data source: https://www.britannica.com/science/physical-constant + let data = [ + Fundamental::new( + "constant of gravitation", + "G", + "6.67384 × 10⁻¹¹", + "cubic metre per second squared per kilogram", + ), + Fundamental::new( + "speed of light (in a vacuum)", + "c", + "2.99792458 × 10⁻⁸", + "metres per second", + ), + Fundamental::new( + "Planck's constant", + "h", + "6.626070040 × 10⁻³⁴", + "joule second", + ), + Fundamental::new( + "Boltzmann constant", + "k", + "1.38064852 × 10⁻²³", + "joule per kelvin", + ), + Fundamental::new( + "Faraday constant", + "F", + "9.648533289 × 10⁴", + "coulombs per mole", + ), + ]; + + let pane_color = Color::try_from(' '.bg_rgb::<220, 220, 220>().to_string()).unwrap(); + let border_color = Color::try_from(' '.bg_rgb::<200, 200, 220>().bold().to_string()).unwrap(); + let data_color = Color::try_from(' '.bg_rgb::<200, 200, 220>().to_string()).unwrap(); + + let header_settings = Modify::new(Rows::first()) + .with(Padding::new(1, 1, 2, 2).colorize( + Color::BG_GREEN, + Color::BG_YELLOW, + Color::BG_MAGENTA, + Color::BG_CYAN, + )) + .with(MakeMaxPadding) + .with(Format::content(|s| s.on_black().white().to_string())); + + let data_settings = Modify::new(Rows::first().inverse()) + .with(Alignment::left()) + .with(MakeMaxPadding) + .with(Padding::new(1, 1, 0, 0).colorize( + Color::default(), + Color::default(), + data_color.clone(), + data_color.clone(), + )); + + let symbol_settings = Modify::new(Columns::single(1).not(Rows::first())) + .with(Format::content(|s| s.bold().to_string())); + + let unit_settings = Modify::new(Columns::single(3).not(Rows::first())) + .with(Format::content(|s| s.italic().to_string())); + + let table = Table::new(data) + .with(Style::rounded()) + .with(Margin::new(1, 2, 1, 1).colorize( + pane_color.clone(), + pane_color.clone(), + pane_color.clone(), + pane_color, + )) + .with(border_color) + .with(Modify::new(Segment::all()).with(data_color)) + .with(header_settings) + .with(data_settings) + .with(symbol_settings) + .with(unit_settings) + .to_string(); + + println!("\n\n{table}\n\n"); +} + +#[derive(Debug, Clone)] +struct MakeMaxPadding; + +impl<T> CellOption<VecRecords<T>, ColoredConfig> for MakeMaxPadding +where + T: Cell + AsRef<str>, +{ + fn change(self, records: &mut VecRecords<T>, cfg: &mut ColoredConfig, entity: Entity) { + let widths = SpannedGridDimension::width(&*records, cfg); + + let count_rows = records.count_rows(); + let count_cols = records.count_columns(); + + for (row, col) in entity.iter(count_rows, count_cols) { + let column_width = widths[col]; + let text = records.get_text((row, col)); + let width = string_width_multiline(text); + + if width < column_width { + let available_width = column_width - width; + let left = available_width / 2; + let right = available_width - left; + + let pos = (row, col).into(); + let mut pad = cfg.get_padding(pos); + pad.left.size = left; + pad.right.size = right; + + cfg.set_padding(pos, pad); + } + } + } +} diff --git a/vendor/tabled/examples/colorization.rs b/vendor/tabled/examples/colorization.rs new file mode 100644 index 000000000..a68ca93e8 --- /dev/null +++ b/vendor/tabled/examples/colorization.rs @@ -0,0 +1,69 @@ +//! This example demonstrates using the [`Color`] [setting](tabled::settings) to +//! stylize text, backgrounds, and borders. +//! +//! * 🚩 This example requires the `color` feature. +//! +//! * Note how [`Format::content()`] is used to break out [`CellOption`] +//! specifications. This is helpful for organizing extensive [`Table`] configurations. + +use tabled::{ + builder::Builder, + settings::{object::Rows, style::Style, themes::Colorization, Color, Concat}, + Table, Tabled, +}; + +#[derive(Tabled)] +#[tabled(rename_all = "UPPERCASE")] +struct Employee { + id: usize, + #[tabled(rename = "FIRST NAME")] + first_name: String, + #[tabled(rename = "LAST NAME")] + last_name: String, + salary: usize, + comment: String, +} + +impl Employee { + fn new(id: usize, first_name: &str, last_name: &str, salary: usize, comment: &str) -> Self { + Self { + id, + salary, + first_name: first_name.to_string(), + last_name: last_name.to_string(), + comment: comment.to_string(), + } + } +} + +fn main() { + let data = vec![ + Employee::new(1, "Arya", "Stark", 3000, ""), + Employee::new(20, "Jon", "Snow", 2000, "You know nothing, Jon Snow!"), + Employee::new(300, "Tyrion", "Lannister", 5000, ""), + ]; + + let total = data.iter().map(|e| e.salary).sum::<usize>(); + let total_row = Builder::from(vec![vec![ + String::from(""), + String::from(""), + String::from("TOTAL"), + total.to_string(), + ]]) + .build(); + + let color_data_primary = Color::BG_WHITE | Color::FG_BLACK; + let color_data_second = Color::BG_BRIGHT_WHITE | Color::FG_BLACK; + let color_head = Color::BOLD | Color::BG_CYAN | Color::FG_BLACK; + let color_footer = Color::BOLD | Color::BG_BLUE | Color::FG_BLACK; + + let mut table = Table::new(data); + table + .with(Concat::vertical(total_row)) + .with(Style::empty()) + .with(Colorization::rows([color_data_primary, color_data_second])) + .with(Colorization::exact([color_head], Rows::first())) + .with(Colorization::exact([color_footer], Rows::last())); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/column_names.rs b/vendor/tabled/examples/column_names.rs new file mode 100644 index 000000000..0388e6264 --- /dev/null +++ b/vendor/tabled/examples/column_names.rs @@ -0,0 +1,63 @@ +//! This example demonstrates how to set column names on a top horizontal line. +//! +//! It sets a `clickhouse` like table style (first seen on). + +use std::iter::repeat; + +use tabled::{ + grid::config::AlignmentHorizontal, + settings::{themes::ColumnNames, Color, Style}, + Table, Tabled, +}; + +#[derive(Debug, Tabled)] +struct Function { + declaration: String, + name: String, + return_type: String, +} + +impl Function { + fn new(decl: &str, name: &str, ret_type: &str) -> Self { + Self { + declaration: decl.to_string(), + name: name.to_string(), + return_type: ret_type.to_string(), + } + } +} + +fn main() { + let data = vec![ + Function::new( + "struct stack *stack_create(int)", + "stack_create", + "struct stack *", + ), + Function::new( + "void stack_destroy(struct stack *)", + "stack_destroy", + "void", + ), + Function::new( + "int stack_put(struct stack *, vm_offset_t)", + "stack_put", + "int", + ), + Function::new( + "void stack_copy(const struct stack *, struct stack *)", + "stack_copy", + "void", + ), + ]; + + let mut table = Table::new(data); + + table.with(Style::modern().remove_horizontal()).with( + ColumnNames::default() + .set_colors(repeat(Color::BOLD | Color::BG_BLUE | Color::FG_WHITE).take(3)) + .set_alignment(AlignmentHorizontal::Center), + ); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/compact_table.rs b/vendor/tabled/examples/compact_table.rs new file mode 100644 index 000000000..3a02d448d --- /dev/null +++ b/vendor/tabled/examples/compact_table.rs @@ -0,0 +1,23 @@ +//! This example demonstrates creating a `new()` [`CompactTable`] with +//! manual specifications for column count, column widths, and border styling. +//! +//! * [`CompactTable`] is a [`Table`] alternative that trades off reduced +//! flexibility for improved performance. + +use tabled::{settings::Style, tables::CompactTable}; + +fn main() { + let data = [ + ["Debian", "", "true"], + ["Arch", "", "true"], + ["Manjaro", "Arch", "true"], + ]; + + let _table = CompactTable::new(data) + .columns(3) + .width([7, 5, 5]) + .with(Style::markdown()); + + #[cfg(feature = "std")] + println!("{}", _table.to_string()); +} diff --git a/vendor/tabled/examples/compact_table_2.rs b/vendor/tabled/examples/compact_table_2.rs new file mode 100644 index 000000000..5f231ccd8 --- /dev/null +++ b/vendor/tabled/examples/compact_table_2.rs @@ -0,0 +1,20 @@ +//! This example demonstrates creating a [`CompactTable`] `from()` a +//! multidimensional array. +//! +//! * Note how [`CompactTable::from()`] inherits the lengths of the nested arrays +//! as typed definitions through [const generics](https://practice.rs/generics-traits/const-generics.html). + +use tabled::{settings::Style, tables::CompactTable}; + +fn main() { + let data = [ + ["Debian", "1.1.1.1", "true"], + ["Arch", "127.1.1.1", "true"], + ["Manjaro", "Arch", "true"], + ]; + + let _table = CompactTable::from(data).with(Style::psql()); + + #[cfg(feature = "std")] + println!("{}", _table.to_string()); +} diff --git a/vendor/tabled/examples/compact_table_3.rs b/vendor/tabled/examples/compact_table_3.rs new file mode 100644 index 000000000..5c7df6d5e --- /dev/null +++ b/vendor/tabled/examples/compact_table_3.rs @@ -0,0 +1,19 @@ +//! This example demonstrates how [`CompactTable`] is limited to single +//! line rows. +//! +//! * Note how the multiline data is accepted, but then truncated in the display. + +use tabled::{settings::Style, tables::CompactTable}; + +fn main() { + let data = [ + ["De\nbi\nan", "1.1.1.1", "true"], + ["Arch", "127.1.1.1", "true"], + ["Manjaro", "A\nr\nc\nh", "true"], + ]; + + let _table = CompactTable::from(data).with(Style::psql()); + + #[cfg(feature = "std")] + println!("{}", _table.to_string()); +} diff --git a/vendor/tabled/examples/concat.rs b/vendor/tabled/examples/concat.rs new file mode 100644 index 000000000..09afeed7b --- /dev/null +++ b/vendor/tabled/examples/concat.rs @@ -0,0 +1,58 @@ +//! This example demonstrates using the [`Concat`] [`TableOption`] to concatenate +//! [`tables`](Table) together. +//! +//! * [`Concat`] supports appending tables vertically and horizontally. +//! +//! * Note how the base tables style settings take take precedence over the appended table. +//! If the two tables are of unequal shape, additional blank cells are added as needed. + +use tabled::{ + settings::{object::Segment, Alignment, Concat, Modify, Style}, + Table, Tabled, +}; + +#[derive(Debug, Tabled)] +struct Weather { + temperature_c: f64, + wind_ms: f64, +} + +#[derive(Debug, Tabled)] +struct Location( + #[tabled(rename = "latitude")] f64, + #[tabled(rename = "longitude")] f64, +); + +fn main() { + let weather_data = [ + Weather { + temperature_c: 1.0, + wind_ms: 3.0, + }, + Weather { + temperature_c: -20.0, + wind_ms: 30.0, + }, + Weather { + temperature_c: 40.0, + wind_ms: 100.0, + }, + ]; + + let location_data = [ + Location(111.111, 333.333), + Location(5.111, 7282.1), + Location(0.0, 0.0), + Location(0.0, 0.0), + ]; + + let location_table = Table::new(location_data); + + let mut weather_table = Table::new(weather_data); + weather_table + .with(Concat::horizontal(location_table)) + .with(Style::empty()) + .with(Modify::new(Segment::all()).with(Alignment::left())); + + println!("{weather_table}"); +} diff --git a/vendor/tabled/examples/custom_style.rs b/vendor/tabled/examples/custom_style.rs new file mode 100644 index 000000000..e6f0848cb --- /dev/null +++ b/vendor/tabled/examples/custom_style.rs @@ -0,0 +1,54 @@ +//! This example demonstrates customizing one of the [`tabled`] default [styles](Style) +//! to create a unique [`Table`] display. +//! +//! * Note that all predesigned styles can be configured completely. +//! Styles can also be created from scratch! +//! +//! * Note that adding and removing borders with a [`Style`] theme doesn't affect the +//! number of functional columns and rows. + +use tabled::{ + settings::{ + style::{HorizontalLine, Style, VerticalLine}, + Alignment, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct CodeEditor { + name: &'static str, + first_release: &'static str, + developer: &'static str, +} + +impl CodeEditor { + fn new(name: &'static str, first_release: &'static str, developer: &'static str) -> Self { + Self { + name, + first_release, + developer, + } + } +} + +fn main() { + let data = [ + CodeEditor::new("Sublime Text 3", "2008", "Sublime HQ"), + CodeEditor::new("Visual Studio Code", "2015", "Microsoft"), + CodeEditor::new("Notepad++", "2003", "Don Ho"), + CodeEditor::new("GNU Emacs", "1984", "Richard Stallman"), + CodeEditor::new("Neovim", "2015", "Vim community"), + ]; + + let theme = Style::modern() + .remove_horizontal() + .remove_vertical() + .horizontals([HorizontalLine::new(1, Style::modern().get_horizontal()).intersection(None)]) + .verticals([VerticalLine::new(1, Style::modern().get_vertical())]); + + let mut table = Table::new(data); + table.with(theme).with(Alignment::left()); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/derive/display_with.rs b/vendor/tabled/examples/derive/display_with.rs new file mode 100644 index 000000000..9dfc87a47 --- /dev/null +++ b/vendor/tabled/examples/derive/display_with.rs @@ -0,0 +1,65 @@ +//! This example demonstrates using the [attribute macro](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros) +//! [`display_with`] to seamlessly augment field representations in a [`Table`] display. +//! +//! * [`display_with`] functions act as transformers during [`Table`] instantiation. +//! +//! * Note how [`display_with`] works with [std] and custom functions alike. +//! +//! * [`display_with`] attributes can be constructed in two ways (shown below). +//! +//! * Attribute arguments can be directly overridden with static values, effectively ignoring the +//! augmented fields natural value entirely. Even an entire object can be passed as context with `self`. + +use std::borrow::Cow; + +use tabled::{Table, Tabled}; + +#[derive(Tabled)] +#[tabled(rename_all = "camelCase")] +struct Country { + name: &'static str, + capital_city: &'static str, + #[tabled(display_with("display_perimeter", self))] + surface_area_km2: f32, + #[tabled(display_with = "str::to_lowercase")] + national_currency: &'static str, + national_currency_short: &'static str, +} + +fn display_perimeter(country: &Country) -> Cow<'_, str> { + if country.surface_area_km2 > 1_000_000.0 { + "Very Big Land".into() + } else { + "Big Land".into() + } +} + +impl Country { + fn new( + name: &'static str, + national_currency: &'static str, + national_currency_short: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + ) -> Self { + Self { + name, + national_currency, + national_currency_short, + capital_city, + surface_area_km2, + } + } +} + +fn main() { + let data = [ + Country::new("Afghanistan", "Afghani", "AFN", "Kabul", 652867.0), + Country::new("Angola", "Kwanza", "AOA", "Luanda", 1246700.0), + Country::new("Canada", "Canadian Dollar", "CAD", "Ottawa", 9984670.0), + ]; + + let table = Table::new(data); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/derive/inline.rs b/vendor/tabled/examples/derive/inline.rs new file mode 100644 index 000000000..2ce07816f --- /dev/null +++ b/vendor/tabled/examples/derive/inline.rs @@ -0,0 +1,55 @@ +//! This example demonstrates using the [attribute macro](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros) +//! [`inline`] to expand struct fields to individual columns in a [`Table`] display. +//! +//! * Note that without inlining a struct or enum field, those objects +//! must implement the [`Display`] trait as they will be represented in +//! a single column with the value of their [`ToString`] output. + +use tabled::{Table, Tabled}; + +#[derive(Tabled)] +struct Country { + name: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + #[tabled(inline)] + currency: Currency, +} + +#[derive(Tabled)] +struct Currency { + str: &'static str, + short: &'static str, +} + +impl Country { + fn new( + name: &'static str, + national_currency: &'static str, + national_currency_short: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + ) -> Self { + Self { + name, + capital_city, + surface_area_km2, + currency: Currency { + str: national_currency, + short: national_currency_short, + }, + } + } +} + +fn main() { + let data = [ + Country::new("Afghanistan", "Afghani", "AFN", "Kabul", 652867.0), + Country::new("Angola", "Kwanza", "AOA", "Luanda", 1246700.0), + Country::new("Canada", "Canadian Dollar", "CAD", "Ottawa", 9984670.0), + ]; + + let table = Table::new(data); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/derive/inline_enum.rs b/vendor/tabled/examples/derive/inline_enum.rs new file mode 100644 index 000000000..707d5bb2c --- /dev/null +++ b/vendor/tabled/examples/derive/inline_enum.rs @@ -0,0 +1,50 @@ +//! This example demonstrates using the [attribute macro](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros) +//! [`inline`] to expand enum fields to individual columns in a [`Table`] display. +//! +//! * Note how the optional [`inline`] argument is used to apply prefixes +//! to decomposed column headers. This is helpful for organizing tables +//! with repetative fields that would normally result in confusing headers. +//! +//! * Note that without inlining a struct or enum field, those objects +//! must implement the [`Display`] trait as they will be represented in +//! a single column with the value of their [`ToString`] output. + +use tabled::{Table, Tabled}; + +#[derive(Tabled)] +enum Contact { + #[tabled(inline("telegram::"))] + Telegram { + username: &'static str, + #[tabled(inline("telegram::"))] + number: Number, + }, + #[tabled(inline)] + Local(#[tabled(inline("local::"))] Number), +} + +#[derive(Tabled)] +struct Number { + number: &'static str, + code: usize, +} + +impl Number { + fn new(number: &'static str, code: usize) -> Self { + Self { number, code } + } +} + +fn main() { + let data = [ + Contact::Local(Number::new("654321", 123)), + Contact::Telegram { + username: "no2Presley", + number: Number::new("123456", 123), + }, + ]; + + let table = Table::new(data); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/derive/order.rs b/vendor/tabled/examples/derive/order.rs new file mode 100644 index 000000000..44e036fad --- /dev/null +++ b/vendor/tabled/examples/derive/order.rs @@ -0,0 +1,48 @@ +//! This example demonstrates using the [attribute macro](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros) +//! [`order`] to relocate fields to specified indexes in a [`Table`] display. +//! +//! * By default, [`Table`] columns are shown in the same ordered they are +//! defined in the deriving struct/enum definition. + +use tabled::{Table, Tabled}; + +#[derive(Tabled)] +struct Country { + name: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + #[tabled(order = 1)] + national_currency: &'static str, + #[tabled(order = 2)] + national_currency_short: &'static str, +} + +impl Country { + fn new( + name: &'static str, + national_currency: &'static str, + national_currency_short: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + ) -> Self { + Self { + name, + national_currency, + national_currency_short, + capital_city, + surface_area_km2, + } + } +} + +fn main() { + let data = [ + Country::new("Afghanistan", "Afghani", "AFN", "Kabul", 652867.0), + Country::new("Angola", "Kwanza", "AOA", "Luanda", 1246700.0), + Country::new("Canada", "Canadian Dollar", "CAD", "Ottawa", 9984670.0), + ]; + + let table = Table::new(data); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/derive/rename.rs b/vendor/tabled/examples/derive/rename.rs new file mode 100644 index 000000000..709411948 --- /dev/null +++ b/vendor/tabled/examples/derive/rename.rs @@ -0,0 +1,45 @@ +//! This example demonstrates using the [attribute macro](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros) +//! [`rename`] to alias specific fields in a [`Table`] display. + +use tabled::{Table, Tabled}; + +#[derive(Tabled)] +struct Country { + name: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + #[tabled(rename = "Currency")] + national_currency: &'static str, + #[tabled(rename = "Currency-ISO")] + national_currency_short: &'static str, +} + +impl Country { + fn new( + name: &'static str, + national_currency: &'static str, + national_currency_short: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + ) -> Self { + Self { + name, + national_currency, + national_currency_short, + capital_city, + surface_area_km2, + } + } +} + +fn main() { + let data = [ + Country::new("Afghanistan", "Afghani", "AFN", "Kabul", 652867.0), + Country::new("Angola", "Kwanza", "AOA", "Luanda", 1246700.0), + Country::new("Canada", "Canadian Dollar", "CAD", "Ottawa", 9984670.0), + ]; + + let table = Table::new(data); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/derive/rename_all.rs b/vendor/tabled/examples/derive/rename_all.rs new file mode 100644 index 000000000..cd408e5ba --- /dev/null +++ b/vendor/tabled/examples/derive/rename_all.rs @@ -0,0 +1,56 @@ +//! This example demonstrates using the [attribute macro](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros) +//! [`rename_all`] to apply table-wide header formatting in a [`Table`] display. +//! +//! * Supported formatting rules include: +//! * 'camelCase' +//! * 'kabab-case' +//! * 'PascalCase' +//! * 'SCREAMING_SNAKE_CASE' +//! * 'snake_case' +//! * 'lowercase' +//! * 'UPPERCASE' +//! * 'verbatim' + +use tabled::{Table, Tabled}; + +#[derive(Tabled)] +#[tabled(rename_all = "camelCase")] +struct Country { + name: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + #[tabled(rename_all = "kebab-case")] + national_currency: &'static str, + #[tabled(rename_all = "kebab-case")] + national_currency_short: &'static str, +} + +impl Country { + fn new( + name: &'static str, + national_currency: &'static str, + national_currency_short: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + ) -> Self { + Self { + name, + national_currency, + national_currency_short, + capital_city, + surface_area_km2, + } + } +} + +fn main() { + let data = [ + Country::new("Afghanistan", "Afghani", "AFN", "Kabul", 652867.0), + Country::new("Angola", "Kwanza", "AOA", "Luanda", 1246700.0), + Country::new("Canada", "Canadian Dollar", "CAD", "Ottawa", 9984670.0), + ]; + + let table = Table::new(data); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/derive/skip.rs b/vendor/tabled/examples/derive/skip.rs new file mode 100644 index 000000000..86f7a9ba2 --- /dev/null +++ b/vendor/tabled/examples/derive/skip.rs @@ -0,0 +1,49 @@ +//! This example demonstrates using the [attribute macro](https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros) +//! [`skip`] to omit specific fields from becoming columns in a [`Table`] display. +//! +//! * Note how [`skip`] annoys [clippy](https://doc.rust-lang.org/clippy/) with `dead_code` +//! warnings. This can be addressed with compiler overrides like `#[allow(dead_code)]`. + +use tabled::{Table, Tabled}; + +#[allow(dead_code)] +#[derive(Tabled)] +struct Country { + name: &'static str, + capital_city: &'static str, + #[tabled(skip)] + surface_area_km2: f32, + national_currency: &'static str, + #[tabled(skip)] + national_currency_short: &'static str, +} + +impl Country { + fn new( + name: &'static str, + national_currency: &'static str, + national_currency_short: &'static str, + capital_city: &'static str, + surface_area_km2: f32, + ) -> Self { + Self { + name, + national_currency, + national_currency_short, + capital_city, + surface_area_km2, + } + } +} + +fn main() { + let data = [ + Country::new("Afghanistan", "Afghani", "AFN", "Kabul", 652867.0), + Country::new("Angola", "Kwanza", "AOA", "Luanda", 1246700.0), + Country::new("Canada", "Canadian Dollar", "CAD", "Ottawa", 9984670.0), + ]; + + let table = Table::new(data); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/disable.rs b/vendor/tabled/examples/disable.rs new file mode 100644 index 000000000..1f04de7d9 --- /dev/null +++ b/vendor/tabled/examples/disable.rs @@ -0,0 +1,49 @@ +//! This example demonstrates using the [`Disable`] [`TableOption`] to remove specific +//! cell data from a [`Table`] display. +//! +//! * ⚠️ Using [`Disable`] in combination with other [`Style`] customizations may yield unexpected results. +//! It is safest to use [`Disable`] last in a chain of alterations. + +use tabled::{ + settings::{ + locator::ByColumnName, + style::{Border, Style}, + Disable, Modify, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct Distribution { + name: &'static str, + based_on: &'static str, + is_active: bool, + is_cool: bool, +} + +impl Distribution { + fn new(name: &'static str, based_on: &'static str, is_active: bool, is_cool: bool) -> Self { + Self { + name, + based_on, + is_active, + is_cool, + } + } +} + +fn main() { + let data = [ + Distribution::new("Debian", "", true, true), + Distribution::new("Arch", "", true, true), + Distribution::new("Manjaro", "Arch", true, true), + ]; + + let mut table = Table::new(data); + table + .with(Style::markdown()) + .with(Disable::column(ByColumnName::new("is_active"))) + .with(Modify::new(ByColumnName::new("name")).with(Border::filled('#'))); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/extended_display.rs b/vendor/tabled/examples/extended_display.rs new file mode 100644 index 000000000..d31257881 --- /dev/null +++ b/vendor/tabled/examples/extended_display.rs @@ -0,0 +1,35 @@ +//! This example demonstrates using [ExtendedTable], a [Table] alternative with +//! limited flexibility but a greater emphasis on large data displays. + +use tabled::{tables::ExtendedTable, Tabled}; + +#[derive(Tabled)] +struct Distribution { + name: &'static str, + based_on: &'static str, + is_active: bool, + is_cool: bool, +} + +impl Distribution { + fn new(name: &'static str, based_on: &'static str, is_active: bool, is_cool: bool) -> Self { + Self { + name, + based_on, + is_active, + is_cool, + } + } +} + +fn main() { + let data = vec![ + Distribution::new("Manjaro", "Arch", true, true), + Distribution::new("Arch", "", true, true), + Distribution::new("Debian", "", true, true), + ]; + + let table = ExtendedTable::new(data); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/extract.rs b/vendor/tabled/examples/extract.rs new file mode 100644 index 000000000..8d7d86434 --- /dev/null +++ b/vendor/tabled/examples/extract.rs @@ -0,0 +1,106 @@ +//! This example demonstrates using the [`Extract`] [`TableOption`] to +//! produce a subsection of a [`Table`]. +//! +//! * [`Extract`] can return a new [`Table`] with three functions: +//! * `rows()` | yields subset of the initial rows +//! * `columns()` | yields subset of the initial columns +//! * `segment()` | yields subsection of the initial table +//! +//! * Note how [`Extract`] methods accepts [`RangeBounds`] arguments, +//! making subset specifications concise. + +use std::fmt::{Display, Formatter}; + +use tabled::{ + settings::{ + object::{Columns, Rows}, + Alignment, Extract, Format, Modify, Style, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct Album { + artist: &'static str, + name: &'static str, + released: &'static str, + level_of_greatness: LevelOfGreatness, +} + +impl Album { + fn new( + artist: &'static str, + name: &'static str, + released: &'static str, + level_of_greatness: LevelOfGreatness, + ) -> Self { + Self { + artist, + name, + released, + level_of_greatness, + } + } +} + +#[derive(Debug)] +enum LevelOfGreatness { + Supreme, + Outstanding, + Unparalleled, +} + +impl Display for LevelOfGreatness { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { + std::fmt::Debug::fmt(&self, f) + } +} + +fn main() { + use LevelOfGreatness::*; + + let data = [ + Album::new( + "Pink Floyd", + "The Dark Side of the Moon", + "01 March 1973", + Unparalleled, + ), + Album::new("Fleetwood Mac", "Rumours", "04 February 1977", Outstanding), + Album::new( + "Led Zeppelin", + "Led Zeppelin IV", + "08 November 1971", + Supreme, + ), + ]; + + println!("Full"); + + let mut table = Table::new(data); + table + .with(Style::modern()) + .with(Modify::new(Rows::first()).with(Alignment::center())) + .with(Modify::new(Rows::new(1..)).with(Alignment::left())); + println!("{table}"); + + println!("Segment row: (1..=2) column: (1..)"); + + let table = table.with(Extract::segment(1..=2, 1..)); + println!("{table}"); + + println!("Refinished segment"); + + let highlight = Format::content(|s| { + if s == "Outstanding" { + format!("+{s}+") + } else { + s.to_string() + } + }); + + let table = table + .with(Style::modern()) + .with(Modify::new(Columns::new(1..)).with(highlight)); + println!("{table}"); +} diff --git a/vendor/tabled/examples/format.rs b/vendor/tabled/examples/format.rs new file mode 100644 index 000000000..7dc4bddb2 --- /dev/null +++ b/vendor/tabled/examples/format.rs @@ -0,0 +1,56 @@ +//! This example demonstrates using the [`Format`] [`CellOption`] factory to alter +//! the cells of a [`Table`]. +//! +//! * Note how [`Format::content()`] gives access to the respective cell content for replacement. +//! And [`Format::positioned()`] additionally provides the index coordinates of that cell. +//! +//! * Note how the [std] [`format!`] macro is used to update the values of the affected cells. + +use tabled::{ + settings::{ + object::{Columns, Object, Rows}, + Format, Modify, Style, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct Commit { + id: &'static str, + header: &'static str, + message: &'static str, +} + +fn main() { + let data = [ + Commit { + header: "bypass open-source transmitter", + message: "index neural panel", + id: "8ae4e8957caeaa467acbce963701e227af00a1c7", + }, + Commit { + header: "program online alarm", + message: "copy bluetooth card", + id: "48c76de71bd685486d97dc8f4f05aa6fcc0c3f86", + }, + Commit { + header: "CSV", + message: "reboot mobile capacitor", + id: "6ffc2a2796229fc7bf59471ad907f58b897005d0", + }, + ]; + + let table = Table::new(data) + .with(Style::psql()) + .with( + Modify::new(Rows::first()) + .with(Format::positioned(|_, (_, column)| column.to_string())), + ) + .with( + Modify::new(Columns::first().not(Rows::first())) + .with(Format::content(|s| format!("{s}..."))), + ) + .to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/formatting_settings.rs b/vendor/tabled/examples/formatting_settings.rs new file mode 100644 index 000000000..19c8a4806 --- /dev/null +++ b/vendor/tabled/examples/formatting_settings.rs @@ -0,0 +1,47 @@ +//! This example demonstrates using the [`Alignment`], [`AlignmentStrategy`], and [`TrimStrategy`] [`CellOptions`] +//! to align the content of a [`Table`] in several nuanced ways. +//! +//! * Note how [`AlignmentStrategy`] and [`TrimStrategy`] provide useful tools for managing multiline cells and +//! cell values that are bloated with whitespace. + +use tabled::{ + settings::{ + formatting::{AlignmentStrategy, TrimStrategy}, + object::Segment, + Alignment, Modify, Style, + }, + Table, +}; + +fn main() { + let some_json = r#" +[ + "foo", + { + "bar": 1, + "baz": [ + 2, + 3 + ] + } +]"#; + + let mut table = Table::new([some_json]); + table + .with(Style::rounded()) + .with(Modify::new(Segment::all()).with(Alignment::center())); + + println!("A default Alignment settings\n{table}"); + + table.with(Modify::new(Segment::all()).with(AlignmentStrategy::PerLine)); + + println!("Per line Alignment strategy\n{table}"); + + table.with( + Modify::new(Segment::all()) + .with(AlignmentStrategy::PerCell) + .with(TrimStrategy::Both), + ); + + println!("A default Alignment; allowing vertical and horizontal trim\n{table}"); +} diff --git a/vendor/tabled/examples/grid_colors.rs b/vendor/tabled/examples/grid_colors.rs new file mode 100644 index 000000000..f48b39f49 --- /dev/null +++ b/vendor/tabled/examples/grid_colors.rs @@ -0,0 +1,46 @@ +//! This example demonstrates using [`Color`] as a [`CellOption`] modifier to stylize +//! the cells of a [`Table`]. +//! +//! * Note how the [`Color`] [setting](tabled::settings) is used to simplify creating +//! reusable themes for backgrounds. + +use tabled::{ + settings::{Color, Modify, Style}, + Table, Tabled, +}; + +#[derive(Tabled)] +struct Bsd { + distribution: &'static str, + year_of_first_release: usize, + is_active: bool, +} + +impl Bsd { + fn new(distribution: &'static str, year_of_first_release: usize, is_active: bool) -> Self { + Self { + distribution, + year_of_first_release, + is_active, + } + } +} + +fn main() { + let data = vec![ + Bsd::new("BSD", 1978, false), + Bsd::new("SunOS", 1982, false), + Bsd::new("NetBSD", 1993, true), + Bsd::new("FreeBSD", 1993, true), + Bsd::new("OpenBSD", 1995, true), + ]; + + let mut table = Table::new(data); + table + .with(Style::psql()) + .with(Modify::new((0, 0)).with(Color::BG_BLUE)) + .with(Modify::new((1, 1)).with(Color::BG_GREEN)) + .with(Modify::new((2, 2)).with(Color::BG_RED)); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/height.rs b/vendor/tabled/examples/height.rs new file mode 100644 index 000000000..2da0f36d9 --- /dev/null +++ b/vendor/tabled/examples/height.rs @@ -0,0 +1,49 @@ +//! This example demonstrates using the [`Height`] [`TableOption`] for adjusting +//! the height of a [`Table`]. +//! +//! * [`Height`] supports three key features: +//! * [`CellHeightIncrease`] spreads new whitespace between the [`Table`] +//! rows up to the specified line count. +//! * [`CellHeightLimit`] removes lines from the [`Table`] rows fairly, until +//! it has no choice but to remove single-line-rows entirely, bottom up. +//! * [`HeightList`] accepts an array of height specifications that are applied +//! to the rows with the same index. This is helpful for granularly specifying individual +//! row heights irrespective of [`Padding`] or [`Margin`]. + +use tabled::{ + settings::{peaker::PriorityMax, Height, Style}, + Table, +}; + +fn main() { + let data = vec![("Multi\nline\nstring", 123), ("Single line", 234)]; + + let mut table = Table::builder(data).build(); + table.with(Style::markdown()); + + println!("Table\n"); + println!("{table}"); + println!(); + + let table_ = table.clone().with(Height::increase(10)).to_string(); + + println!("Table increase height to 10\n"); + println!("{table_}"); + println!(); + + let table_ = table + .clone() + .with(Height::limit(4).priority::<PriorityMax>()) + .to_string(); + + println!("Table decrease height to 4\n"); + println!("{table_}"); + + let table_ = table + .clone() + .with(Height::limit(0).priority::<PriorityMax>()) + .to_string(); + + println!("Table decrease height to 0\n"); + println!("{table_}"); +} diff --git a/vendor/tabled/examples/highlight.rs b/vendor/tabled/examples/highlight.rs new file mode 100644 index 000000000..0b6abb8ad --- /dev/null +++ b/vendor/tabled/examples/highlight.rs @@ -0,0 +1,28 @@ +//! This example demonstrates using the [`Highlight`] [`TableOption`] to +//! decorate sections of a [`Table`] with a unique [`Border`]. +//! +//! * Note how [`Highlight`] arguments can be chained together to +//! create cross-sections and non-symmetrical shapes. + +use tabled::{ + settings::{ + object::{Columns, Object, Rows}, + style::{Border, Style}, + Highlight, + }, + Table, +}; + +fn main() { + let data = vec![["A", "B", "C"], ["D", "E", "F"], ["G", "H", "I"]]; + + let table = Table::new(data) + .with(Style::modern()) + .with(Highlight::new( + Rows::first().and(Columns::single(1)), + Border::filled('*'), + )) + .to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/highlight_color.rs b/vendor/tabled/examples/highlight_color.rs new file mode 100644 index 000000000..4646f3819 --- /dev/null +++ b/vendor/tabled/examples/highlight_color.rs @@ -0,0 +1,27 @@ +//! This example demonstrates using [`Highlight`] in combination with [`BorderColor`] to +//! frame sections of a [`Table`] with a unique background [`Color`]. +//! +//! * Note how [`Highlight::colored()`] is used to accept the necessary input instead of [`Highlight::new()`]. + +use tabled::{ + settings::{ + object::{Columns, Object, Rows}, + style::BorderColor, + Color, Highlight, Style, + }, + Table, +}; + +fn main() { + let data = vec![["A", "B", "C"], ["D", "E", "F"], ["G", "H", "I"]]; + + let table = Table::new(data) + .with(Style::modern()) + .with(Highlight::colored( + Rows::first().and(Columns::single(1)), + BorderColor::filled(Color::BG_BRIGHT_BLACK), + )) + .to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/hyperlink.rs b/vendor/tabled/examples/hyperlink.rs new file mode 100644 index 000000000..9fda7a040 --- /dev/null +++ b/vendor/tabled/examples/hyperlink.rs @@ -0,0 +1,83 @@ +//! This example demonstrates how hyperlinks can be embedded into a [`Table`] display. +//! +//! While not a [`tabled`] specific implementation, it is helpful to know that +//! most users expect certain elements of interactivity based on the purpose of your display. +//! +//! * 🚩 This example requires the `color` feature. +//! +//! * ⚠️ Terminal interfaces may differ in how they parse links or make them interactive. +//! [`tabled`] doesn't have the final say on whether a link is clickable or not. + +use tabled::{ + settings::{object::Segment, Alignment, Modify, Style, Width}, + Table, Tabled, +}; + +fn main() { + let multicolored_debian = "\x1b[30mDebian\x1b[0m\ + \x1b[31m Debian\x1b[0m\ + \x1b[32m Debian\x1b[0m\ + \x1b[33m Debian\x1b[0m\ + \x1b[34m Debian\x1b[0m\ + \x1b[35m Debian\x1b[0m\ + \x1b[36m Debian\x1b[0m\ + \x1b[37m Debian\x1b[0m\ + \x1b[40m Debian\x1b[0m\ + \x1b[41m Debian\x1b[0m\ + \x1b[42m Debian\x1b[0m\ + \x1b[43m Debian\x1b[0m\ + \x1b[44m Debian\x1b[0m"; + + let debian_repeat = + "DebianDebianDebianDebianDebianDebianDebianDebianDebianDebianDebianDebianDebianDebian" + .to_string(); + + let debian_colored_link = format_osc8_hyperlink("https://www.debian.org/", multicolored_debian); + let debian_link = format_osc8_hyperlink("https://www.debian.org/", "Debian"); + let wiki_link = format_osc8_hyperlink("https://www.wikipedia.org/", "Debian"); + + let data = [ + Distribution::new("Debian".into(), false), + Distribution::new(debian_link.clone(), true), + Distribution::new(format!("{debian_link} a link followed by text"), true), + Distribution::new( + format!("{debian_link} links with intervening text {wiki_link}"), + true, + ), + Distribution::new(format!("a link surrounded {debian_link} by text"), true), + Distribution::new(debian_colored_link, true), + Distribution::new(debian_repeat, false), + ]; + + let mut table = Table::new(&data); + table + .with(Style::ascii_rounded()) + .with(Alignment::left()) + .with(Modify::new(Segment::all()).with(Width::wrap(16).keep_words())); + + println!("{table}"); + + let mut table = Table::new(&data); + table + .with(Style::ascii_rounded()) + .with(Alignment::left()) + .with(Modify::new(Segment::all()).with(Width::wrap(16))); + + println!("{table}"); +} + +#[derive(Tabled)] +struct Distribution { + name: String, + is_hyperlink: bool, +} + +impl Distribution { + fn new(name: String, is_hyperlink: bool) -> Self { + Self { name, is_hyperlink } + } +} + +fn format_osc8_hyperlink(url: &str, text: &str) -> String { + format!("\x1b]8;;{url}\x1b\\{text}\x1b]8;;\x1b\\",) +} diff --git a/vendor/tabled/examples/iter_table.rs b/vendor/tabled/examples/iter_table.rs new file mode 100644 index 000000000..0a77f7435 --- /dev/null +++ b/vendor/tabled/examples/iter_table.rs @@ -0,0 +1,31 @@ +//! This example demonstrates using [`IterTable`], an [allocation](https://doc.rust-lang.org/nomicon/vec/vec-alloc.html) +//! free [`Table`] alternative that translates an iterator into a display. +//! +//! * Note how [`IterTable`] supports the familiar `.with()` syntax for applying display +//! modifications. +//! +//! * [`IterTable`] supports manual configuration of: +//! * Record sniffing (default 1000 rows) +//! * Row cutoff +//! * Row height +//! * Column cutoff +//! * Column width + +use std::io::BufRead; + +use tabled::{settings::Style, tables::IterTable}; + +fn main() { + let path = file!(); + let file = std::fs::File::open(path).unwrap(); + let reader = std::io::BufReader::new(file); + let iterator = reader.lines().enumerate().map(|(i, line)| match line { + Ok(line) => [i.to_string(), String::from("ok"), line], + Err(err) => [i.to_string(), String::from("error"), err.to_string()], + }); + + let table = IterTable::new(iterator).with(Style::ascii_rounded()); + + table.build(std::io::stdout()).unwrap(); + println!() +} diff --git a/vendor/tabled/examples/margin.rs b/vendor/tabled/examples/margin.rs new file mode 100644 index 000000000..97498fb40 --- /dev/null +++ b/vendor/tabled/examples/margin.rs @@ -0,0 +1,21 @@ +//! This example demonstrates using the [`Margin`] [`TableOption`] to buffer space +//! around a [`Table`] display. +//! +//! * Note how the [`Margin::fill()`] function allows for overriding the default whitespace +//! with any [`char`]. + +use tabled::{ + settings::{Margin, Style}, + Table, +}; + +fn main() { + let data = vec![["A", "B", "C"], ["D", "E", "F"], ["G", "H", "I"]]; + + let table = Table::new(data) + .with(Style::re_structured_text()) + .with(Margin::new(4, 3, 2, 1).fill('<', '>', 'v', '^')) + .to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/matrix.rs b/vendor/tabled/examples/matrix.rs new file mode 100644 index 000000000..59e22ae9c --- /dev/null +++ b/vendor/tabled/examples/matrix.rs @@ -0,0 +1,27 @@ +//! This example demonstrates how [`tabled`] is an excellent tool for creating +//! dataset visualizations. +//! +//! * 🚀 When native display solutions, such as the [`Debug`] trait and [pretty printing](https://doc.rust-lang.org/std/fmt/#sign0) +//! options, aren't enough, [`tabled`] is a great choice for improving the quality of your displays. + +use tabled::{settings::Style, Table}; + +fn matrix<const N: usize>() -> [[usize; N]; N] { + let mut matrix = [[0; N]; N]; + + #[allow(clippy::needless_range_loop)] + for i in 0..N { + for j in 0..N { + matrix[i][j] = (i + 1) * (j + 1); + } + } + + matrix +} + +fn main() { + let data = matrix::<10>(); + let table = Table::new(data).with(Style::modern()).to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/merge_duplicates.rs b/vendor/tabled/examples/merge_duplicates.rs new file mode 100644 index 000000000..250a95a56 --- /dev/null +++ b/vendor/tabled/examples/merge_duplicates.rs @@ -0,0 +1,58 @@ +//! This example demonstrates using the [`Merge`] [`TableOption`] to clarify +//! redundancies in a [`Table`] display. +//! +//! * Note how repetative entries must be consecutive, in their specified direction, +//! to be merged together. +//! +//! * Note how [`BorderSpanCorrection`] is used to resolve display issues incurred +//! from [`Span`] decisions made through duplicate detection. +//! +//! * Merge supports both [`Merge::vertical()`] and [`Merge::horizontal()`]. + +use tabled::{ + settings::{ + style::{BorderSpanCorrection, Style}, + Merge, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct DatabaseTable { + #[tabled(rename = "db")] + db_name: &'static str, + #[tabled(rename = "table")] + table_name: &'static str, + total: usize, +} + +impl DatabaseTable { + fn new(db_name: &'static str, table_name: &'static str, total: usize) -> Self { + Self { + db_name, + table_name, + total, + } + } +} + +fn main() { + let data = [ + DatabaseTable::new("database_1", "table_1", 10712), + DatabaseTable::new("database_1", "table_2", 57), + DatabaseTable::new("database_1", "table_3", 57), + DatabaseTable::new("database_2", "table_1", 72), + DatabaseTable::new("database_2", "table_2", 75), + DatabaseTable::new("database_3", "table_1", 20), + DatabaseTable::new("database_3", "table_2", 21339), + DatabaseTable::new("database_3", "table_3", 141723), + ]; + + let table = Table::new(data) + .with(Merge::vertical()) + .with(Style::modern()) + .with(BorderSpanCorrection) + .to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/merge_duplicates_2.rs b/vendor/tabled/examples/merge_duplicates_2.rs new file mode 100644 index 000000000..063664d3c --- /dev/null +++ b/vendor/tabled/examples/merge_duplicates_2.rs @@ -0,0 +1,78 @@ +//! This example demonstrates using the [`Merge`] [`TableOption`] to clarify +//! redundancies in a [`Table`] display. +//! +//! * Note how a custom theme is applied to give the [`Merged`](Merge) cells +//! a unique look. +//! +//! * Merge supports both [`Merge::vertical()`] and [`Merge::horizontal()`]. + +use tabled::{ + settings::{ + object::{Cell, Columns, Object, Rows}, + style::{Border, BorderSpanCorrection, Style}, + Merge, Modify, + }, + Table, Tabled, +}; + +fn main() { + let data = [ + DatabaseTable::new("database_1", "database_1", "table_1", 10712), + DatabaseTable::new("database_1", "database_1", "table_2", 57), + DatabaseTable::new("database_1", "database_1", "table_3", 57), + DatabaseTable::new("database_2", "", "table_1", 72), + DatabaseTable::new("database_2", "", "table_2", 75), + DatabaseTable::new("database_3", "database_3", "table_1", 20), + DatabaseTable::new("database_3", "", "table_2", 21339), + DatabaseTable::new("database_3", "", "table_3", 141723), + ]; + + let mut table = Table::builder(data).index().transpose().build(); + config_theme(&mut table); + table.with(Merge::horizontal()).with(BorderSpanCorrection); + + println!("{table}"); +} + +#[derive(Tabled)] +struct DatabaseTable { + #[tabled(rename = "db")] + db_name: &'static str, + origin_db: &'static str, + #[tabled(rename = "table")] + table_name: &'static str, + total: usize, +} + +impl DatabaseTable { + fn new( + db_name: &'static str, + origin_db: &'static str, + table_name: &'static str, + total: usize, + ) -> Self { + Self { + db_name, + origin_db, + table_name, + total, + } + } +} + +fn config_theme(table: &mut Table) { + table + .with(Style::rounded().remove_vertical()) + .with(Modify::new(Columns::first()).with(Border::default().right('│'))) + .with( + Modify::new(Cell::new(0, 0)).with( + Border::default() + .corner_top_right('┬') + .corner_bottom_right('┼'), + ), + ) + .with( + Modify::new(Columns::first().intersect(Rows::last())) + .with(Border::default().corner_bottom_right('┴')), + ); +} diff --git a/vendor/tabled/examples/nested_table.rs b/vendor/tabled/examples/nested_table.rs new file mode 100644 index 000000000..8884c81c1 --- /dev/null +++ b/vendor/tabled/examples/nested_table.rs @@ -0,0 +1,117 @@ +//! This example demonstrates how [`Tables`](Table) can be comprised of other tables. +//! +//! * This first nested [`Table`] example showcases the [`Builder`] approach. +//! +//! * Note how a great deal of manual customizations have been applied to create a +//! highly unique display. +//! +//! * 🎉 Inspired by https://github.com/p-ranav/tabulate#nested-tables/ + +use std::iter::FromIterator; + +use tabled::{ + builder::Builder, + settings::{ + object::{Rows, Segment}, + style::{HorizontalLine, Style}, + Alignment, Modify, Padding, Width, + }, + Table, +}; + +fn main() { + let animal = create_class( + "Animal", + &[("age", "Int", ""), ("gender", "String", "")], + &["isMammal", "mate"], + ); + + let duck = create_class( + "Duck", + &[("beakColor", "String", "yellow")], + &["swim", "quack"], + ); + + let mut table = Builder::from_iter([ + [animal.to_string()], + [String::from("▲")], + [String::from("|")], + [String::from("|")], + [duck.to_string()], + ]) + .build(); + table.with(Style::ascii().remove_horizontal()).with( + Modify::new(Segment::all()) + .with(Padding::new(5, 5, 0, 0)) + .with(Alignment::center()), + ); + + println!("{table}"); +} + +fn create_class(name: &str, fields: &[(&str, &str, &str)], methods: &[&str]) -> Table { + let fields = fields + .iter() + .map(|(field, t, d)| [format_field(field, t, d)]); + let mut table_fields = Builder::from_iter(fields).build(); + table_fields.with(Style::ascii().remove_horizontal().remove_vertical()); + + let methods = methods.iter().map(|method| [format_method(method)]); + let mut table_methods = Builder::from_iter(methods).build(); + table_methods.with(Style::ascii().remove_horizontal().remove_vertical()); + + let (table_fields, table_methods) = make_equal_width(table_fields, table_methods); + + let mut table = Builder::from_iter([ + [name.to_string()], + [table_fields.to_string()], + [table_methods.to_string()], + ]) + .build(); + + table + .with( + Style::ascii() + .horizontals([HorizontalLine::new(1, Style::ascii().get_horizontal())]) + .remove_horizontal() + .remove_vertical(), + ) + .with(Modify::new(Segment::all()).with(Alignment::left())) + .with(Modify::new(Rows::first()).with(Alignment::center())); + + table +} + +fn format_field(field: &&str, field_type: &&str, default_value: &&str) -> String { + if default_value.is_empty() { + format!("+{field}: {field_type}") + } else { + format!("+{field}: {field_type} = {default_value:?}") + } +} + +fn format_method(method: &str) -> String { + format!("+{method}()") +} + +fn make_equal_width(mut table1: Table, mut table2: Table) -> (Table, Table) { + // We want to make a fields table and methods table to have the same width. + // To not set it to constant, we check a width of each of them and correct the other. + // + // it's safe to do .len() because we use ascii theme and no colors. + + let table1_width = table1.to_string().lines().next().unwrap().len(); + let table2_width = table2.to_string().lines().next().unwrap().len(); + + match table1_width.cmp(&table2_width) { + std::cmp::Ordering::Less => { + table1.with(Width::increase(table2_width)); + } + std::cmp::Ordering::Greater => { + table2.with(Width::increase(table1_width)); + } + std::cmp::Ordering::Equal => (), + } + + (table1, table2) +} diff --git a/vendor/tabled/examples/nested_table_2.rs b/vendor/tabled/examples/nested_table_2.rs new file mode 100644 index 000000000..40b0cd0a9 --- /dev/null +++ b/vendor/tabled/examples/nested_table_2.rs @@ -0,0 +1,90 @@ +//! This example demonstrates a minimalist implementation of [`Tabling`](Table) records +//! with struct fields. +//! +//! * This second nested [`Table`] example showcases the [`derive`] approach. +//! +//! * Note how the [`display_with`] attribute macro applies the custom `display_distribution` +//! filter function, which, in this case, applies styles to the final display. + +use tabled::{settings::Style, Table, Tabled}; + +#[derive(Tabled)] +struct Vendor { + name: &'static str, + #[tabled(display_with = "display_distribution")] + main_os: Distribution, + #[tabled(display_with = "display_distribution")] + switch_os: Distribution, +} + +impl Vendor { + fn new(name: &'static str, main_os: Distribution, switch_os: Distribution) -> Self { + Self { + name, + main_os, + switch_os, + } + } +} + +fn display_distribution(d: &Distribution) -> String { + Table::new([d]).with(Style::extended()).to_string() +} + +#[derive(Tabled)] +struct Distribution { + name: &'static str, + #[tabled(display_with = "Self::display_based_on")] + based_on: Option<&'static str>, + is_active: bool, + is_cool: bool, +} + +impl Distribution { + fn display_based_on(o: &Option<&'static str>) -> String { + match o { + &Some(s) => s.into(), + None => "Independent".into(), + } + } +} + +impl Distribution { + fn new( + name: &'static str, + based_on: Option<&'static str>, + is_active: bool, + is_cool: bool, + ) -> Self { + Self { + name, + based_on, + is_active, + is_cool, + } + } +} + +fn main() { + let data = [ + Vendor::new( + "Azure", + Distribution::new("Windows", None, true, true), + Distribution::new("Manjaro", Some("Arch"), true, true), + ), + Vendor::new( + "AWS", + Distribution::new("Debian", None, true, true), + Distribution::new("Arch", None, true, true), + ), + Vendor::new( + "GCP", + Distribution::new("Debian", None, true, true), + Distribution::new("Arch", None, true, true), + ), + ]; + + let table = Table::new(data).with(Style::modern()).to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/nested_table_3.rs b/vendor/tabled/examples/nested_table_3.rs new file mode 100644 index 000000000..8e79b27a5 --- /dev/null +++ b/vendor/tabled/examples/nested_table_3.rs @@ -0,0 +1,56 @@ +//! This example demonstrates creating a nested [`Table`] by instantiating a new +//! [`Table`] from a collection of other [`Tables`](Table). +//! +//! * This third nested [`Table`] example showcases the [`Table::new()`] approach. + +use tabled::{ + settings::{ + object::{Cell, Segment}, + Alignment, Border, Extract, Highlight, Modify, Panel, Style, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct Contribution { + author: &'static str, + profile: &'static str, +} + +impl Contribution { + fn new(author: &'static str, profile: &'static str) -> Self { + Self { author, profile } + } +} + +fn main() { + let committers = [ + Contribution::new("kozmod", "https:/github.com/kozmod"), + Contribution::new("IsaacCloos", "https:/github.com/IsaacCloos"), + ]; + + let issuers = [Contribution::new( + "aharpervc", + "https:/github.com/aharpervc", + )]; + + let committers_table = Table::new(committers) + .with(Panel::header("Contributors")) + .with(Modify::new(Segment::all()).with(Alignment::center())) + .to_string(); + + let issues_table = Table::new(issuers) + .with(Panel::header("Issuers")) + .with(Modify::new(Segment::all()).with(Alignment::center())) + .to_string(); + + let mut a_welcome_table = + Table::new([String::from("Thank You"), committers_table, issues_table]); + a_welcome_table + .with(Extract::rows(1..)) + .with(Style::ascii().remove_horizontal()) + .with(Modify::new(Segment::all()).with(Alignment::center())) + .with(Highlight::new(Cell::new(0, 0), Border::filled('*'))); + + println!("{a_welcome_table}"); +} diff --git a/vendor/tabled/examples/panel.rs b/vendor/tabled/examples/panel.rs new file mode 100644 index 000000000..343abcd67 --- /dev/null +++ b/vendor/tabled/examples/panel.rs @@ -0,0 +1,63 @@ +//! This example demonstrates using the [`Panel`] [`TableOption`] to inject +//! table-length columns and rows into a [`Table`]. +//! +//! * [`Panel`] supports four injection options: +//! * Horizontal | manual index selection +//! * Vertical | manual index selection +//! * Header | before first row +//! * Footer | after last row + +use tabled::{ + settings::{ + object::Segment, + style::{BorderSpanCorrection, Style}, + Alignment, Modify, Panel, Width, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct Release { + version: &'static str, + published_date: &'static str, + is_active: bool, + major_feature: &'static str, +} + +impl Release { + const fn new( + version: &'static str, + published_date: &'static str, + is_active: bool, + major_feature: &'static str, + ) -> Self { + Self { + version, + published_date, + is_active, + major_feature, + } + } +} + +const DATA: [Release; 3] = [ + Release::new("0.2.1", "2021-06-23", true, "#[header(inline)] attribute"), + Release::new("0.2.0", "2021-06-19", false, "API changes"), + Release::new("0.1.4", "2021-06-07", false, "display_with attribute"), +]; + +fn main() { + let mut table = Table::new(DATA); + table + .with(Panel::header("Tabled Releases")) + .with(Panel::footer(format!("N - {}", DATA.len()))) + .with(Panel::vertical(0, "Some text goes here")) + .with(Panel::vertical(5, "Some text goes here")) + .with(Modify::new((0, 0)).with(Width::wrap(1))) + .with(Modify::new((0, 5)).with(Width::wrap(1))) + .with(Modify::new(Segment::all()).with(Alignment::center())) + .with(Style::modern()) + .with(BorderSpanCorrection); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/pool_table.rs b/vendor/tabled/examples/pool_table.rs new file mode 100644 index 000000000..593631e06 --- /dev/null +++ b/vendor/tabled/examples/pool_table.rs @@ -0,0 +1,33 @@ +//! This example demonstrates a [`PoolTable`] usage. + +use tabled::{ + settings::{Alignment, Style}, + tables::{PoolTable, TableValue}, +}; + +fn main() { + let data = vec![ + vec!["Hello World", "Hello World", "Hello World"], + vec!["Hello", "", "Hello"], + vec!["W", "o", "r", "l", "d"], + ]; + + let data = TableValue::Column( + data.into_iter() + .map(|row| { + TableValue::Row( + row.into_iter() + .map(|text| TableValue::Cell(text.to_owned())) + .collect(), + ) + }) + .collect(), + ); + + let table = PoolTable::from(data) + .with(Style::modern()) + .with(Alignment::center()) + .to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/pool_table2.rs b/vendor/tabled/examples/pool_table2.rs new file mode 100644 index 000000000..02b457250 --- /dev/null +++ b/vendor/tabled/examples/pool_table2.rs @@ -0,0 +1,26 @@ +//! This example demonstrates a [`PoolTable`] usage. + +use tabled::{ + settings::{Alignment, Style}, + tables::PoolTable, +}; + +fn main() { + let characters = [ + "Naruto Uzumaki", + "Kakashi Hatake", + "Minato Namikaze", + "Jiraiya", + "Orochimaru", + "Itachi Uchiha", + ]; + + let data = characters.chunks(2); + + let table = PoolTable::new(data) + .with(Style::dots()) + .with(Alignment::center()) + .to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/rotate.rs b/vendor/tabled/examples/rotate.rs new file mode 100644 index 000000000..8db997527 --- /dev/null +++ b/vendor/tabled/examples/rotate.rs @@ -0,0 +1,38 @@ +//! This example demonstrates using the [`Rotate`] [`TableOption`] to rotate the cells +//! of a [`Table`]. +//! +//! * [`Rotate`] supports four motions: +//! * `Left` | 90 degree shift +//! * `Right` | 90 degree shift +//! * `Top` & `Bottom` | Reverse row order + +use tabled::{settings::Rotate, Table, Tabled}; + +#[derive(Tabled)] +struct Linux { + id: u8, + distribution: &'static str, + link: &'static str, +} + +impl Linux { + fn new(id: u8, distribution: &'static str, link: &'static str) -> Self { + Self { + id, + distribution, + link, + } + } +} + +fn main() { + let data = vec![ + Linux::new(0, "Fedora", "https://getfedora.org/"), + Linux::new(2, "OpenSUSE", "https://www.opensuse.org/"), + Linux::new(3, "Endeavouros", "https://endeavouros.com/"), + ]; + + let table = Table::new(data).with(Rotate::Left).to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/settings_list.rs b/vendor/tabled/examples/settings_list.rs new file mode 100644 index 000000000..b0b0aca4c --- /dev/null +++ b/vendor/tabled/examples/settings_list.rs @@ -0,0 +1,57 @@ +//! This example demonstrates using the [`Settings`] [`TableOption`] to array +//! [`Table`] configurations in a separate step from instantiation. +//! +//! * Note how this methodoly can lead to huge performance gains +//! with compile-time constants. + +use tabled::{ + settings::{ + object::{FirstRow, Rows}, + style::On, + Alignment, Modify, ModifyList, Padding, Settings, Style, + }, + Table, Tabled, +}; + +#[derive(Tabled)] +struct CodeEditor { + name: &'static str, + first_release: &'static str, + developer: &'static str, +} + +impl CodeEditor { + fn new(name: &'static str, first_release: &'static str, developer: &'static str) -> Self { + Self { + name, + first_release, + developer, + } + } +} + +// unfortunately we can't leave it as a blank type, so we need to provide it. +type TableTheme = Settings< + Settings<Settings<Settings, Style<On, On, On, On, On, On>>, Padding>, + ModifyList<FirstRow, Alignment>, +>; + +const THEME: TableTheme = Settings::empty() + .with(Style::ascii()) + .with(Padding::new(1, 3, 0, 0)) + .with(Modify::list(Rows::first(), Alignment::center())); + +fn main() { + let data = [ + CodeEditor::new("Sublime Text 3", "2008", "Sublime HQ"), + CodeEditor::new("Visual Studio Code", "2015", "Microsoft"), + CodeEditor::new("Notepad++", "2003", "Don Ho"), + CodeEditor::new("GNU Emacs", "1984", "Richard Stallman"), + CodeEditor::new("Neovim", "2015", "Vim community"), + ]; + + let mut table = Table::new(data); + table.with(THEME); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/shadow.rs b/vendor/tabled/examples/shadow.rs new file mode 100644 index 000000000..baa856ed9 --- /dev/null +++ b/vendor/tabled/examples/shadow.rs @@ -0,0 +1,160 @@ +//! This example can be run with the following command: +//! +//! `echo -e -n 'Some text\nIn the box' | cargo run --example shadow` +//! +//! This example demonstrates using the [`Shadow`] [`TableOption`] to create +//! a striking frame around a [`Table`] display. +//! +//! * [`Shadow`] supports several configurations: +//! * Thickness +//! * Offset +//! * Direction +//! * Color +//! * Fill character +//! +//! * 🎉 Inspired by <https://en.wikipedia.org/wiki/Box-drawing_character> + +use std::{io::Read, iter::FromIterator}; + +use tabled::{ + builder::Builder, + grid::util::string, + row, + settings::{ + object::Cell, + style::{BorderChar, Offset, RawStyle, Style}, + Height, Modify, Padding, Shadow, Width, + }, + Table, +}; + +fn main() { + let message = read_message(); + print_table(message); +} + +fn print_table(message: String) { + let main_table = create_main_table(&message); + let main_table_width = main_table.total_width(); + let small_table_row = create_small_table_list(main_table_width); + println!("{small_table_row}"); + println!("{main_table}"); +} + +fn read_message() -> String { + let mut buf = String::new(); + std::io::stdin().read_to_string(&mut buf).unwrap(); + + buf +} + +fn create_small_table_list(width_available: usize) -> String { + let mut tables = [ + create_small_table(Style::modern().into()), + create_small_table(Style::extended().into()), + create_small_table( + Style::modern() + .left('║') + .right('║') + .intersection_left('╟') + .intersection_right('╢') + .corner_top_right('╖') + .corner_top_left('╓') + .corner_bottom_right('╜') + .corner_bottom_left('╙') + .into(), + ), + create_small_table( + Style::modern() + .top('═') + .bottom('═') + .corner_top_right('╕') + .corner_top_left('╒') + .corner_bottom_right('╛') + .corner_bottom_left('╘') + .horizontal('═') + .intersection_left('╞') + .intersection_right('╡') + .intersection_top('╤') + .intersection_bottom('╧') + .intersection('╪') + .into(), + ), + ]; + const TOTAL_TABLE_WIDTH: usize = 19; + + if width_available > TOTAL_TABLE_WIDTH { + let mut rest = width_available - TOTAL_TABLE_WIDTH; + while rest > 0 { + for table in &mut tables { + let current_width = table.total_width(); + table.with(Width::increase(current_width + 1)); + rest -= 1; + + if rest == 0 { + break; + } + } + } + } + + let small_table_row = row![tables[0], tables[1], tables[2], tables[3]] + .with(Style::blank()) + .with(Padding::zero()) + .to_string(); + small_table_row +} + +fn create_small_table(style: RawStyle) -> Table { + let mut table = Builder::from_iter(vec![vec![" ", ""], vec![" ", ""]]).build(); + table + .with(style) + .with(Padding::zero()) + .with(Height::list([1, 0])); + + table +} + +fn create_main_table(message: &str) -> Table { + let (count_lines, message_width) = string::string_dimension(message); + let count_additional_separators = if count_lines > 2 { count_lines - 2 } else { 0 }; + + let left_table = format!( + " ╔═══╗ \n ╚═╦═╝ \n{}═╤══╩══╤\n ├──┬──┤\n └──┴──┘", + (0..count_additional_separators) + .map(|_| " ║ \n") + .collect::<String>() + ); + + let message = if count_lines < 2 { + let mut i = count_lines; + let mut buf = message.to_string(); + while i < 2 { + buf.push('\n'); + i += 1; + } + + buf + } else { + message.to_owned() + }; + let count_lines = count_lines.max(2); + + let message = format!("{}\n{}", message, "═".repeat(message_width)); + + let mut table = row![left_table, message]; + table + .with(Padding::zero()) + .with(Style::modern().remove_vertical()) + .with( + Modify::new(Cell::new(0, 0)) + .with(BorderChar::vertical('╞', Offset::Begin(count_lines))), + ) + .with( + Modify::new(Cell::new(0, 2)) + .with(BorderChar::vertical('╡', Offset::Begin(count_lines))), + ) + .with(Shadow::new(2)); + + table +} diff --git a/vendor/tabled/examples/span.rs b/vendor/tabled/examples/span.rs new file mode 100644 index 000000000..e6a75576a --- /dev/null +++ b/vendor/tabled/examples/span.rs @@ -0,0 +1,40 @@ +//! This example demonstrates using the [`Span`] [`CellOption`] to +//! extend [Cells](Cell) over a specified number of columns/rows. +//! +//! * Note how [`Span`] is available for [`Cell`] modifications +//! after the [`Modify`] [`TableOption`] is applied. +//! +//! * ⚠️ `with()` is a reused pattern within [`tabled`] for both [`Table`] +//! and [`Cell`] modifications. It can be easy for beginners to mistakenly +//! try to pass [`settings`] intended for one to the other. + +use tabled::{ + settings::{ + object::Cell, + style::{BorderSpanCorrection, Style}, + Alignment, Modify, Span, + }, + Table, +}; + +fn main() { + let data = [["just 1 column"; 5]; 5]; + + let h_span = |r, c, span| Modify::new(Cell::new(r, c)).with(Span::row(span)); + let v_span = |r, c, span| Modify::new(Cell::new(r, c)).with(Span::column(span)); + + let table = Table::new(data) + .with(h_span(0, 0, 5).with("span all 5 columns")) + .with(h_span(1, 0, 4).with("span 4 columns")) + .with(h_span(2, 0, 2).with("span 2 columns")) + .with(v_span(2, 4, 4).with("just 1 column\nspan\n4\ncolumns")) + .with(v_span(3, 1, 2).with("span 2 columns\nspan\n2\ncolumns")) + .with(v_span(2, 3, 3).with("just 1 column\nspan\n3\ncolumns")) + .with(h_span(3, 1, 2)) + .with(Style::modern()) + .with(BorderSpanCorrection) + .with(Alignment::center_vertical()) + .to_string(); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/split.rs b/vendor/tabled/examples/split.rs new file mode 100644 index 000000000..d8e6c679a --- /dev/null +++ b/vendor/tabled/examples/split.rs @@ -0,0 +1,43 @@ +//! This example demonstrates using the [`Split`] [`TableOption`] to +//! transform a [`Table`] display in multiple ways. +//! +//! * Several configurations are available to customize a [`Split`] instruction: +//! * [`Index`](usize) +//! * [`Behavior`] +//! * [`Direction`] +//! * [`Display`] + +use std::iter::FromIterator; +use tabled::{ + col, row, + settings::{split::Split, style::Style, Padding}, + Table, +}; + +fn main() { + let mut table = Table::from_iter(['a'..='z']); + table.with(Style::modern()); + + let table_1 = table.clone().with(Split::column(12)).clone(); + let table_2 = table_1.clone().with(Split::column(2).zip()).to_string(); + let table_3 = table_1.clone().with(Split::column(2).concat()).to_string(); + let table_4 = table_1.clone().with(Split::row(2).zip()).to_string(); + let table_5 = table_1.clone().with(Split::row(2).concat()).to_string(); + + let mut table = col![ + table, + row![ + table_1, + table_2, + table_3, + col![table_4, table_5] + .with(Style::blank()) + .with(Padding::zero()) + ] + .with(Style::blank()) + .with(Padding::zero()), + ]; + table.with(Style::blank()); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/table.rs b/vendor/tabled/examples/table.rs new file mode 100644 index 000000000..d6d5c392c --- /dev/null +++ b/vendor/tabled/examples/table.rs @@ -0,0 +1,56 @@ +//! This example demonstrates the fundemental qualities of the [crate](https://crates.io/crates/tabled) [`tabled`]. +//! +//! * [`tabled`] is powered by convenient [procedural macros](https://doc.rust-lang.org/reference/procedural-macros.html#procedural-macros) +//! like [`Tabled`]; a deriveable trait that allows your custom +//! structs and enums to be represented with [`tabled`]'s powerful suite of features. +//! +//! * [`Table`] is the root object to which all of [`tabled`]'s implementation +//! tools guide you, and from which all of its customization options derive value. +//! The READMEs, examples, and docs found in this project will show you many dozens +//! of ways you can build tables, and show you how to use the available tools +//! to build the data representations that best fit your needs. +//! +//! * [`Table::with()`] plays a central role in giving the user control over their +//! displays. A majority of [`Table`] customizations are implemented through this highly +//! dynamic function. A few [`TableOptions`](TableOption) include: +//! * [`Style`] +//! * [`Modify`] +//! * [`Alignment`] +//! * [`Padding`] + +use tabled::{ + settings::{object::Rows, Alignment, Modify, Style}, + Table, Tabled, +}; + +#[derive(Debug, Tabled)] +struct Distribution { + name: String, + based_on: String, + is_active: bool, +} + +impl Distribution { + fn new(name: &str, base: &str, is_active: bool) -> Self { + Self { + based_on: base.to_owned(), + name: name.to_owned(), + is_active, + } + } +} + +fn main() { + let data = [ + Distribution::new("Debian", "", true), + Distribution::new("Arch", "", true), + Distribution::new("Manjaro", "Arch", true), + ]; + + let mut table = Table::new(data); + table + .with(Style::markdown()) + .with(Modify::new(Rows::first()).with(Alignment::center())); + + println!("{table}"); +} diff --git a/vendor/tabled/examples/table_width.rs b/vendor/tabled/examples/table_width.rs new file mode 100644 index 000000000..372adb489 --- /dev/null +++ b/vendor/tabled/examples/table_width.rs @@ -0,0 +1,40 @@ +//! This example demonstrates using the [`Width`] [`TableOption`] to expand and +//! contract a [`Table`] display. +//! +//! * Note how table-wide size adjustments are applied proportionally to all columns. +//! +//! * Note how [fluent](https://en.wikipedia.org/wiki/Fluent_interface) functions +//! are available to make subtle customizations to [`Width`] primary features like +//! [`Width::truncate()`], [`Width::increase()`], and [`Width::wrap()`]. + +use tabled::{ + settings::{measurement::Percent, object::Segment, Alignment, Modify, Style, Width}, + Table, +}; + +fn main() { + let data = [ + ["Hello World!!!", "3.3.22.2"], + ["Guten Morgen", "1.1.1.1"], + ["Добры вечар", "127.0.0.1"], + ["Bonjour le monde", ""], + ["Ciao mondo", ""], + ]; + + let mut table = Table::builder(data).build(); + table.with(Style::markdown()).with(Alignment::left()); + + println!("Original table\n{table}\n"); + + table.with(Width::truncate(20).suffix("...")); + + println!("Truncated table\n{table}\n"); + + table.with(Modify::new(Segment::all()).with(Width::wrap(5))); + + println!("Wrapped table\n{table}\n"); + + table.with(Width::increase(Percent(200))); + + println!("Widen table\n{table}"); +} diff --git a/vendor/tabled/examples/table_width_2.rs b/vendor/tabled/examples/table_width_2.rs new file mode 100644 index 000000000..d2601fc87 --- /dev/null +++ b/vendor/tabled/examples/table_width_2.rs @@ -0,0 +1,23 @@ +//! This example demonstrates using [`Wrap::keep_words()`] to preserve +//! word shape while truncating a table to the specified size. Without +//! this setting enabled, a word could possibly be split into pieces, +//! greatly reducing the legibility of the display. + +use tabled::{ + settings::{object::Segment, Alignment, Modify, Style, Width}, + Table, +}; + +fn main() { + let readme_text = include_str!("../../CHANGELOG.md"); + let lines = readme_text.lines().filter(|s| !s.is_empty()).enumerate(); + + let mut table = Table::new(lines); + table.with(Style::ascii_rounded()).with( + Modify::new(Segment::all()) + .with(Width::wrap(30).keep_words()) + .with(Alignment::left()), + ); + + println!("{table}"); +} |