@@ -1324,7 +1324,6 @@ func TestContentWrapping(t *testing.T) {
1324
1324
1325
1325
golden .RequireEqual (t , []byte (table .String ()))
1326
1326
})
1327
-
1328
1327
}
1329
1328
}
1330
1329
@@ -1655,111 +1654,32 @@ func stripString(str string) string {
1655
1654
1656
1655
// Examples
1657
1656
1658
- func ExampleWrap () {
1659
- tests := []struct {
1660
- name string
1661
- headers []string
1662
- data [][]string
1663
- }{
1664
- {
1665
- "long row content" ,
1666
- []string {"Name" , "Description" , "Type" , "Required" , "Default" },
1667
- [][]string {{"command" , "A command to be executed inside the container to assess its health. Each space delimited token of the command is a separate array element. Commands exiting 0 are considered to be successful probes, whilst all other exit codes are considered failures." , "yes" , "hello" , "yep" }},
1668
- },
1669
- {
1670
- "missing row content" ,
1671
- []string {"Name" , "Description" , "Type" , "Required" , "Default" },
1672
- [][]string {{"command" , "A command to be executed inside the container to assess its health. Each space delimited token of the command is a separate array element. Commands exiting 0 are considered to be successful probes, whilst all other exit codes are considered failures." , "yes" , "" , "" }},
1673
- },
1674
- {
1675
- "long header content, long and short rows" ,
1676
- []string {"Destination" , "Why are you going on this trip? Is it a hot or cold climate?" , "Affordability" },
1677
- [][]string {
1678
- {"Mexico" , "I want to go somewhere hot, dry, and affordable. Mexico has really good food, just don't drink tap water!" , "$" },
1679
- {"New York" , "I'm thinking about going during the Christmas season to check out Rockefeller center. Might be cold though..." , "$$$" },
1680
- {"California" , "" , "$$$" },
1681
- },
1682
- },
1657
+ func ExampleTable_Wrap () {
1658
+ // Long text, different languages
1659
+ headers := []string {"Hello" , "ไฝ ๅฅฝ" , "ู
ุฑุญุจูุง" , "์๋
ํ์ธ์" }
1660
+ data := [][]string {
1683
1661
{
1684
- "Long text, different languages" ,
1685
- []string {"Hello" , "ไฝ ๅฅฝ" , "ู
ุฑุญุจูุง" , "์๋
ํ์ธ์" },
1686
- [][]string {
1687
- {
1688
- "Lorem ipsum dolor sit amet, regione detracto eos an. Has ei quidam hendrerit intellegebat, id tamquam iudicabit necessitatibus ius, at errem officiis hendrerit mei. Exerci noster at has, sit id tota convenire, vel ex rebum inciderint liberavisse. Quaeque delectus corrumpit cu cum." ,
1689
- `่่จฑใฑใจใซใ่ชฟๅบใใ็ฃไปถใณ็ๅฅใใณๅ็ตฆ็ฝใฌใใๆจฉ่ผใขใจใไผๅฒใใ้ฟ3็พใจใๆๆใใ ใณใป็ตๆฉใ ใคใกใๆๆใจใฏ็พ็พฉใชใใ่ซๆ
ใใใใฆๆถไธป็ฎกๅทใใงใตใใๆใใใคใ็พๅใฑใๅบ่ฆใๅ่
ใชๆ่ฑใใใญใ่ซ็ดขใขใใใคไปปๅในใฒ่ฉฑ็ ดใชใคใจ็งๆญขๅฃใคใปใฝในๆญขๅคฎใฎใ้ฃๅจๅฅใงใฆใคใ ๅฎ้ใ่ชญ่ด้ๅฎนใฒใในใ้ใใใใฅๅธๅฑ
ใใ ใค็ ๆ ก35ๅฒฉ6็นนใใใฏๅ ฑๆใค้ฉๆทฑ52็ใใฌในใ็ฉถๆฑในใฉ่ก3้ใฉ้ฒๅ ใในใ
1662
+ "Lorem ipsum dolor sit amet, regione detracto eos an. Has ei quidam hendrerit intellegebat, id tamquam iudicabit necessitatibus ius, at errem officiis hendrerit mei. Exerci noster at has, sit id tota convenire, vel ex rebum inciderint liberavisse. Quaeque delectus corrumpit cu cum." ,
1663
+ `่่จฑใฑใจใซใ่ชฟๅบใใ็ฃไปถใณ็ๅฅใใณๅ็ตฆ็ฝใฌใใๆจฉ่ผใขใจใไผๅฒใใ้ฟ3็พใจใๆๆใใ ใณใป็ตๆฉใ ใคใกใๆๆใจใฏ็พ็พฉใชใใ่ซๆ
ใใใใฆๆถไธป็ฎกๅทใใงใตใใๆใใใคใ็พๅใฑใๅบ่ฆใๅ่
ใชๆ่ฑใใใญใ่ซ็ดขใขใใใคไปปๅในใฒ่ฉฑ็ ดใชใคใจ็งๆญขๅฃใคใปใฝในๆญขๅคฎใฎใ้ฃๅจๅฅใงใฆใคใ ๅฎ้ใ่ชญ่ด้ๅฎนใฒใในใ้ใใใใฅๅธๅฑ
ใใ ใค็ ๆ ก35ๅฒฉ6็นนใใใฏๅ ฑๆใค้ฉๆทฑ52็ใใฌในใ็ฉถๆฑในใฉ่ก3้ใฉ้ฒๅ ใในใ
1690
1664
็ฆใซใณใๅฟๅบทใใปใใซ้จฐ่ฌใญใฉไบ่ถ
ในใใใ็่กจไฝใซใข่ชๆตฉใฒใทใๅณๅฎข็ทใใต้็ใฑใผใพๅๆๆๆ็ผ่ฉ้ขใใใๆๅผทใใณใใปไพกไฟใญๆ85ๅฒกใขใๆๅฐใฒใใใชๅไธฆใใๅบๆฅใผใใใ็น็ฎใฒใฆๆญข็ฐๅ
ฌใใฌไบๅฟใฟในๅฟ
ๆธใฟใกใ ใๅฝ84็กไฟกๅใกใฒใใไพกใผใไธญๅฎขใใตๅ่ฆงใจใใๆฅตๆดใฉๅพ95็จฟใฏใใฉใๆฑๅฉในๅฎไธธ้ใ่ๆดใน้ๅฐใๆฅญๅทจ่ทใใฉใๅๅ
ใใชใ` ,
1691
- "ุดูุก ูุฏ ููุญููู
ุฉ ูุงูููุฑู ุงูุฃูุฑูุจูููู, ุจูุงุจุฉ ุชุนุฏูู ูุงุนุชูุงุก ุถุฑุจ ุจู. ุฅุฐ ุฃุณุฑ ุงุชูุฌุฉ ุงุนูุงู, ูฃู ุงูุชูุจุฑ ุงูุนุตุจุฉ ุงุณุชู
ุฑุงุฑ ูู
ู. ุฃูุงู ููุณูุทุฑุฉ ุงูุชุงุฑูุฎุ ู
ุน ุจุญุซ, ููู ุงุชูุฌุฉ ุงูููู ู
ุน. ูุจุนุฏ ุงูุทุงููุงุ ุชู
ุญุชู, ููู ุชู
ุฌุณูู
ุฉ ุงูุฅุญุชูุงุธ ูุจุงุณุชุซูุงุก, ุนู ูุฑูุณุง ูุงูุชูุงุกู ุงูุฅูุชุตุงุฏูุฉ ุนุฑุถ. ููุชุฌ ุฏุฃุจูุง ุฅุญูุงู
ุจุงู ุฅุฐ. ูุบุงุช ุนู
ููุฉ ูุชู
ู
ุน, ูุตู ุจุฏุงูุฉ ูุจุบุทุงุก ุงูุจุฑูุฉ ุจู, ุฃู ูุฑุฑุช ุจูุงุฏู ููุงูุช ุญุฏู" ,
1692
- "็ๅฟ้ๆฝ้จไธญๅน็ๅถๅ ฑ้ๆกๅ่ฆๅฃๅบใๅๅฅๅฟ
ๆจฉๆฌก่ฆง็ทจไปๆญ้ๅ ดๅ
ๅๆฐๆฑๆทฑ็ฐฟไปฃไพไพใๅฎ่ๆธ็ฅ็งๅๆตๆฑๆณขๆ้็งใๆชๆ ผๆๅฅฝไฝๅจๆฅๅฉ้ชๆ่ฅฟ็ฆๆไธๅฅณใๆจฉๅนฝๅๅญฃ่ฒ ๅจ่ณผๅๆง่ณๅฅ่ผๅกๅผๆดป้ธใๆชๅๆ กๆ้บ็ถ่กๅ่ฟๆฎๅบ็ฅ่งไบกๅฟไธ่ชฌ็ฉบไฝใๆณ็ๅฝๆญปๅนดๅ็ตก่ๆนๅๆๅฅใๅฎคๅๆงๅฑฑๅคฉๆ
ๆ็ป่ฉณ็ฅๆต
ๆน่ฃใๅคๆฟไผ้ไธญ้ๅ็่ผๅ
้้ก็ซฏๅใไธญๅฟ
ๅฐ้้ ไบๅฏๆฐ็ต่ฝๅไฝ่" ,
1693
- "๊ฐ๊ธ ์ ๊ฑฐ๊ด๋ฆฌ์์ํ์ ์กฐ์งยท์ง๋ฌด๋ฒ์ ๊ธฐํ ํ์ํ ์ฌํญ์ ๋ฒ๋ฅ ๋ก ์ ํ๋ค. ์์ํ์ ํ๊ธฐ๋ 30์ผ์ ์ด๊ณผํ ์ ์๋ค. ๊ตญ๊ฐ๋ ์ฌ์์ ๋ณต์ง์ ๊ถ์ต์ ํฅ์์ ์ํ์ฌ ๋
ธ๋ ฅํ์ฌ์ผ ํ๋ค. ๊ตญ๊ตฐ์ ์กฐ์ง๊ณผ ํธ์ฑ์ ๋ฒ๋ฅ ๋ก ์ ํ๋ค." ,
1694
- },
1695
- },
1665
+ "ุดูุก ูุฏ ููุญููู
ุฉ ูุงูููุฑู ุงูุฃูุฑูุจูููู, ุจูุงุจุฉ ุชุนุฏูู ูุงุนุชูุงุก ุถุฑุจ ุจู. ุฅุฐ ุฃุณุฑ ุงุชูุฌุฉ ุงุนูุงู, ูฃู ุงูุชูุจุฑ ุงูุนุตุจุฉ ุงุณุชู
ุฑุงุฑ ูู
ู. ุฃูุงู ููุณูุทุฑุฉ ุงูุชุงุฑูุฎุ ู
ุน ุจุญุซ, ููู ุงุชูุฌุฉ ุงูููู ู
ุน. ูุจุนุฏ ุงูุทุงููุงุ ุชู
ุญุชู, ููู ุชู
ุฌุณูู
ุฉ ุงูุฅุญุชูุงุธ ูุจุงุณุชุซูุงุก, ุนู ูุฑูุณุง ูุงูุชูุงุกู ุงูุฅูุชุตุงุฏูุฉ ุนุฑุถ. ููุชุฌ ุฏุฃุจูุง ุฅุญูุงู
ุจุงู ุฅุฐ. ูุบุงุช ุนู
ููุฉ ูุชู
ู
ุน, ูุตู ุจุฏุงูุฉ ูุจุบุทุงุก ุงูุจุฑูุฉ ุจู, ุฃู ูุฑุฑุช ุจูุงุฏู ููุงูุช ุญุฏู" ,
1666
+ "็ๅฟ้ๆฝ้จไธญๅน็ๅถๅ ฑ้ๆกๅ่ฆๅฃๅบใๅๅฅๅฟ
ๆจฉๆฌก่ฆง็ทจไปๆญ้ๅ ดๅ
ๅๆฐๆฑๆทฑ็ฐฟไปฃไพไพใๅฎ่ๆธ็ฅ็งๅๆตๆฑๆณขๆ้็งใๆชๆ ผๆๅฅฝไฝๅจๆฅๅฉ้ชๆ่ฅฟ็ฆๆไธๅฅณใๆจฉๅนฝๅๅญฃ่ฒ ๅจ่ณผๅๆง่ณๅฅ่ผๅกๅผๆดป้ธใๆชๅๆ กๆ้บ็ถ่กๅ่ฟๆฎๅบ็ฅ่งไบกๅฟไธ่ชฌ็ฉบไฝใๆณ็ๅฝๆญปๅนดๅ็ตก่ๆนๅๆๅฅใๅฎคๅๆงๅฑฑๅคฉๆ
ๆ็ป่ฉณ็ฅๆต
ๆน่ฃใๅคๆฟไผ้ไธญ้ๅ็่ผๅ
้้ก็ซฏๅใไธญๅฟ
ๅฐ้้ ไบๅฏๆฐ็ต่ฝๅไฝ่" ,
1667
+ "๊ฐ๊ธ ์ ๊ฑฐ๊ด๋ฆฌ์์ํ์ ์กฐ์งยท์ง๋ฌด๋ฒ์ ๊ธฐํ ํ์ํ ์ฌํญ์ ๋ฒ๋ฅ ๋ก ์ ํ๋ค. ์์ํ์ ํ๊ธฐ๋ 30์ผ์ ์ด๊ณผํ ์ ์๋ค. ๊ตญ๊ฐ๋ ์ฌ์์ ๋ณต์ง์ ๊ถ์ต์ ํฅ์์ ์ํ์ฌ ๋
ธ๋ ฅํ์ฌ์ผ ํ๋ค. ๊ตญ๊ตฐ์ ์กฐ์ง๊ณผ ํธ์ฑ์ ๋ฒ๋ฅ ๋ก ์ ํ๋ค." ,
1696
1668
},
1697
1669
}
1698
1670
1699
- for _ , tc := range tests {
1700
- for _ , wrap := range []bool {false , true } {
1701
- table := New ().
1702
- Headers (tc .headers ... ).
1703
- Rows (tc .data ... ).
1704
- StyleFunc (TableStyle ).
1705
- Width (80 ).
1706
- Wrap (wrap )
1707
- fmt .Println (table .String ())
1708
- }
1671
+ table := New ().
1672
+ Headers (headers ... ).
1673
+ Rows (data ... ).
1674
+ StyleFunc (TableStyle ).
1675
+ Width (80 ).
1676
+ Wrap (false )
1677
+ fmt .Println (table .String ())
1709
1678
1710
- }
1679
+ table .Wrap (true )
1680
+ fmt .Println (table .String ())
1711
1681
1712
1682
// Output:
1713
- // โญโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโฎ
1714
- // โ Name โ Description โ Type โ Required โ Default โ
1715
- // โโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโค
1716
- // โ command โ A command to be executed inside the cโฆ โ yes โ hello โ yep โ
1717
- // โฐโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโฏ
1718
- // โญโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโฎ
1719
- // โ Name โ Description โ Type โ Required โ Default โ
1720
- // โโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโค
1721
- // โ command โ A command to be executed inside the โ yes โ hello โ yep โ
1722
- // โ โ container to assess its health. Each โ โ โ โ
1723
- // โ โ space delimited token of the command โ โ โ โ
1724
- // โ โ is a separate array element. Commands โ โ โ โ
1725
- // โ โ exiting 0 are considered to be โ โ โ โ
1726
- // โ โ successful probes, whilst all other โ โ โ โ
1727
- // โ โ exit codes are considered failures. โ โ โ โ
1728
- // โฐโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโฏ
1729
- // โญโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโฎ
1730
- // โ Name โ Description โ Type โ Required โ Default โ
1731
- // โโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโค
1732
- // โ command โ A command to be executed inside the cโฆ โ yes โ โ โ
1733
- // โฐโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโฏ
1734
- // โญโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโฎ
1735
- // โ Name โ Description โ Type โ Required โ Default โ
1736
- // โโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโค
1737
- // โ command โ A command to be executed inside the โ yes โ โ โ
1738
- // โ โ container to assess its health. Each โ โ โ โ
1739
- // โ โ space delimited token of the command โ โ โ โ
1740
- // โ โ is a separate array element. Commands โ โ โ โ
1741
- // โ โ exiting 0 are considered to be โ โ โ โ
1742
- // โ โ successful probes, whilst all other โ โ โ โ
1743
- // โ โ exit codes are considered failures. โ โ โ โ
1744
- // โฐโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโฏ
1745
- // โญโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโฎ
1746
- // โ Destination โ Why are you going on this trip? Is it a hot or โ Affordability โ
1747
- // โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโค
1748
- // โ Mexico โ I want to go somewhere hot, dry, and affordabโฆ โ $ โ
1749
- // โ New York โ I'm thinking about going during the Christmasโฆ โ $$$ โ
1750
- // โ California โ โ $$$ โ
1751
- // โฐโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโฏ
1752
- // โญโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโฎ
1753
- // โ Destination โ Why are you going on this trip? Is it a hot or โ Affordability โ
1754
- // โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโค
1755
- // โ Mexico โ I want to go somewhere hot, dry, and โ $ โ
1756
- // โ โ affordable. Mexico has really good food, just โ โ
1757
- // โ โ don't drink tap water! โ โ
1758
- // โ New York โ I'm thinking about going during the Christmas โ $$$ โ
1759
- // โ โ season to check out Rockefeller center. Might โ โ
1760
- // โ โ be cold though... โ โ
1761
- // โ California โ โ $$$ โ
1762
- // โฐโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโฏ
1763
1683
// โญโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโฎ
1764
1684
// โ Hello โ ไฝ ๅฅฝ โ ู
ุฑุญุจูุง โ ์๋
ํ์ธ์ โ โ
1765
1685
// โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโค
0 commit comments