diff --git a/go.mod b/go.mod index 30eb8c9..a8b240d 100644 --- a/go.mod +++ b/go.mod @@ -3,38 +3,34 @@ module github.com/marwanhawari/stew go 1.22 require ( - github.com/AlecAivazis/survey/v2 v2.3.2 - github.com/briandowns/spinner v1.18.0 - github.com/gookit/color v1.5.0 + github.com/AlecAivazis/survey/v2 v2.3.7 + github.com/briandowns/spinner v1.23.0 + github.com/gookit/color v1.5.4 github.com/mholt/archiver v3.1.1+incompatible - github.com/schollz/progressbar/v3 v3.8.5 - github.com/urfave/cli v1.22.5 + github.com/schollz/progressbar/v3 v3.14.2 + github.com/urfave/cli v1.22.14 ) require ( - github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect - github.com/fatih/color v1.7.0 // indirect + github.com/fatih/color v1.16.0 // indirect github.com/frankban/quicktest v1.14.0 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/hinshun/vt10x v0.0.0-20220127042424-3ca73d0126d7 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect - github.com/mattn/go-colorable v0.1.9 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect - github.com/mattn/go-runewidth v0.0.13 // indirect - github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect - github.com/nwaples/rardecode v1.1.0 // indirect + github.com/nwaples/rardecode v1.1.3 // indirect github.com/pierrec/lz4 v2.6.1+incompatible // indirect - github.com/rivo/uniseg v0.2.0 // indirect - github.com/russross/blackfriday/v2 v2.0.1 // indirect - github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect - github.com/ulikunitz/xz v0.5.10 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/ulikunitz/xz v0.5.12 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect - github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect - golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect - golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect - golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect - golang.org/x/text v0.3.7 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/term v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect ) diff --git a/go.sum b/go.sum index b7fd43e..63acf1d 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,13 @@ -github.com/AlecAivazis/survey/v2 v2.3.2 h1:TqTB+aDDCLYhf9/bD2TwSO8u8jDSmMUd2SUVO4gCnU8= -github.com/AlecAivazis/survey/v2 v2.3.2/go.mod h1:TH2kPCDU3Kqq7pLbnCWwZXDBjnhZtmsCle5EiYDJ2fg= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc= +github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ= +github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= -github.com/briandowns/spinner v1.18.0 h1:SJs0maNOs4FqhBwiJ3Gr7Z1D39/rukIVGQvpNZVHVcM= -github.com/briandowns/spinner v1.18.0/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX3FScO+3/ZPQ= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4Pt2A= +github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= @@ -17,8 +17,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 h1:iFaUwBSo5Svw6L7HYpRu/0lE3e0BaElwnNO1qkNQxBY= github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj60/X5sZFNxpG4HBPDHVqxNm4DfnCKgrbZOT+s= github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY= -github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/frankban/quicktest v1.14.0 h1:+cqqvzZV87b4adx/5ayVOaYZ2CrvM4ejQvUdBzPPUss= github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= @@ -26,9 +26,9 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/gookit/color v1.5.0 h1:1Opow3+BWDwqor78DcJkJCIwnkviFi+rrOANki9BUFw= -github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= -github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= +github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= +github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w= +github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/hinshun/vt10x v0.0.0-20220127042424-3ca73d0126d7 h1:PoerlCqzob3t6b5/8mjCPkX4QSTYR4/+kB8IzqZE3ug= github.com/hinshun/vt10x v0.0.0-20220127042424-3ca73d0126d7/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= @@ -40,91 +40,98 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ= -github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= -github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= -github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= +github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= +github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU= github.com/mholt/archiver v3.1.1+incompatible/go.mod h1:Dh2dOXnSdiLxRiPoVfIr/fI1TwETms9B8CTWfeh7ROU= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= -github.com/nwaples/rardecode v1.1.0 h1:vSxaY8vQhOcVr4mm5e8XllHWTiM4JF507A0Katqw7MQ= -github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= +github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9lEc= +github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/schollz/progressbar/v3 v3.8.5 h1:VcmmNRO+eFN3B0m5dta6FXYXY+MEJmXdWoIS+jjssQM= -github.com/schollz/progressbar/v3 v3.8.5/go.mod h1:ewO25kD7ZlaJFTvMeOItkOZa8kXu1UvFs379htE8HMQ= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/schollz/progressbar/v3 v3.14.2 h1:EducH6uNLIWsr560zSV1KrTeUb/wZGAHqyMFIEa99ks= +github.com/schollz/progressbar/v3 v3.14.2/go.mod h1:aQAZQnhF4JGFtRJiw/eobaXpsqpVQAftEQ+hLGXaRc4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= -github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8= -github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= -github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= -github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc= +github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk= +github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= -github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= -github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= +golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= +golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/github.com/AlecAivazis/survey/v2/.travis.yml b/vendor/github.com/AlecAivazis/survey/v2/.travis.yml deleted file mode 100644 index f96db1a..0000000 --- a/vendor/github.com/AlecAivazis/survey/v2/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -language: go - -go: - - 1.12 - -os: - - linux - - linux-ppc64le - - osx - - windows - -go_import_path: github.com/AlecAivazis/survey/v2 - -before_install: - - go get github.com/alecaivazis/run - -install: - - run install-deps - -script: - - run tests - # - run autoplay-tests diff --git a/vendor/github.com/AlecAivazis/survey/v2/CONTRIBUTING.md b/vendor/github.com/AlecAivazis/survey/v2/CONTRIBUTING.md index a84e060..31f5be9 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/CONTRIBUTING.md +++ b/vendor/github.com/AlecAivazis/survey/v2/CONTRIBUTING.md @@ -4,48 +4,26 @@ The following is a set of guidelines to follow when contributing to this package. These are not hard rules, please use common sense and feel free to propose changes to this document in a pull request. -## Table of Contents - -1. [Code of Conduct](#code-of-conduct) -1. [Getting Help](#getting-help) -1. [Filing a Bug Report](#how-to-file-a-bug-report) -1. [Suggesting an API change](#suggesting-an-api-change) -1. [Submitting a Contribution](#submitting-a-contribution) -1. [Writing and Running Tests](#writing-and-running-tests) - ## Code of Conduct This project and its contibutors are expected to uphold the [Go Community Code of Conduct](https://golang.org/conduct). By participating, you are expected to follow these guidelines. ## Getting help -Feel free to [open up an issue](https://github.com/AlecAivazis/survey/v2/issues/new) on GitHub when asking a question so others will be able to find it. Please remember to tag the issue with the `Question` label so the maintainers can get to your question as soon as possible. If the question is urgent, feel free to reach out to `@AlecAivazis` directly in the gophers slack channel. - -## How to file a bug report - -Bugs are tracked using the Github Issue tracker. When filing a bug, please remember to label the issue as a `Bug` and answer/provide the following: - -1. What operating system and terminal are you using? -1. An example that showcases the bug. -1. What did you expect to see? -1. What did you see instead? - -## Suggesting an API change - -If you have an idea, I'm more than happy to discuss it. Please open an issue and we can work through it. In order to maintain some sense of stability, additions to the top-level API are taken just as seriously as changes that break it. Adding stuff is much easier than removing it. +* [Open an issue](https://github.com/AlecAivazis/survey/issues/new/choose) +* Reach out to `@AlecAivazis` or `@mislav` in the Gophers slack (please use only when urgent) ## Submitting a contribution -In order to maintain stability, most features get fully integrated in more than one PR. This allows for more opportunity to think through each API change without amassing large amounts of tech debt and API changes at once. If your feature can be broken into separate chunks, it will be able to be reviewed much quicker. For example, if the PR that implemented the `Validate` field was submitted in a PR separately from one that included `survey.Required`, it would be able to get merge without having to decide how many different `Validators` we want to provide as part of `survey`'s API. - When submitting a contribution, -- Provide a description of the feature or change -- Reference the ticket addressed by the PR if there is one -- Following community standards, add comments for all exported members so that all necessary information is available on godocs -- Remember to update the project README.md with changes to the high-level API -- Include both positive and negative unit tests (when applicable) -- Contributions with visual ramifications or interaction changes should be accompanied with the appropriate `go-expect` tests. For more information on writing these tests, see [Writing and Running Tests](#writing-and-running-tests) +- Try to make a series of smaller changes instead of one large change +- Provide a description of each change that you are proposing +- Reference the issue addressed by your pull request (if there is one) +- Document all new exported Go APIs +- Update the project's README when applicable +- Include unit tests if possible +- Contributions with visual ramifications or interaction changes should be accompanied with an integration test—see below for details. ## Writing and running tests diff --git a/vendor/github.com/AlecAivazis/survey/v2/Gopkg.lock b/vendor/github.com/AlecAivazis/survey/v2/Gopkg.lock deleted file mode 100644 index b764f30..0000000 --- a/vendor/github.com/AlecAivazis/survey/v2/Gopkg.lock +++ /dev/null @@ -1,78 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - branch = "master" - name = "github.com/Netflix/go-expect" - packages = ["."] - revision = "c93bf25de8e869da25cf26bcd2932b36141f61ae" - -[[projects]] - name = "github.com/davecgh/go-spew" - packages = ["spew"] - revision = "346938d642f2ec3594ed81d874461961cd0faa76" - version = "v1.1.0" - -[[projects]] - branch = "master" - name = "github.com/hinshun/vt10x" - packages = ["."] - revision = "1954e646417484a2a687ea344edade2c2b6523c8" - -[[projects]] - branch = "master" - name = "github.com/kballard/go-shellquote" - packages = ["."] - revision = "95032a82bc518f77982ea72343cc1ade730072f0" - -[[projects]] - name = "github.com/kr/pty" - packages = ["."] - revision = "282ce0e5322c82529687d609ee670fac7c7d917c" - version = "v1.1.1" - -[[projects]] - name = "github.com/mattn/go-colorable" - packages = ["."] - revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" - version = "v0.0.9" - -[[projects]] - name = "github.com/mattn/go-isatty" - packages = ["."] - revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" - version = "v0.0.3" - -[[projects]] - branch = "master" - name = "github.com/mgutz/ansi" - packages = ["."] - revision = "9520e82c474b0a04dd04f8a40959027271bab992" - -[[projects]] - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - name = "github.com/stretchr/testify" - packages = [ - "assert", - "require" - ] - revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" - version = "v1.2.1" - -[[projects]] - branch = "master" - name = "golang.org/x/sys" - packages = ["unix"] - revision = "9527bec2660bd847c050fda93a0f0c6dee0800bb" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "371508ebad4798adc38a118f858b5c17a65b58594203548f9feb74cb781dd907" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/vendor/github.com/AlecAivazis/survey/v2/Gopkg.toml b/vendor/github.com/AlecAivazis/survey/v2/Gopkg.toml deleted file mode 100644 index 8acb825..0000000 --- a/vendor/github.com/AlecAivazis/survey/v2/Gopkg.toml +++ /dev/null @@ -1,54 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - -[[constraint]] - branch = "master" - name = "github.com/Netflix/go-expect" - -[[constraint]] - branch = "master" - name = "github.com/hinshun/vt10x" - -[[constraint]] - name = "github.com/mattn/go-isatty" - version = "0.0.3" - -[[constraint]] - branch = "master" - name = "github.com/mgutz/ansi" - -[[constraint]] - name = "github.com/stretchr/testify" - version = "1.2.1" - -[prune] - go-tests = true - unused-packages = true - -[[constraint]] - branch = "master" - name = "github.com/kballard/go-shellquote" diff --git a/vendor/github.com/AlecAivazis/survey/v2/README.md b/vendor/github.com/AlecAivazis/survey/v2/README.md index 5ab410e..ba75b32 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/README.md +++ b/vendor/github.com/AlecAivazis/survey/v2/README.md @@ -1,6 +1,5 @@ # Survey -[![Build Status](https://travis-ci.org/AlecAivazis/survey.svg?branch=feature%2Fpretty)](https://travis-ci.org/AlecAivazis/survey) [![GoDoc](http://img.shields.io/badge/godoc-reference-5272B4.svg)](https://pkg.go.dev/github.com/AlecAivazis/survey/v2) A library for building interactive and accessible prompts on terminals supporting ANSI escape sequences. @@ -56,39 +55,12 @@ func main() { } ``` -## Table of Contents - -1. [Examples](#examples) -1. [Running the Prompts](#running-the-prompts) -1. [Prompts](#prompts) - 1. [Input](#input) - 1. [Suggestion Options](#suggestion-options) - 1. [Multiline](#multiline) - 1. [Password](#password) - 1. [Confirm](#confirm) - 1. [Select](#select) - 1. [MultiSelect](#multiselect) - 1. [Editor](#editor) -1. [Filtering Options](#filtering-options) -1. [Validation](#validation) - 1. [Built-in Validators](#built-in-validators) -1. [Help Text](#help-text) - 1. [Changing the input rune](#changing-the-input-rune) -1. [Changing the Icons ](#changing-the-icons) -1. [Custom Types](#custom-types) -1. [Testing](#testing) -1. [FAQ](#faq) - ## Examples Examples can be found in the `examples/` directory. Run them to see basic behavior: ```bash -go get github.com/AlecAivazis/survey/v2 - -cd $GOPATH/src/github.com/AlecAivazis/survey - go run examples/simple.go go run examples/validation.go ``` @@ -221,6 +193,28 @@ prompt := &survey.MultiSelect{..., PageSize: 10} survey.AskOne(prompt, &days, survey.WithPageSize(10)) ``` +#### Select options description + +The optional description text can be used to add extra information to each option listed in the select prompt: + +```golang +color := "" +prompt := &survey.Select{ + Message: "Choose a color:", + Options: []string{"red", "blue", "green"}, + Description: func(value string, index int) string { + if value == "red" { + return "My favorite color" + } + return "" + }, +} +survey.AskOne(prompt, &color) + +// Assuming that the user chose "red - My favorite color": +fmt.Println(color) //=> "red" +``` + ### MultiSelect ![Example](img/multi-select-all-none.gif) @@ -363,6 +357,39 @@ All of the prompts have a `Help` field which can be defined to provide more info } ``` +## Removing the "Select All" and "Select None" options + +By default, users can select all of the multi-select options using the right arrow key. To prevent users from being able to do this (and remove the ` to all` message from the prompt), use the option `WithRemoveSelectAll`: + +```golang +import ( + "github.com/AlecAivazis/survey/v2" +) + +number := "" +prompt := &survey.Input{ + Message: "This question has the select all option removed", +} + +survey.AskOne(prompt, &number, survey.WithRemoveSelectAll()) +``` + +Also by default, users can use the left arrow key to unselect all of the options. To prevent users from being able to do this (and remove the ` to none` message from the prompt), use the option `WithRemoveSelectNone`: + +```golang +import ( + "github.com/AlecAivazis/survey/v2" +) + +number := "" +prompt := &survey.Input{ + Message: "This question has the select all option removed", +} + +survey.AskOne(prompt, &number, survey.WithRemoveSelectNone()) +``` + + ### Changing the input rune In some situations, `?` is a perfectly valid response. To handle this, you can change the rune that survey diff --git a/vendor/github.com/AlecAivazis/survey/v2/_tasks.hcl b/vendor/github.com/AlecAivazis/survey/v2/_tasks.hcl deleted file mode 100644 index 0eefcb5..0000000 --- a/vendor/github.com/AlecAivazis/survey/v2/_tasks.hcl +++ /dev/null @@ -1,19 +0,0 @@ -task "install-deps" { - description = "Install all of package dependencies" - pipeline = [ - "go get -v {{.files}}", - ] -} - -task "tests" { - description = "Run the test suite" - command = "go test -v {{.files}}" - environment = { - GOFLAGS = "-mod=vendor" - } -} - -variables = { - files = "$(go list -v ./... | grep -iEv \"tests|examples\")" -} - diff --git a/vendor/github.com/AlecAivazis/survey/v2/confirm.go b/vendor/github.com/AlecAivazis/survey/v2/confirm.go index 8e5d7ef..1c23fb4 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/confirm.go +++ b/vendor/github.com/AlecAivazis/survey/v2/confirm.go @@ -49,8 +49,10 @@ func yesNo(t bool) string { func (c *Confirm) getBool(showHelp bool, config *PromptConfig) (bool, error) { cursor := c.NewCursor() rr := c.NewRuneReader() - rr.SetTermMode() - defer rr.RestoreTermMode() + _ = rr.SetTermMode() + defer func() { + _ = rr.RestoreTermMode() + }() // start waiting for input for { @@ -88,6 +90,7 @@ func (c *Confirm) getBool(showHelp bool, config *PromptConfig) (bool, error) { continue default: // we didnt get a valid answer, so print error and prompt again + //lint:ignore ST1005 it should be fine for this error message to have punctuation if err := c.Error(config, fmt.Errorf("%q is not a valid answer, please try again.", val)); err != nil { return c.Default, err } @@ -107,8 +110,6 @@ func (c *Confirm) getBool(showHelp bool, config *PromptConfig) (bool, error) { } return answer, nil } - // should not get here - return c.Default, nil } /* diff --git a/vendor/github.com/AlecAivazis/survey/v2/core/template.go b/vendor/github.com/AlecAivazis/survey/v2/core/template.go index 6b3d20c..02da879 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/core/template.go +++ b/vendor/github.com/AlecAivazis/survey/v2/core/template.go @@ -2,6 +2,7 @@ package core import ( "bytes" + "os" "sync" "text/template" @@ -23,11 +24,22 @@ var TemplateFuncsNoColor = map[string]interface{}{ }, } -//RunTemplate returns two formatted strings given a template and -//the data it requires. The first string returned is generated for -//user-facing output and may or may not contain ANSI escape codes -//for colored output. The second string does not contain escape codes -//and can be used by the renderer for layout purposes. +// envColorDisabled returns if output colors are forbid by environment variables +func envColorDisabled() bool { + return os.Getenv("NO_COLOR") != "" || os.Getenv("CLICOLOR") == "0" +} + +// envColorForced returns if output colors are forced from environment variables +func envColorForced() bool { + val, ok := os.LookupEnv("CLICOLOR_FORCE") + return ok && val != "0" +} + +// RunTemplate returns two formatted strings given a template and +// the data it requires. The first string returned is generated for +// user-facing output and may or may not contain ANSI escape codes +// for colored output. The second string does not contain escape codes +// and can be used by the renderer for layout purposes. func RunTemplate(tmpl string, data interface{}) (string, string, error) { tPair, err := GetTemplatePair(tmpl) if err != nil { @@ -52,11 +64,11 @@ var ( memoMutex = &sync.RWMutex{} ) -//GetTemplatePair returns a pair of compiled templates where the -//first template is generated for user-facing output and the -//second is generated for use by the renderer. The second -//template does not contain any color escape codes, whereas -//the first template may or may not depending on DisableColor. +// GetTemplatePair returns a pair of compiled templates where the +// first template is generated for user-facing output and the +// second is generated for use by the renderer. The second +// template does not contain any color escape codes, whereas +// the first template may or may not depending on DisableColor. func GetTemplatePair(tmpl string) ([2]*template.Template, error) { memoMutex.RLock() if t, ok := memoizedGetTemplate[tmpl]; ok { @@ -74,7 +86,8 @@ func GetTemplatePair(tmpl string) ([2]*template.Template, error) { templatePair[1] = templateNoColor - if DisableColor { + envColorHide := envColorDisabled() && !envColorForced() + if DisableColor || envColorHide { templatePair[0] = templatePair[1] } else { templateWithColor, err := template.New("prompt").Funcs(TemplateFuncsWithColor).Parse(tmpl) diff --git a/vendor/github.com/AlecAivazis/survey/v2/core/write.go b/vendor/github.com/AlecAivazis/survey/v2/core/write.go index dfe9b49..2225e3b 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/core/write.go +++ b/vendor/github.com/AlecAivazis/survey/v2/core/write.go @@ -142,12 +142,12 @@ func (err errFieldNotMatch) Is(target error) bool { // implements the dynamic er // It returns the Question.Name that couldn't be matched with a destination field. // // Usage: -// err := survey.Ask(qs, &v); -// if err != nil { -// if name, ok := core.IsFieldNotMatch(err); ok { -// [...name is the not matched question name] -// } -// } +// +// if err := survey.Ask(qs, &v); err != nil { +// if name, ok := core.IsFieldNotMatch(err); ok { +// // name is the question name that did not match a field +// } +// } func IsFieldNotMatch(err error) (string, bool) { if err != nil { if v, ok := err.(errFieldNotMatch); ok { @@ -178,7 +178,7 @@ func findField(s reflect.Value, name string) (reflect.Value, reflect.StructField // then look for matching names for _, f := range fields { // if the name of the field matches what we're looking for - if strings.ToLower(f.fieldType.Name) == strings.ToLower(name) { + if strings.EqualFold(f.fieldType.Name, name) { return f.value, f.fieldType, nil } } @@ -197,9 +197,7 @@ func flattenFields(s reflect.Value) []reflectField { if field.Kind() == reflect.Struct && fieldType.Anonymous { // field is a promoted structure - for _, f := range flattenFields(field) { - fields = append(fields, f) - } + fields = append(fields, flattenFields(field)...) continue } fields = append(fields, reflectField{field, fieldType}) @@ -303,6 +301,7 @@ func copy(t reflect.Value, v reflect.Value) (err error) { case reflect.Float64: castVal, casterr = strconv.ParseFloat(vString, 64) default: + //lint:ignore ST1005 allow this error message to be capitalized return fmt.Errorf("Unable to convert from string to type %s", t.Kind()) } @@ -337,6 +336,7 @@ func copy(t reflect.Value, v reflect.Value) (err error) { } // we're copying an option answer to an incorrect type + //lint:ignore ST1005 allow this error message to be capitalized return fmt.Errorf("Unable to convert from OptionAnswer to type %s", t.Kind()) } @@ -361,7 +361,9 @@ func copy(t reflect.Value, v reflect.Value) (err error) { // otherwise it could be an array case reflect.Array: // set the index to the appropriate value - copy(t.Slice(i, i+1).Index(0), v.Index(i)) + if err := copy(t.Slice(i, i+1).Index(0), v.Index(i)); err != nil { + return err + } } } } else { diff --git a/vendor/github.com/AlecAivazis/survey/v2/editor.go b/vendor/github.com/AlecAivazis/survey/v2/editor.go index ec6a141..20470f1 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/editor.go +++ b/vendor/github.com/AlecAivazis/survey/v2/editor.go @@ -101,8 +101,10 @@ func (e *Editor) prompt(initialValue string, config *PromptConfig) (interface{}, // start reading runes from the standard in rr := e.NewRuneReader() - rr.SetTermMode() - defer rr.RestoreTermMode() + _ = rr.SetTermMode() + defer func() { + _ = rr.RestoreTermMode() + }() cursor := e.NewCursor() cursor.Hide() @@ -147,7 +149,9 @@ func (e *Editor) prompt(initialValue string, config *PromptConfig) (interface{}, if err != nil { return "", err } - defer os.Remove(f.Name()) + defer func() { + _ = os.Remove(f.Name()) + }() // write utf8 BOM header // The reason why we do this is because notepad.exe on Windows determines the diff --git a/vendor/github.com/AlecAivazis/survey/v2/input.go b/vendor/github.com/AlecAivazis/survey/v2/input.go index a1abab1..0474763 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/input.go +++ b/vendor/github.com/AlecAivazis/survey/v2/input.go @@ -127,14 +127,14 @@ func (i *Input) onRune(config *PromptConfig) terminal.OnRuneFn { ) if err == nil { - err = readLineAgain + err = errReadLineAgain } return []rune(i.typedAnswer), true, err }) } -var readLineAgain = errors.New("read line again") +var errReadLineAgain = errors.New("read line again") func (i *Input) Prompt(config *PromptConfig) (interface{}, error) { // render the template @@ -152,9 +152,10 @@ func (i *Input) Prompt(config *PromptConfig) (interface{}, error) { // start reading runes from the standard in rr := i.NewRuneReader() - rr.SetTermMode() - defer rr.RestoreTermMode() - + _ = rr.SetTermMode() + defer func() { + _ = rr.RestoreTermMode() + }() cursor := i.NewCursor() if !config.ShowCursor { cursor.Hide() // hide the cursor @@ -169,7 +170,7 @@ func (i *Input) Prompt(config *PromptConfig) (interface{}, error) { } line, err = rr.ReadLineWithDefault(0, line, i.onRune(config)) - if err == readLineAgain { + if err == errReadLineAgain { continue } @@ -206,20 +207,13 @@ func (i *Input) Prompt(config *PromptConfig) (interface{}, error) { } func (i *Input) Cleanup(config *PromptConfig, val interface{}) error { - // use the default answer when cleaning up the prompt if necessary - ans := i.answer - if ans == "" && i.Default != "" { - ans = i.Default - } - - // render the cleanup return i.Render( InputQuestionTemplate, InputTemplateData{ Input: *i, ShowAnswer: true, Config: config, - Answer: ans, + Answer: val.(string), }, ) } diff --git a/vendor/github.com/AlecAivazis/survey/v2/multiline.go b/vendor/github.com/AlecAivazis/survey/v2/multiline.go index d0523b7..bff9622 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/multiline.go +++ b/vendor/github.com/AlecAivazis/survey/v2/multiline.go @@ -50,8 +50,10 @@ func (i *Multiline) Prompt(config *PromptConfig) (interface{}, error) { // start reading runes from the standard in rr := i.NewRuneReader() - rr.SetTermMode() - defer rr.RestoreTermMode() + _ = rr.SetTermMode() + defer func() { + _ = rr.RestoreTermMode() + }() cursor := i.NewCursor() @@ -60,7 +62,7 @@ func (i *Multiline) Prompt(config *PromptConfig) (interface{}, error) { emptyOnce := false // get the next line for { - line := []rune{} + var line []rune line, err = rr.ReadLine(0) if err != nil { return string(line), err diff --git a/vendor/github.com/AlecAivazis/survey/v2/multiselect.go b/vendor/github.com/AlecAivazis/survey/v2/multiselect.go index 1e94f80..396169f 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/multiselect.go +++ b/vendor/github.com/AlecAivazis/survey/v2/multiselect.go @@ -29,6 +29,7 @@ type MultiSelect struct { VimMode bool FilterMessage string Filter func(filter string, value string, index int) bool + Description func(value string, index int) string filter string selectedIndex int checked map[int]bool @@ -43,6 +44,7 @@ type MultiSelectTemplateData struct { Checked map[int]bool SelectedIndex int ShowHelp bool + Description func(value string, index int) string PageEntries []core.OptionAnswer Config *PromptConfig @@ -59,19 +61,26 @@ func (m MultiSelectTemplateData) IterateOption(ix int, opt core.OptionAnswer) in return copy } +func (m MultiSelectTemplateData) GetDescription(opt core.OptionAnswer) string { + if m.Description == nil { + return "" + } + return m.Description(opt.Value, opt.Index) +} + var MultiSelectQuestionTemplate = ` {{- define "option"}} {{- if eq .SelectedIndex .CurrentIndex }}{{color .Config.Icons.SelectFocus.Format }}{{ .Config.Icons.SelectFocus.Text }}{{color "reset"}}{{else}} {{end}} {{- if index .Checked .CurrentOpt.Index }}{{color .Config.Icons.MarkedOption.Format }} {{ .Config.Icons.MarkedOption.Text }} {{else}}{{color .Config.Icons.UnmarkedOption.Format }} {{ .Config.Icons.UnmarkedOption.Text }} {{end}} {{- color "reset"}} - {{- " "}}{{- .CurrentOpt.Value}} + {{- " "}}{{- .CurrentOpt.Value}}{{ if ne ($.GetDescription .CurrentOpt) "" }} - {{color "cyan"}}{{ $.GetDescription .CurrentOpt }}{{color "reset"}}{{end}} {{end}} {{- if .ShowHelp }}{{- color .Config.Icons.Help.Format }}{{ .Config.Icons.Help.Text }} {{ .Help }}{{color "reset"}}{{"\n"}}{{end}} {{- color .Config.Icons.Question.Format }}{{ .Config.Icons.Question.Text }} {{color "reset"}} {{- color "default+hb"}}{{ .Message }}{{ .FilterMessage }}{{color "reset"}} {{- if .ShowAnswer}}{{color "cyan"}} {{.Answer}}{{color "reset"}}{{"\n"}} {{- else }} - {{- " "}}{{- color "cyan"}}[Use arrows to move, space to select, to all, to none, type to filter{{- if and .Help (not .ShowHelp)}}, {{ .Config.HelpInput }} for more help{{end}}]{{color "reset"}} + {{- " "}}{{- color "cyan"}}[Use arrows to move, space to select,{{- if not .Config.RemoveSelectAll }} to all,{{end}}{{- if not .Config.RemoveSelectNone }} to none,{{end}} type to filter{{- if and .Help (not .ShowHelp)}}, {{ .Config.HelpInput }} for more help{{end}}]{{color "reset"}} {{- "\n"}} {{- range $ix, $option := .PageEntries}} {{- template "option" $.IterateOption $ix $option}} @@ -134,14 +143,14 @@ func (m *MultiSelect) OnChange(key rune, config *PromptConfig) { } else if key >= terminal.KeySpace { m.filter += string(key) m.VimMode = false - } else if key == terminal.KeyArrowRight { + } else if !config.RemoveSelectAll && key == terminal.KeyArrowRight { for _, v := range options { m.checked[v.Index] = true } if !config.KeepFilter { m.filter = "" } - } else if key == terminal.KeyArrowLeft { + } else if !config.RemoveSelectNone && key == terminal.KeyArrowLeft { for _, v := range options { m.checked[v.Index] = false } @@ -179,12 +188,13 @@ func (m *MultiSelect) OnChange(key rune, config *PromptConfig) { SelectedIndex: idx, Checked: m.checked, ShowHelp: m.showingHelp, + Description: m.Description, PageEntries: opts, Config: config, } // render the options - m.RenderWithCursorOffset(MultiSelectQuestionTemplate, tmplData, opts, idx) + _ = m.RenderWithCursorOffset(MultiSelectQuestionTemplate, tmplData, opts, idx) } func (m *MultiSelect) filterOptions(config *PromptConfig) []core.OptionAnswer { @@ -272,6 +282,7 @@ func (m *MultiSelect) Prompt(config *PromptConfig) (interface{}, error) { tmplData := MultiSelectTemplateData{ MultiSelect: *m, SelectedIndex: idx, + Description: m.Description, Checked: m.checked, PageEntries: opts, Config: config, @@ -284,8 +295,10 @@ func (m *MultiSelect) Prompt(config *PromptConfig) (interface{}, error) { } rr := m.NewRuneReader() - rr.SetTermMode() - defer rr.RestoreTermMode() + _ = rr.SetTermMode() + defer func() { + _ = rr.RestoreTermMode() + }() // start waiting for input for { @@ -340,6 +353,7 @@ func (m *MultiSelect) Cleanup(config *PromptConfig, val interface{}) error { Checked: m.checked, Answer: answer, ShowAnswer: true, + Description: m.Description, Config: config, }, ) diff --git a/vendor/github.com/AlecAivazis/survey/v2/password.go b/vendor/github.com/AlecAivazis/survey/v2/password.go index 285bff5..96a2ae8 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/password.go +++ b/vendor/github.com/AlecAivazis/survey/v2/password.go @@ -44,27 +44,32 @@ func (p *Password) Prompt(config *PromptConfig) (interface{}, error) { Config: config, }, ) - fmt.Fprint(terminal.NewAnsiStdout(p.Stdio().Out), userOut) if err != nil { return "", err } + if _, err := fmt.Fprint(terminal.NewAnsiStdout(p.Stdio().Out), userOut); err != nil { + return "", err + } + rr := p.NewRuneReader() - rr.SetTermMode() - defer rr.RestoreTermMode() + _ = rr.SetTermMode() + defer func() { + _ = rr.RestoreTermMode() + }() // no help msg? Just return any response if p.Help == "" { - line, err := rr.ReadLine('*') + line, err := rr.ReadLine(config.HideCharacter) return string(line), err } cursor := p.NewCursor() - line := []rune{} + var line []rune // process answers looking for help prompt answer for { - line, err = rr.ReadLine('*') + line, err = rr.ReadLine(config.HideCharacter) if err != nil { return string(line), err } @@ -91,7 +96,7 @@ func (p *Password) Prompt(config *PromptConfig) (interface{}, error) { } lineStr := string(line) - p.AppendRenderedText(strings.Repeat("*", len(lineStr))) + p.AppendRenderedText(strings.Repeat(string(config.HideCharacter), len(lineStr))) return lineStr, err } diff --git a/vendor/github.com/AlecAivazis/survey/v2/renderer.go b/vendor/github.com/AlecAivazis/survey/v2/renderer.go index 5503d81..a16207d 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/renderer.go +++ b/vendor/github.com/AlecAivazis/survey/v2/renderer.go @@ -3,8 +3,6 @@ package survey import ( "bytes" "fmt" - "unicode/utf8" - "github.com/AlecAivazis/survey/v2/core" "github.com/AlecAivazis/survey/v2/terminal" "golang.org/x/term" @@ -61,7 +59,9 @@ func (r *Renderer) Error(config *PromptConfig, invalid error) error { } // send the message to the user - fmt.Fprint(terminal.NewAnsiStdout(r.stdio.Out), userOut) + if _, err := fmt.Fprint(terminal.NewAnsiStdout(r.stdio.Out), userOut); err != nil { + return err + } // add the printed text to the rendered error buffer so we can cleanup later r.appendRenderedError(layoutOut) @@ -90,7 +90,9 @@ func (r *Renderer) Render(tmpl string, data interface{}) error { } // print the summary - fmt.Fprint(terminal.NewAnsiStdout(r.stdio.Out), userOut) + if _, err := fmt.Fprint(terminal.NewAnsiStdout(r.stdio.Out), userOut); err != nil { + return err + } // add the printed text to the rendered text buffer so we can cleanup later r.AppendRenderedText(layoutOut) @@ -165,8 +167,8 @@ func (r *Renderer) countLines(buf bytes.Buffer) int { count := 0 curr := 0 - delim := -1 for curr < len(bufBytes) { + var delim int // read until the next newline or the end of the string relDelim := bytes.IndexRune(bufBytes[curr:], '\n') if relDelim != -1 { @@ -176,7 +178,8 @@ func (r *Renderer) countLines(buf bytes.Buffer) int { delim = len(bufBytes) // no new line found, read rest of text } - if lineWidth := utf8.RuneCount(bufBytes[curr:delim]); lineWidth > w { + str := string(bufBytes[curr:delim]) + if lineWidth := terminal.StringWidth(str); lineWidth > w { // account for word wrapping count += lineWidth / w if (lineWidth % w) == 0 { diff --git a/vendor/github.com/AlecAivazis/survey/v2/select.go b/vendor/github.com/AlecAivazis/survey/v2/select.go index 915f34b..1210122 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/select.go +++ b/vendor/github.com/AlecAivazis/survey/v2/select.go @@ -2,6 +2,7 @@ package survey import ( "errors" + "fmt" "github.com/AlecAivazis/survey/v2/core" "github.com/AlecAivazis/survey/v2/terminal" @@ -28,9 +29,9 @@ type Select struct { VimMode bool FilterMessage string Filter func(filter string, value string, index int) bool + Description func(value string, index int) string filter string selectedIndex int - useDefault bool showingHelp bool } @@ -42,6 +43,7 @@ type SelectTemplateData struct { Answer string ShowAnswer bool ShowHelp bool + Description func(value string, index int) string Config *PromptConfig // These fields are used when rendering an individual option @@ -57,10 +59,17 @@ func (s SelectTemplateData) IterateOption(ix int, opt core.OptionAnswer) interfa return copy } +func (s SelectTemplateData) GetDescription(opt core.OptionAnswer) string { + if s.Description == nil { + return "" + } + return s.Description(opt.Value, opt.Index) +} + var SelectQuestionTemplate = ` {{- define "option"}} {{- if eq .SelectedIndex .CurrentIndex }}{{color .Config.Icons.SelectFocus.Format }}{{ .Config.Icons.SelectFocus.Text }} {{else}}{{color "default"}} {{end}} - {{- .CurrentOpt.Value}} + {{- .CurrentOpt.Value}}{{ if ne ($.GetDescription .CurrentOpt) "" }} - {{color "cyan"}}{{ $.GetDescription .CurrentOpt }}{{end}} {{- color "reset"}} {{end}} {{- if .ShowHelp }}{{- color .Config.Icons.Help.Format }}{{ .Config.Icons.Help.Text }} {{ .Help }}{{color "reset"}}{{"\n"}}{{end}} @@ -94,8 +103,6 @@ func (s *Select) OnChange(key rune, config *PromptConfig) bool { // if the user pressed the up arrow or 'k' to emulate vim } else if (key == terminal.KeyArrowUp || (s.VimMode && key == 'k')) && len(options) > 0 { - s.useDefault = false - // if we are at the top of the list if s.selectedIndex == 0 { // start from the button @@ -107,7 +114,6 @@ func (s *Select) OnChange(key rune, config *PromptConfig) bool { // if the user pressed down or 'j' to emulate vim } else if (key == terminal.KeyTab || key == terminal.KeyArrowDown || (s.VimMode && key == 'j')) && len(options) > 0 { - s.useDefault = false // if we are at the bottom of the list if s.selectedIndex == len(options)-1 { // start from the top @@ -138,8 +144,6 @@ func (s *Select) OnChange(key rune, config *PromptConfig) bool { s.filter += string(key) // make sure vim mode is disabled s.VimMode = false - // make sure that we use the current value in the filtered list - s.useDefault = false } s.FilterMessage = "" @@ -171,12 +175,13 @@ func (s *Select) OnChange(key rune, config *PromptConfig) bool { Select: *s, SelectedIndex: idx, ShowHelp: s.showingHelp, + Description: s.Description, PageEntries: opts, Config: config, } // render the options - s.RenderWithCursorOffset(SelectQuestionTemplate, tmplData, opts, idx) + _ = s.RenderWithCursorOffset(SelectQuestionTemplate, tmplData, opts, idx) // keep prompting return false @@ -197,7 +202,6 @@ func (s *Select) filterOptions(config *PromptConfig) []core.OptionAnswer { filter = config.Filter } - // for i, opt := range s.Options { // i the filter says to include the option if filter(s.filter, opt, i) { @@ -219,23 +223,29 @@ func (s *Select) Prompt(config *PromptConfig) (interface{}, error) { return "", errors.New("please provide options to select from") } - // start off with the first option selected - sel := 0 - // if there is a default - if s.Default != "" { - // find the choice - for i, opt := range s.Options { - // if the option corresponds to the default - if opt == s.Default { - // we found our initial value - sel = i - // stop looking - break + s.selectedIndex = 0 + if s.Default != nil { + switch defaultValue := s.Default.(type) { + case string: + var found bool + for i, opt := range s.Options { + if opt == defaultValue { + s.selectedIndex = i + found = true + } } + if !found { + return "", fmt.Errorf("default value %q not found in options", defaultValue) + } + case int: + if defaultValue >= len(s.Options) { + return "", fmt.Errorf("default index %d exceeds the number of options", defaultValue) + } + s.selectedIndex = defaultValue + default: + return "", errors.New("default value of select must be an int or string") } } - // save the selected index - s.selectedIndex = sel // figure out the page size pageSize := s.PageSize @@ -246,7 +256,7 @@ func (s *Select) Prompt(config *PromptConfig) (interface{}, error) { } // figure out the options and index to render - opts, idx := paginate(pageSize, core.OptionAnswerList(s.Options), sel) + opts, idx := paginate(pageSize, core.OptionAnswerList(s.Options), s.selectedIndex) cursor := s.NewCursor() cursor.Save() // for proper cursor placement during selection @@ -257,6 +267,7 @@ func (s *Select) Prompt(config *PromptConfig) (interface{}, error) { tmplData := SelectTemplateData{ Select: *s, SelectedIndex: idx, + Description: s.Description, ShowHelp: s.showingHelp, PageEntries: opts, Config: config, @@ -268,12 +279,11 @@ func (s *Select) Prompt(config *PromptConfig) (interface{}, error) { return "", err } - // by default, use the default value - s.useDefault = true - rr := s.NewRuneReader() - rr.SetTermMode() - defer rr.RestoreTermMode() + _ = rr.SetTermMode() + defer func() { + _ = rr.RestoreTermMode() + }() // start waiting for input for { @@ -291,45 +301,16 @@ func (s *Select) Prompt(config *PromptConfig) (interface{}, error) { break } } + options := s.filterOptions(config) s.filter = "" s.FilterMessage = "" - // the index to report - var val string - // if we are supposed to use the default value - if s.useDefault || s.selectedIndex >= len(options) { - // if there is a default value - if s.Default != nil { - // if the default is a string - if defaultString, ok := s.Default.(string); ok { - // use the default value - val = defaultString - // the default value could also be an interpret which is interpretted as the index - } else if defaultIndex, ok := s.Default.(int); ok { - val = s.Options[defaultIndex] - } else { - return val, errors.New("default value of select must be an int or string") - } - } else if len(options) > 0 { - // there is no default value so use the first - val = options[0].Value - } - // otherwise the selected index points to the value - } else if s.selectedIndex < len(options) { - // the - val = options[s.selectedIndex].Value - } - - // now that we have the value lets go hunt down the right index to return - idx = -1 - for i, optionValue := range s.Options { - if optionValue == val { - idx = i - } + if s.selectedIndex < len(options) { + return options[s.selectedIndex], err } - return core.OptionAnswer{Value: val, Index: idx}, err + return options[0], err } func (s *Select) Cleanup(config *PromptConfig, val interface{}) error { @@ -338,10 +319,11 @@ func (s *Select) Cleanup(config *PromptConfig, val interface{}) error { return s.Render( SelectQuestionTemplate, SelectTemplateData{ - Select: *s, - Answer: val.(core.OptionAnswer).Value, - ShowAnswer: true, - Config: config, + Select: *s, + Answer: val.(core.OptionAnswer).Value, + ShowAnswer: true, + Description: s.Description, + Config: config, }, ) } diff --git a/vendor/github.com/AlecAivazis/survey/v2/survey.go b/vendor/github.com/AlecAivazis/survey/v2/survey.go index 1aae459..aad73bb 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/survey.go +++ b/vendor/github.com/AlecAivazis/survey/v2/survey.go @@ -56,8 +56,11 @@ func defaultAskOptions() *AskOptions { // include this option if it matches return strings.Contains(strings.ToLower(value), filter) }, - KeepFilter: false, - ShowCursor: false, + KeepFilter: false, + ShowCursor: false, + RemoveSelectAll: false, + RemoveSelectNone: false, + HideCharacter: '*', }, } } @@ -111,13 +114,16 @@ type Question struct { // PromptConfig holds the global configuration for a prompt type PromptConfig struct { - PageSize int - Icons IconSet - HelpInput string - SuggestInput string - Filter func(filter string, option string, index int) bool - KeepFilter bool - ShowCursor bool + PageSize int + Icons IconSet + HelpInput string + SuggestInput string + Filter func(filter string, option string, index int) bool + KeepFilter bool + ShowCursor bool + RemoveSelectAll bool + RemoveSelectNone bool + HideCharacter rune } // Prompt is the primary interface for the objects that can take user input @@ -175,6 +181,22 @@ func WithKeepFilter(KeepFilter bool) AskOpt { } } +// WithRemoveSelectAll remove the select all option in Multiselect +func WithRemoveSelectAll() AskOpt { + return func(options *AskOptions) error { + options.PromptConfig.RemoveSelectAll = true + return nil + } +} + +// WithRemoveSelectNone remove the select none/unselect all in Multiselect +func WithRemoveSelectNone() AskOpt { + return func(options *AskOptions) error { + options.PromptConfig.RemoveSelectNone = true + return nil + } +} + // WithValidator specifies a validator to use while prompting the user func WithValidator(v Validator) AskOpt { return func(options *AskOptions) error { @@ -234,6 +256,17 @@ func WithShowCursor(ShowCursor bool) AskOpt { } } +// WithHideCharacter sets the default character shown instead of the password for password inputs +func WithHideCharacter(char rune) AskOpt { + return func(options *AskOptions) error { + // set the hide character + options.PromptConfig.HideCharacter = char + + // nothing went wrong + return nil + } +} + /* AskOne performs the prompt for a single prompt and asks for validation if required. Response types should be something that can be casted from the response type designated @@ -245,7 +278,6 @@ in the documentation. For example: } survey.AskOne(prompt, &name) - */ func AskOne(p Prompt, response interface{}, opts ...AskOpt) error { err := Ask([]*Question{{Prompt: p}}, response, opts...) @@ -297,6 +329,20 @@ func Ask(qs []*Question, response interface{}, opts ...AskOpt) error { return errors.New("cannot call Ask() with a nil reference to record the answers") } + validate := func(q *Question, val interface{}) error { + if q.Validate != nil { + if err := q.Validate(val); err != nil { + return err + } + } + for _, v := range options.Validators { + if err := v(val); err != nil { + return err + } + } + return nil + } + // go over every question for _, q := range qs { // If Prompt implements controllable stdio, pass in specified stdio. @@ -304,46 +350,28 @@ func Ask(qs []*Question, response interface{}, opts ...AskOpt) error { p.WithStdio(options.Stdio) } - // grab the user input and save it - ans, err := q.Prompt.Prompt(&options.PromptConfig) - // if there was a problem - if err != nil { - return err - } - - // build up a list of validators that we have to apply to this question - validators := []Validator{} - - // make sure to include the question specific one - if q.Validate != nil { - validators = append(validators, q.Validate) - } - // add any "global" validators - for _, validator := range options.Validators { - validators = append(validators, validator) - } - - // apply every validator to thte response - for _, validator := range validators { - // wait for a valid response - for invalid := validator(ans); invalid != nil; invalid = validator(ans) { - err := q.Prompt.Error(&options.PromptConfig, invalid) - // if there was a problem - if err != nil { - return err - } - - // ask for more input - if promptAgainer, ok := q.Prompt.(PromptAgainer); ok { - ans, err = promptAgainer.PromptAgain(&options.PromptConfig, ans, invalid) - } else { - ans, err = q.Prompt.Prompt(&options.PromptConfig) - } - // if there was a problem - if err != nil { + var ans interface{} + var validationErr error + // prompt and validation loop + for { + if validationErr != nil { + if err := q.Prompt.Error(&options.PromptConfig, validationErr); err != nil { return err } } + var err error + if promptAgainer, ok := q.Prompt.(PromptAgainer); ok && validationErr != nil { + ans, err = promptAgainer.PromptAgain(&options.PromptConfig, ans, validationErr) + } else { + ans, err = q.Prompt.Prompt(&options.PromptConfig) + } + if err != nil { + return err + } + validationErr = validate(q, ans) + if validationErr == nil { + break + } } if q.Transform != nil { @@ -356,21 +384,14 @@ func Ask(qs []*Question, response interface{}, opts ...AskOpt) error { } // tell the prompt to cleanup with the validated value - q.Prompt.Cleanup(&options.PromptConfig, ans) - - // if something went wrong - if err != nil { - // stop listening + if err := q.Prompt.Cleanup(&options.PromptConfig, ans); err != nil { return err } // add it to the map - err = core.WriteAnswer(response, q.Name, ans) - // if something went wrong - if err != nil { + if err := core.WriteAnswer(response, q.Name, ans); err != nil { return err } - } // return the response @@ -420,7 +441,6 @@ type IterableOpts interface { func computeCursorOffset(tmpl string, data IterableOpts, opts []core.OptionAnswer, idx, tWidth int) int { tmpls, err := core.GetTemplatePair(tmpl) - if err != nil { return 0 } @@ -428,8 +448,8 @@ func computeCursorOffset(tmpl string, data IterableOpts, opts []core.OptionAnswe t := tmpls[0] renderOpt := func(ix int, opt core.OptionAnswer) string { - buf := bytes.NewBufferString("") - t.ExecuteTemplate(buf, "option", data.IterateOption(ix, opt)) + var buf bytes.Buffer + _ = t.ExecuteTemplate(&buf, "option", data.IterateOption(ix, opt)) return buf.String() } diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/cursor.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/cursor.go index 1ac74fd..75117e0 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/cursor.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/cursor.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package terminal @@ -21,81 +22,99 @@ type Cursor struct { } // Up moves the cursor n cells to up. -func (c *Cursor) Up(n int) { - fmt.Fprintf(c.Out, "\x1b[%dA", n) +func (c *Cursor) Up(n int) error { + _, err := fmt.Fprintf(c.Out, "\x1b[%dA", n) + return err } // Down moves the cursor n cells to down. -func (c *Cursor) Down(n int) { - fmt.Fprintf(c.Out, "\x1b[%dB", n) +func (c *Cursor) Down(n int) error { + _, err := fmt.Fprintf(c.Out, "\x1b[%dB", n) + return err } // Forward moves the cursor n cells to right. -func (c *Cursor) Forward(n int) { - fmt.Fprintf(c.Out, "\x1b[%dC", n) +func (c *Cursor) Forward(n int) error { + _, err := fmt.Fprintf(c.Out, "\x1b[%dC", n) + return err } // Back moves the cursor n cells to left. -func (c *Cursor) Back(n int) { - fmt.Fprintf(c.Out, "\x1b[%dD", n) +func (c *Cursor) Back(n int) error { + _, err := fmt.Fprintf(c.Out, "\x1b[%dD", n) + return err } // NextLine moves cursor to beginning of the line n lines down. -func (c *Cursor) NextLine(n int) { - c.Down(1) - c.HorizontalAbsolute(0) +func (c *Cursor) NextLine(n int) error { + if err := c.Down(1); err != nil { + return err + } + return c.HorizontalAbsolute(0) } // PreviousLine moves cursor to beginning of the line n lines up. -func (c *Cursor) PreviousLine(n int) { - c.Up(1) - c.HorizontalAbsolute(0) +func (c *Cursor) PreviousLine(n int) error { + if err := c.Up(1); err != nil { + return err + } + return c.HorizontalAbsolute(0) } // HorizontalAbsolute moves cursor horizontally to x. -func (c *Cursor) HorizontalAbsolute(x int) { - fmt.Fprintf(c.Out, "\x1b[%dG", x) +func (c *Cursor) HorizontalAbsolute(x int) error { + _, err := fmt.Fprintf(c.Out, "\x1b[%dG", x) + return err } // Show shows the cursor. -func (c *Cursor) Show() { - fmt.Fprint(c.Out, "\x1b[?25h") +func (c *Cursor) Show() error { + _, err := fmt.Fprint(c.Out, "\x1b[?25h") + return err } // Hide hide the cursor. -func (c *Cursor) Hide() { - fmt.Fprint(c.Out, "\x1b[?25l") +func (c *Cursor) Hide() error { + _, err := fmt.Fprint(c.Out, "\x1b[?25l") + return err } -// Move moves the cursor to a specific x,y location. -func (c *Cursor) Move(x int, y int) { - fmt.Fprintf(c.Out, "\x1b[%d;%df", x, y) +// move moves the cursor to a specific x,y location. +func (c *Cursor) move(x int, y int) error { + _, err := fmt.Fprintf(c.Out, "\x1b[%d;%df", x, y) + return err } // Save saves the current position -func (c *Cursor) Save() { - fmt.Fprint(c.Out, "\x1b7") +func (c *Cursor) Save() error { + _, err := fmt.Fprint(c.Out, "\x1b7") + return err } // Restore restores the saved position of the cursor -func (c *Cursor) Restore() { - fmt.Fprint(c.Out, "\x1b8") +func (c *Cursor) Restore() error { + _, err := fmt.Fprint(c.Out, "\x1b8") + return err } // for comparability purposes between windows // in unix we need to print out a new line on some terminals -func (c *Cursor) MoveNextLine(cur *Coord, terminalSize *Coord) { +func (c *Cursor) MoveNextLine(cur *Coord, terminalSize *Coord) error { if cur.Y == terminalSize.Y { - fmt.Fprintln(c.Out) + if _, err := fmt.Fprintln(c.Out); err != nil { + return err + } } - c.NextLine(1) + return c.NextLine(1) } // Location returns the current location of the cursor in the terminal func (c *Cursor) Location(buf *bytes.Buffer) (*Coord, error) { // ANSI escape sequence for DSR - Device Status Report // https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences - fmt.Fprint(c.Out, "\x1b[6n") + if _, err := fmt.Fprint(c.Out, "\x1b[6n"); err != nil { + return nil, err + } // There may be input in Stdin prior to CursorLocation so make sure we don't // drop those bytes. @@ -176,7 +195,7 @@ func (c *Cursor) Size(buf *bytes.Buffer) (*Coord, error) { defer c.Restore() // move the cursor to the very bottom of the terminal - c.Move(999, 999) + c.move(999, 999) // ask for the current location bottom, err := c.Location(buf) diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/cursor_windows.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/cursor_windows.go index e24440e..c264591 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/cursor_windows.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/cursor_windows.go @@ -16,31 +16,37 @@ type Cursor struct { Out FileWriter } -func (c *Cursor) Up(n int) { - c.cursorMove(0, n) +func (c *Cursor) Up(n int) error { + return c.cursorMove(0, n) } -func (c *Cursor) Down(n int) { - c.cursorMove(0, -1*n) +func (c *Cursor) Down(n int) error { + return c.cursorMove(0, -1*n) } -func (c *Cursor) Forward(n int) { - c.cursorMove(n, 0) +func (c *Cursor) Forward(n int) error { + return c.cursorMove(n, 0) } -func (c *Cursor) Back(n int) { - c.cursorMove(-1*n, 0) +func (c *Cursor) Back(n int) error { + return c.cursorMove(-1*n, 0) } // save the cursor location -func (c *Cursor) Save() { - cursorLoc, _ = c.Location(nil) +func (c *Cursor) Save() error { + loc, err := c.Location(nil) + if err != nil { + return err + } + cursorLoc = *loc + return nil } -func (c *Cursor) Restore() { +func (c *Cursor) Restore() error { handle := syscall.Handle(c.Out.Fd()) // restore it to the original position - procSetConsoleCursorPosition.Call(uintptr(handle), uintptr(*(*int32)(unsafe.Pointer(&cursorLoc)))) + _, _, err := procSetConsoleCursorPosition.Call(uintptr(handle), uintptr(*(*int32)(unsafe.Pointer(&cursorLoc)))) + return normalizeError(err) } func (cur Coord) CursorIsAtLineEnd(size *Coord) bool { @@ -51,40 +57,49 @@ func (cur Coord) CursorIsAtLineBegin() bool { return cur.X == 0 } -func (c *Cursor) cursorMove(x int, y int) { +func (c *Cursor) cursorMove(x int, y int) error { handle := syscall.Handle(c.Out.Fd()) var csbi consoleScreenBufferInfo - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) + if _, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))); normalizeError(err) != nil { + return err + } var cursor Coord cursor.X = csbi.cursorPosition.X + Short(x) cursor.Y = csbi.cursorPosition.Y + Short(y) - procSetConsoleCursorPosition.Call(uintptr(handle), uintptr(*(*int32)(unsafe.Pointer(&cursor)))) + _, _, err := procSetConsoleCursorPosition.Call(uintptr(handle), uintptr(*(*int32)(unsafe.Pointer(&cursor)))) + return normalizeError(err) } -func (c *Cursor) NextLine(n int) { - c.Up(n) - c.HorizontalAbsolute(0) +func (c *Cursor) NextLine(n int) error { + if err := c.Up(n); err != nil { + return err + } + return c.HorizontalAbsolute(0) } -func (c *Cursor) PreviousLine(n int) { - c.Down(n) - c.HorizontalAbsolute(0) +func (c *Cursor) PreviousLine(n int) error { + if err := c.Down(n); err != nil { + return err + } + return c.HorizontalAbsolute(0) } // for comparability purposes between windows // in windows we don't have to print out a new line -func (c *Cursor) MoveNextLine(cur Coord, terminalSize *Coord) { - c.NextLine(1) +func (c *Cursor) MoveNextLine(cur *Coord, terminalSize *Coord) error { + return c.NextLine(1) } -func (c *Cursor) HorizontalAbsolute(x int) { +func (c *Cursor) HorizontalAbsolute(x int) error { handle := syscall.Handle(c.Out.Fd()) var csbi consoleScreenBufferInfo - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) + if _, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))); normalizeError(err) != nil { + return err + } var cursor Coord cursor.X = Short(x) @@ -94,43 +109,54 @@ func (c *Cursor) HorizontalAbsolute(x int) { cursor.X = csbi.size.X } - procSetConsoleCursorPosition.Call(uintptr(handle), uintptr(*(*int32)(unsafe.Pointer(&cursor)))) + _, _, err := procSetConsoleCursorPosition.Call(uintptr(handle), uintptr(*(*int32)(unsafe.Pointer(&cursor)))) + return normalizeError(err) } -func (c *Cursor) Show() { +func (c *Cursor) Show() error { handle := syscall.Handle(c.Out.Fd()) var cci consoleCursorInfo - procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&cci))) + if _, _, err := procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&cci))); normalizeError(err) != nil { + return err + } cci.visible = 1 - procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&cci))) + _, _, err := procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&cci))) + return normalizeError(err) } -func (c *Cursor) Hide() { +func (c *Cursor) Hide() error { handle := syscall.Handle(c.Out.Fd()) var cci consoleCursorInfo - procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&cci))) + if _, _, err := procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&cci))); normalizeError(err) != nil { + return err + } cci.visible = 0 - procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&cci))) + _, _, err := procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&cci))) + return normalizeError(err) } -func (c *Cursor) Location(buf *bytes.Buffer) (Coord, error) { +func (c *Cursor) Location(buf *bytes.Buffer) (*Coord, error) { handle := syscall.Handle(c.Out.Fd()) var csbi consoleScreenBufferInfo - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) + if _, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))); normalizeError(err) != nil { + return nil, err + } - return csbi.cursorPosition, nil + return &csbi.cursorPosition, nil } func (c *Cursor) Size(buf *bytes.Buffer) (*Coord, error) { handle := syscall.Handle(c.Out.Fd()) var csbi consoleScreenBufferInfo - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) + if _, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))); normalizeError(err) != nil { + return nil, err + } // windows' coordinate system begins at (0, 0) csbi.size.X-- csbi.size.Y-- diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/display_posix.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/display_posix.go index 838dd66..fbd1b79 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/display_posix.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/display_posix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package terminal @@ -6,6 +7,7 @@ import ( "fmt" ) -func EraseLine(out FileWriter, mode EraseLineMode) { - fmt.Fprintf(out, "\x1b[%dK", mode) +func EraseLine(out FileWriter, mode EraseLineMode) error { + _, err := fmt.Fprintf(out, "\x1b[%dK", mode) + return err } diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/display_windows.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/display_windows.go index 0adc1de..fc9db9f 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/display_windows.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/display_windows.go @@ -5,11 +5,13 @@ import ( "unsafe" ) -func EraseLine(out FileWriter, mode EraseLineMode) { +func EraseLine(out FileWriter, mode EraseLineMode) error { handle := syscall.Handle(out.Fd()) var csbi consoleScreenBufferInfo - procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))) + if _, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi))); normalizeError(err) != nil { + return err + } var w uint32 var x Short @@ -23,5 +25,7 @@ func EraseLine(out FileWriter, mode EraseLineMode) { cursor.X = 0 x = csbi.size.X } - procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(x), uintptr(*(*int32)(unsafe.Pointer(&cursor))), uintptr(unsafe.Pointer(&w))) + + _, _, err := procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(x), uintptr(*(*int32)(unsafe.Pointer(&cursor))), uintptr(unsafe.Pointer(&w))) + return normalizeError(err) } diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/error.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/error.go index 710c361..55eb665 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/error.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/error.go @@ -5,5 +5,6 @@ import ( ) var ( + //lint:ignore ST1012 keeping old name for backwards compatibility InterruptErr = errors.New("interrupt") ) diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/output.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/output.go index 6fe11c0..2910242 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/output.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/output.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package terminal diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/output_windows.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/output_windows.go index 6622690..eaf5c43 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/output_windows.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/output_windows.go @@ -12,18 +12,6 @@ import ( "github.com/mattn/go-isatty" ) -var ( - cursorFunctions = map[rune]func(c *Cursor) func(int){ - 'A': func(c *Cursor) func(int) { return c.Up }, - 'B': func(c *Cursor) func(int) { return c.Down }, - 'C': func(c *Cursor) func(int) { return c.Forward }, - 'D': func(c *Cursor) func(int) { return c.Back }, - 'E': func(c *Cursor) func(int) { return c.NextLine }, - 'F': func(c *Cursor) func(int) { return c.PreviousLine }, - 'G': func(c *Cursor) func(int) { return c.HorizontalAbsolute }, - } -) - const ( foregroundBlue = 0x1 foregroundGreen = 0x2 @@ -67,9 +55,14 @@ func (w *Writer) Write(data []byte) (n int, err error) { r := bytes.NewReader(data) for { - ch, size, err := r.ReadRune() + var ch rune + var size int + ch, size, err = r.ReadRune() if err != nil { - break + if err == io.EOF { + err = nil + } + return } n += size @@ -78,22 +71,29 @@ func (w *Writer) Write(data []byte) (n int, err error) { size, err = w.handleEscape(r) n += size if err != nil { - break + return } default: - fmt.Fprint(w.out, string(ch)) + _, err = fmt.Fprint(w.out, string(ch)) + if err != nil { + return + } } } - return } func (w *Writer) handleEscape(r *bytes.Reader) (n int, err error) { buf := make([]byte, 0, 10) buf = append(buf, "\x1b"...) + var ch rune + var size int // Check '[' continues after \x1b - ch, size, err := r.ReadRune() + ch, size, err = r.ReadRune() if err != nil { + if err == io.EOF { + err = nil + } fmt.Fprint(w.out, string(buf)) return } @@ -109,6 +109,9 @@ func (w *Writer) handleEscape(r *bytes.Reader) (n int, err error) { for { ch, size, err = r.ReadRune() if err != nil { + if err == io.EOF { + err = nil + } fmt.Fprint(w.out, string(buf)) return } @@ -120,47 +123,62 @@ func (w *Writer) handleEscape(r *bytes.Reader) (n int, err error) { argBuf = append(argBuf, string(ch)...) } - w.applyEscapeCode(buf, string(argBuf), code) + err = w.applyEscapeCode(buf, string(argBuf), code) return } -func (w *Writer) applyEscapeCode(buf []byte, arg string, code rune) { +func (w *Writer) applyEscapeCode(buf []byte, arg string, code rune) error { c := &Cursor{Out: w.out} switch arg + string(code) { case "?25h": - c.Show() - return + return c.Show() case "?25l": - c.Hide() - return + return c.Hide() } - if f, ok := cursorFunctions[code]; ok { + if code >= 'A' && code <= 'G' { if n, err := strconv.Atoi(arg); err == nil { - f(c)(n) - return + switch code { + case 'A': + return c.Up(n) + case 'B': + return c.Down(n) + case 'C': + return c.Forward(n) + case 'D': + return c.Back(n) + case 'E': + return c.NextLine(n) + case 'F': + return c.PreviousLine(n) + case 'G': + return c.HorizontalAbsolute(n) + } } } switch code { case 'm': - w.applySelectGraphicRendition(arg) + return w.applySelectGraphicRendition(arg) default: buf = append(buf, string(code)...) - fmt.Fprint(w.out, string(buf)) + _, err := fmt.Fprint(w.out, string(buf)) + return err } } // Original implementation: https://github.com/mattn/go-colorable -func (w *Writer) applySelectGraphicRendition(arg string) { +func (w *Writer) applySelectGraphicRendition(arg string) error { if arg == "" { - procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(w.orgAttr)) - return + _, _, err := procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(w.orgAttr)) + return normalizeError(err) } var csbi consoleScreenBufferInfo - procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))) + if _, _, err := procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi))); normalizeError(err) != nil { + return err + } attr := csbi.attributes for _, param := range strings.Split(arg, ";") { @@ -223,5 +241,13 @@ func (w *Writer) applySelectGraphicRendition(arg string) { } } - procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(attr)) + _, _, err := procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(attr)) + return normalizeError(err) +} + +func normalizeError(err error) error { + if syserr, ok := err.(syscall.Errno); ok && syserr == 0 { + return nil + } + return err } diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader.go index 94c915c..998e415 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader.go @@ -8,9 +8,8 @@ import ( ) type RuneReader struct { - stdio Stdio - cursor *Cursor - state runeReaderState + stdio Stdio + state runeReaderState } func NewRuneReader(stdio Stdio) *RuneReader { @@ -20,15 +19,16 @@ func NewRuneReader(stdio Stdio) *RuneReader { } } -func (rr *RuneReader) printChar(char rune, mask rune) { +func (rr *RuneReader) printChar(char rune, mask rune) error { // if we don't need to mask the input if mask == 0 { // just print the character the user pressed - fmt.Fprintf(rr.stdio.Out, "%c", char) - } else { - // otherwise print the mask we were given - fmt.Fprintf(rr.stdio.Out, "%c", mask) + _, err := fmt.Fprintf(rr.stdio.Out, "%c", char) + return err } + // otherwise print the mask we were given + _, err := fmt.Fprintf(rr.stdio.Out, "%c", mask) + return err } type OnRuneFn func(rune, []rune) ([]rune, bool, error) @@ -80,7 +80,9 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune if len(d) > 0 { index = len(d) - fmt.Fprint(rr.stdio.Out, string(d)) + if _, err := fmt.Fprint(rr.stdio.Out, string(d)); err != nil { + return d, err + } line = d for range d { increment() @@ -121,7 +123,9 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune // if the user interrupts (ie with ctrl+c) if r == KeyInterrupt { // go to the beginning of the next line - fmt.Fprint(rr.stdio.Out, "\r\n") + if _, err := fmt.Fprint(rr.stdio.Out, "\r\n"); err != nil { + return line, err + } // we're done processing the input, and treat interrupt like an error return line, InterruptErr @@ -168,8 +172,9 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune //Erase symbols which are left over from older print EraseLine(rr.stdio.Out, ERASE_LINE_END) // print characters to the new line appropriately - rr.printChar(char, mask) - + if err := rr.printChar(char, mask); err != nil { + return line, err + } } // erase what's left over from last print if cursorCurrent.Y < terminalSize.Y { @@ -191,7 +196,7 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune decrement() } else { // otherwise the user pressed backspace while at the beginning of the line - soundBell(rr.stdio.Out) + _ = soundBell(rr.stdio.Out) } // we're done processing this key @@ -216,7 +221,7 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune } else { // otherwise we are at the beginning of where we started reading lines // sound the bell - soundBell(rr.stdio.Out) + _ = soundBell(rr.stdio.Out) } // we're done processing this key press @@ -239,7 +244,7 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune } else { // otherwise we are at the end of the word and can't go past // sound the bell - soundBell(rr.stdio.Out) + _ = soundBell(rr.stdio.Out) } // we're done processing this key press @@ -288,7 +293,9 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune for _, char := range line[index:] { EraseLine(rr.stdio.Out, ERASE_LINE_END) // print out the character - rr.printChar(char, mask) + if err := rr.printChar(char, mask); err != nil { + return line, err + } } // erase what's left on last line if cursorCurrent.Y < terminalSize.Y { @@ -320,7 +327,9 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune index++ increment() // print out the character - rr.printChar(r, mask) + if err := rr.printChar(r, mask); err != nil { + return line, err + } } else { // we are in the middle of the word so we need to insert the character the user pressed line = append(line[:index], append([]rune{r}, line[index:]...)...) @@ -334,13 +343,17 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune for _, char := range line[index:] { EraseLine(rr.stdio.Out, ERASE_LINE_END) // print out the character - rr.printChar(char, mask) + if err := rr.printChar(char, mask); err != nil { + return line, err + } increment() } // if we are at the last line, we want to visually insert a new line and append to it. if cursorCurrent.CursorIsAtLineEnd(terminalSize) && cursorCurrent.Y == terminalSize.Y { // add a new line to the terminal - fmt.Fprintln(rr.stdio.Out) + if _, err := fmt.Fprintln(rr.stdio.Out); err != nil { + return line, err + } // restore the position of the cursor horizontally cursor.Restore() // restore the position of the cursor vertically @@ -364,10 +377,41 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune } } +// runeWidth returns the number of columns spanned by a rune when printed to the terminal func runeWidth(r rune) int { switch width.LookupRune(r).Kind() { case width.EastAsianWide, width.EastAsianFullwidth: return 2 } + + if !unicode.IsPrint(r) { + return 0 + } return 1 } + +// isAnsiMarker returns if a rune denotes the start of an ANSI sequence +func isAnsiMarker(r rune) bool { + return r == '\x1B' +} + +// isAnsiTerminator returns if a rune denotes the end of an ANSI sequence +func isAnsiTerminator(r rune) bool { + return (r >= 0x40 && r <= 0x5a) || (r == 0x5e) || (r >= 0x60 && r <= 0x7e) +} + +// StringWidth returns the visible width of a string when printed to the terminal +func StringWidth(str string) int { + w := 0 + ansi := false + + for _, r := range str { + // increase width only when outside of ANSI escape sequences + if ansi || isAnsiMarker(r) { + ansi = !isAnsiTerminator(r) + } else { + w += runeWidth(r) + } + } + return w +} diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_bsd.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_bsd.go index 6ea3409..57f1014 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_bsd.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_bsd.go @@ -3,6 +3,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build darwin || dragonfly || freebsd || netbsd || openbsd // +build darwin dragonfly freebsd netbsd openbsd package terminal diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_linux.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_linux.go index 6dd60ea..dc7ec67 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_linux.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_linux.go @@ -2,6 +2,7 @@ // Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build linux && !ppc64le // +build linux,!ppc64le package terminal diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_posix.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_posix.go index 99cbf43..563a081 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_posix.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_posix.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows // The terminal mode manipulation code is derived heavily from: @@ -50,6 +51,11 @@ func (rr *RuneReader) SetTermMode() error { newState := rr.state.term newState.Lflag &^= syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG + // Because we are clearing canonical mode, we need to ensure VMIN & VTIME are + // set to the values we expect. This combination puts things in standard + // "blocking read" mode (see termios(3)). + newState.Cc[syscall.VMIN] = 1 + newState.Cc[syscall.VTIME] = 0 if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(rr.stdio.In.Fd()), ioctlWriteTermios, uintptr(unsafe.Pointer(&newState)), 0, 0, 0); err != 0 { return err diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_ppc64le.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_ppc64le.go index ae4eb09..450f796 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_ppc64le.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/runereader_ppc64le.go @@ -1,3 +1,4 @@ +//go:build ppc64le && linux // +build ppc64le,linux package terminal diff --git a/vendor/github.com/AlecAivazis/survey/v2/terminal/sequences.go b/vendor/github.com/AlecAivazis/survey/v2/terminal/sequences.go index 6d9e877..5f61e2b 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/terminal/sequences.go +++ b/vendor/github.com/AlecAivazis/survey/v2/terminal/sequences.go @@ -26,6 +26,7 @@ const ( KeyTab = '\t' ) -func soundBell(out io.Writer) { - fmt.Fprint(out, "\a") +func soundBell(out io.Writer) error { + _, err := fmt.Fprint(out, "\a") + return err } diff --git a/vendor/github.com/AlecAivazis/survey/v2/transform.go b/vendor/github.com/AlecAivazis/survey/v2/transform.go index 58d5193..a78ada3 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/transform.go +++ b/vendor/github.com/AlecAivazis/survey/v2/transform.go @@ -3,6 +3,9 @@ package survey import ( "reflect" "strings" + + "golang.org/x/text/cases" + "golang.org/x/text/language" ) // TransformString returns a `Transformer` based on the "f" @@ -62,7 +65,7 @@ func ToLower(ans interface{}) interface{} { // return a nil value, meaning that the above answer // will not be affected by this call at all. func Title(ans interface{}) interface{} { - transformer := TransformString(strings.Title) + transformer := TransformString(cases.Title(language.English).String) return transformer(ans) } diff --git a/vendor/github.com/AlecAivazis/survey/v2/validate.go b/vendor/github.com/AlecAivazis/survey/v2/validate.go index 462dc5e..7f03b23 100644 --- a/vendor/github.com/AlecAivazis/survey/v2/validate.go +++ b/vendor/github.com/AlecAivazis/survey/v2/validate.go @@ -15,6 +15,7 @@ func Required(val interface{}) error { // if the value passed in is the zero value of the appropriate type if isZero(value) && value.Kind() != reflect.Bool { + //lint:ignore ST1005 this error message should render as capitalized return errors.New("Value is required") } return nil @@ -87,7 +88,7 @@ func MinItems(numberItems int) Validator { // if the list is shorter than the given value if len(list) < numberItems { // yell loudly - return fmt.Errorf("value is too long. Min items is %v", numberItems) + return fmt.Errorf("value is too short. Min items is %v", numberItems) } } else { // otherwise we cannot convert the value into a list of answer and cannot enforce length diff --git a/vendor/github.com/briandowns/spinner/NOTICE.txt b/vendor/github.com/briandowns/spinner/NOTICE.txt index e72228e..95e2a24 100644 --- a/vendor/github.com/briandowns/spinner/NOTICE.txt +++ b/vendor/github.com/briandowns/spinner/NOTICE.txt @@ -1,4 +1,4 @@ Spinner -Copyright (c) 2021 Brian J. Downs +Copyright (c) 2022 Brian J. Downs This product is licensed to you under the Apache 2.0 license (the "License"). You may not use this product except in compliance with the Apache 2.0 License. This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. diff --git a/vendor/github.com/briandowns/spinner/README.md b/vendor/github.com/briandowns/spinner/README.md index 20b315f..28b024d 100644 --- a/vendor/github.com/briandowns/spinner/README.md +++ b/vendor/github.com/briandowns/spinner/README.md @@ -1,6 +1,6 @@ # Spinner -[![GoDoc](https://godoc.org/github.com/briandowns/spinner?status.svg)](https://godoc.org/github.com/briandowns/spinner) [![Build Status](https://travis-ci.org/briandowns/spinner.svg?branch=master)](https://travis-ci.org/briandowns/spinner) +[![GoDoc](https://godoc.org/github.com/briandowns/spinner?status.svg)](https://godoc.org/github.com/briandowns/spinner) [![CircleCI](https://circleci.com/gh/briandowns/spinner.svg?style=svg)](https://circleci.com/gh/briandowns/spinner) spinner is a simple package to add a spinner / progress indicator to any terminal application. Examples can be found below as well as full examples in the examples directory. diff --git a/vendor/github.com/briandowns/spinner/character_sets.go b/vendor/github.com/briandowns/spinner/character_sets.go index 9c8a98b..df41a0f 100644 --- a/vendor/github.com/briandowns/spinner/character_sets.go +++ b/vendor/github.com/briandowns/spinner/character_sets.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Brian J. Downs +// Copyright (c) 2022 Brian J. Downs // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/vendor/github.com/briandowns/spinner/spinner.go b/vendor/github.com/briandowns/spinner/spinner.go index 7fc56f4..97b1a8f 100644 --- a/vendor/github.com/briandowns/spinner/spinner.go +++ b/vendor/github.com/briandowns/spinner/spinner.go @@ -19,6 +19,7 @@ import ( "errors" "fmt" "io" + "math" "os" "runtime" "strconv" @@ -28,6 +29,8 @@ import ( "unicode/utf8" "github.com/fatih/color" + "github.com/mattn/go-isatty" + "golang.org/x/term" ) // errInvalidColor is returned when attempting to set an invalid color @@ -99,7 +102,8 @@ var validColors = map[string]bool{ } // returns true if the OS is windows and the WT_SESSION env variable is set. -var isWindowsTerminalOnWindows = len(os.Getenv("WT_SESSION")) > 0 && runtime.GOOS == "windows" +var isWindows = runtime.GOOS == "windows" +var isWindowsTerminalOnWindows = len(os.Getenv("WT_SESSION")) > 0 && isWindows // returns a valid color's foreground text color attribute var colorAttributeMap = map[string]color.Attribute{ @@ -173,32 +177,38 @@ func validColor(c string) bool { // Spinner struct to hold the provided options. type Spinner struct { - mu *sync.RWMutex - Delay time.Duration // Delay is the speed of the indicator - chars []string // chars holds the chosen character set - Prefix string // Prefix is the text preppended to the indicator - Suffix string // Suffix is the text appended to the indicator - FinalMSG string // string displayed after Stop() is called - lastOutput string // last character(set) written - color func(a ...interface{}) string // default color is white - Writer io.Writer // to make testing better, exported so users have access. Use `WithWriter` to update after initialization. - active bool // active holds the state of the spinner - stopChan chan struct{} // stopChan is a channel used to stop the indicator - HideCursor bool // hideCursor determines if the cursor is visible - PreUpdate func(s *Spinner) // will be triggered before every spinner update - PostUpdate func(s *Spinner) // will be triggered after every spinner update + mu *sync.RWMutex + Delay time.Duration // Delay is the speed of the indicator + chars []string // chars holds the chosen character set + Prefix string // Prefix is the text preppended to the indicator + Suffix string // Suffix is the text appended to the indicator + FinalMSG string // string displayed after Stop() is called + lastOutputPlain string // last character(set) written + LastOutput string // last character(set) written with colors + color func(a ...interface{}) string // default color is white + Writer io.Writer // to make testing better, exported so users have access. Use `WithWriter` to update after initialization. + WriterFile *os.File // writer as file to allow terminal check + active bool // active holds the state of the spinner + enabled bool // indicates whether the spinner is enabled or not + stopChan chan struct{} // stopChan is a channel used to stop the indicator + HideCursor bool // hideCursor determines if the cursor is visible + PreUpdate func(s *Spinner) // will be triggered before every spinner update + PostUpdate func(s *Spinner) // will be triggered after every spinner update } // New provides a pointer to an instance of Spinner with the supplied options. func New(cs []string, d time.Duration, options ...Option) *Spinner { s := &Spinner{ - Delay: d, - chars: cs, - color: color.New(color.FgWhite).SprintFunc(), - mu: &sync.RWMutex{}, - Writer: color.Output, - active: false, - stopChan: make(chan struct{}, 1), + Delay: d, + chars: cs, + color: color.New(color.FgWhite).SprintFunc(), + mu: &sync.RWMutex{}, + Writer: color.Output, + WriterFile: os.Stdout, // matches color.Output + stopChan: make(chan struct{}, 1), + active: false, + enabled: true, + HideCursor: true, } for _, option := range options { @@ -253,11 +263,28 @@ func WithHiddenCursor(hideCursor bool) Option { // WithWriter adds the given writer to the spinner. This // function should be favored over directly assigning to -// the struct value. +// the struct value. Assumes it is not working on a terminal +// since it cannot determine from io.Writer. Use WithWriterFile +// to support terminal checks. func WithWriter(w io.Writer) Option { return func(s *Spinner) { s.mu.Lock() s.Writer = w + s.WriterFile = os.Stdout // emulate previous behavior for terminal check + s.mu.Unlock() + } +} + +// WithWriterFile adds the given writer to the spinner. This +// function should be favored over directly assigning to +// the struct value. Unlike WithWriter, this function allows +// us to check if displaying to a terminal (enable spinning) or +// not (disable spinning). Supersedes WithWriter() +func WithWriterFile(f *os.File) Option { + return func(s *Spinner) { + s.mu.Lock() + s.Writer = f // io.Writer for actual writing + s.WriterFile = f // file used only for terminal check s.mu.Unlock() } } @@ -267,10 +294,27 @@ func (s *Spinner) Active() bool { return s.active } +// Enabled returns whether or not the spinner is enabled. +func (s *Spinner) Enabled() bool { + return s.enabled +} + +// Enable enables and restarts the spinner +func (s *Spinner) Enable() { + s.enabled = true + s.Restart() +} + +// Disable stops and disables the spinner +func (s *Spinner) Disable() { + s.enabled = false + s.Stop() +} + // Start will start the indicator. func (s *Spinner) Start() { s.mu.Lock() - if s.active { + if s.active || !s.enabled || !isRunningInTerminal(s) { s.mu.Unlock() return } @@ -278,6 +322,12 @@ func (s *Spinner) Start() { // hides the cursor fmt.Fprint(s.Writer, "\033[?25l") } + // Disable colors for simple Windows CMD or Powershell + // as they can not recognize them + if isWindows && !isWindowsTerminalOnWindows { + color.NoColor = true + } + s.active = true s.mu.Unlock() @@ -302,7 +352,7 @@ func (s *Spinner) Start() { } var outColor string - if runtime.GOOS == "windows" { + if isWindows { if s.Writer == os.Stderr { outColor = fmt.Sprintf("\r%s%s%s", s.Prefix, s.chars[i], s.Suffix) } else { @@ -313,7 +363,8 @@ func (s *Spinner) Start() { } outPlain := fmt.Sprintf("\r%s%s%s", s.Prefix, s.chars[i], s.Suffix) fmt.Fprint(s.Writer, outColor) - s.lastOutput = outPlain + s.lastOutputPlain = outPlain + s.LastOutput = outColor delay := s.Delay if s.PostUpdate != nil { @@ -401,22 +452,32 @@ func (s *Spinner) UpdateCharSet(cs []string) { // erase deletes written characters on the current line. // Caller must already hold s.lock. func (s *Spinner) erase() { - n := utf8.RuneCountInString(s.lastOutput) + n := utf8.RuneCountInString(s.lastOutputPlain) if runtime.GOOS == "windows" && !isWindowsTerminalOnWindows { clearString := "\r" + strings.Repeat(" ", n) + "\r" fmt.Fprint(s.Writer, clearString) - s.lastOutput = "" + s.lastOutputPlain = "" return } + numberOfLinesToErase := computeNumberOfLinesNeededToPrintString(s.lastOutputPlain) + // Taken from https://en.wikipedia.org/wiki/ANSI_escape_code: // \r - Carriage return - Moves the cursor to column zero // \033[K - Erases part of the line. If n is 0 (or missing), clear from // cursor to the end of the line. If n is 1, clear from cursor to beginning // of the line. If n is 2, clear entire line. Cursor position does not // change. - fmt.Fprintf(s.Writer, "\r\033[K") - s.lastOutput = "" + // \033[F - Go to the beginning of previous line + eraseCodeString := strings.Builder{} + // current position is at the end of the last printed line. Start by erasing current line + eraseCodeString.WriteString("\r\033[K") // start by erasing current line + for i := 1; i < numberOfLinesToErase; i++ { + // For each additional lines, go up one line and erase it. + eraseCodeString.WriteString("\033[F\033[K") + } + fmt.Fprintf(s.Writer, eraseCodeString.String()) + s.lastOutputPlain = "" } // Lock allows for manual control to lock the spinner. @@ -438,3 +499,59 @@ func GenerateNumberSequence(length int) []string { } return numSeq } + +// isRunningInTerminal check if the writer file descriptor is a terminal +func isRunningInTerminal(s *Spinner) bool { + return isatty.IsTerminal(s.WriterFile.Fd()) +} + +func computeNumberOfLinesNeededToPrintString(linePrinted string) int { + terminalWidth := math.MaxInt // assume infinity by default to keep behaviour consistent with what we had before + if term.IsTerminal(0) { + if width, _, err := term.GetSize(0); err == nil { + terminalWidth = width + } + } + return computeNumberOfLinesNeededToPrintStringInternal(linePrinted, terminalWidth) +} + +// isAnsiMarker returns if a rune denotes the start of an ANSI sequence +func isAnsiMarker(r rune) bool { + return r == '\x1b' +} + +// isAnsiTerminator returns if a rune denotes the end of an ANSI sequence +func isAnsiTerminator(r rune) bool { + return (r >= 0x40 && r <= 0x5a) || (r == 0x5e) || (r >= 0x60 && r <= 0x7e) +} + +// computeLineWidth returns the displayed width of a line +func computeLineWidth(line string) int { + width := 0 + ansi := false + + for _, r := range []rune(line) { + // increase width only when outside of ANSI escape sequences + if ansi || isAnsiMarker(r) { + ansi = !isAnsiTerminator(r) + } else { + width += utf8.RuneLen(r) + } + } + + return width +} + +func computeNumberOfLinesNeededToPrintStringInternal(linePrinted string, maxLineWidth int) int { + lineCount := 0 + for _, line := range strings.Split(linePrinted, "\n") { + lineCount += 1 + + lineWidth := computeLineWidth(line) + if lineWidth > maxLineWidth { + lineCount += int(float64(lineWidth) / float64(maxLineWidth)) + } + } + + return lineCount +} diff --git a/vendor/github.com/cpuguy83/go-md2man/v2/md2man/md2man.go b/vendor/github.com/cpuguy83/go-md2man/v2/md2man/md2man.go index b480056..42bf32a 100644 --- a/vendor/github.com/cpuguy83/go-md2man/v2/md2man/md2man.go +++ b/vendor/github.com/cpuguy83/go-md2man/v2/md2man/md2man.go @@ -9,6 +9,8 @@ func Render(doc []byte) []byte { renderer := NewRoffRenderer() return blackfriday.Run(doc, - []blackfriday.Option{blackfriday.WithRenderer(renderer), - blackfriday.WithExtensions(renderer.GetExtensions())}...) + []blackfriday.Option{ + blackfriday.WithRenderer(renderer), + blackfriday.WithExtensions(renderer.GetExtensions()), + }...) } diff --git a/vendor/github.com/cpuguy83/go-md2man/v2/md2man/roff.go b/vendor/github.com/cpuguy83/go-md2man/v2/md2man/roff.go index 0668a66..8a290f1 100644 --- a/vendor/github.com/cpuguy83/go-md2man/v2/md2man/roff.go +++ b/vendor/github.com/cpuguy83/go-md2man/v2/md2man/roff.go @@ -1,6 +1,8 @@ package md2man import ( + "bufio" + "bytes" "fmt" "io" "os" @@ -15,38 +17,40 @@ type roffRenderer struct { extensions blackfriday.Extensions listCounters []int firstHeader bool - defineTerm bool + firstDD bool listDepth int } const ( - titleHeader = ".TH " - topLevelHeader = "\n\n.SH " - secondLevelHdr = "\n.SH " - otherHeader = "\n.SS " - crTag = "\n" - emphTag = "\\fI" - emphCloseTag = "\\fP" - strongTag = "\\fB" - strongCloseTag = "\\fP" - breakTag = "\n.br\n" - paraTag = "\n.PP\n" - hruleTag = "\n.ti 0\n\\l'\\n(.lu'\n" - linkTag = "\n\\[la]" - linkCloseTag = "\\[ra]" - codespanTag = "\\fB\\fC" - codespanCloseTag = "\\fR" - codeTag = "\n.PP\n.RS\n\n.nf\n" - codeCloseTag = "\n.fi\n.RE\n" - quoteTag = "\n.PP\n.RS\n" - quoteCloseTag = "\n.RE\n" - listTag = "\n.RS\n" - listCloseTag = "\n.RE\n" - arglistTag = "\n.TP\n" - tableStart = "\n.TS\nallbox;\n" - tableEnd = ".TE\n" - tableCellStart = "T{\n" - tableCellEnd = "\nT}\n" + titleHeader = ".TH " + topLevelHeader = "\n\n.SH " + secondLevelHdr = "\n.SH " + otherHeader = "\n.SS " + crTag = "\n" + emphTag = "\\fI" + emphCloseTag = "\\fP" + strongTag = "\\fB" + strongCloseTag = "\\fP" + breakTag = "\n.br\n" + paraTag = "\n.PP\n" + hruleTag = "\n.ti 0\n\\l'\\n(.lu'\n" + linkTag = "\n\\[la]" + linkCloseTag = "\\[ra]" + codespanTag = "\\fB" + codespanCloseTag = "\\fR" + codeTag = "\n.EX\n" + codeCloseTag = ".EE\n" // Do not prepend a newline character since code blocks, by definition, include a newline already (or at least as how blackfriday gives us on). + quoteTag = "\n.PP\n.RS\n" + quoteCloseTag = "\n.RE\n" + listTag = "\n.RS\n" + listCloseTag = "\n.RE\n" + dtTag = "\n.TP\n" + dd2Tag = "\n" + tableStart = "\n.TS\nallbox;\n" + tableEnd = ".TE\n" + tableCellStart = "T{\n" + tableCellEnd = "\nT}\n" + tablePreprocessor = `'\" t` ) // NewRoffRenderer creates a new blackfriday Renderer for generating roff documents @@ -73,6 +77,16 @@ func (r *roffRenderer) GetExtensions() blackfriday.Extensions { // RenderHeader handles outputting the header at document start func (r *roffRenderer) RenderHeader(w io.Writer, ast *blackfriday.Node) { + // We need to walk the tree to check if there are any tables. + // If there are, we need to enable the roff table preprocessor. + ast.Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus { + if node.Type == blackfriday.Table { + out(w, tablePreprocessor+"\n") + return blackfriday.Terminate + } + return blackfriday.GoToNext + }) + // disable hyphenation out(w, ".nh\n") } @@ -85,12 +99,11 @@ func (r *roffRenderer) RenderFooter(w io.Writer, ast *blackfriday.Node) { // RenderNode is called for each node in a markdown document; based on the node // type the equivalent roff output is sent to the writer func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering bool) blackfriday.WalkStatus { - - var walkAction = blackfriday.GoToNext + walkAction := blackfriday.GoToNext switch node.Type { case blackfriday.Text: - r.handleText(w, node, entering) + escapeSpecialChars(w, node.Literal) case blackfriday.Softbreak: out(w, crTag) case blackfriday.Hardbreak: @@ -108,9 +121,16 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering out(w, strongCloseTag) } case blackfriday.Link: - if !entering { - out(w, linkTag+string(node.LinkData.Destination)+linkCloseTag) + // Don't render the link text for automatic links, because this + // will only duplicate the URL in the roff output. + // See https://daringfireball.net/projects/markdown/syntax#autolink + if !bytes.Equal(node.LinkData.Destination, node.FirstChild.Literal) { + out(w, string(node.FirstChild.Literal)) } + // Hyphens in a link must be escaped to avoid word-wrap in the rendered man page. + escapedLink := strings.ReplaceAll(string(node.LinkData.Destination), "-", "\\-") + out(w, linkTag+escapedLink+linkCloseTag) + walkAction = blackfriday.SkipChildren case blackfriday.Image: // ignore images walkAction = blackfriday.SkipChildren @@ -150,40 +170,26 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering out(w, codeCloseTag) case blackfriday.Table: r.handleTable(w, node, entering) - case blackfriday.TableCell: - r.handleTableCell(w, node, entering) case blackfriday.TableHead: case blackfriday.TableBody: case blackfriday.TableRow: // no action as cell entries do all the nroff formatting return blackfriday.GoToNext + case blackfriday.TableCell: + r.handleTableCell(w, node, entering) + case blackfriday.HTMLSpan: + // ignore other HTML tags + case blackfriday.HTMLBlock: + if bytes.HasPrefix(node.Literal, []byte("