diff --git a/flake.lock b/flake.lock index c89e91af53467c15c8ae069e938d0a0ac68183e2..0c3545e84fe6280b7cd9b4416dd0ead0b02e3861 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1731797254, - "narHash": "sha256-df3dJApLPhd11AlueuoN0Q4fHo/hagP75LlM5K1sz9g=", + "lastModified": 1735563628, + "narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59", + "rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798", "type": "github" }, "original": { diff --git a/source/go.mod b/source/go.mod index 481528c8a7a6ce5a0dff616a83f8bc8b72d904a6..d35e23f932852777a0937df1a7fd539124f1f409 100644 --- a/source/go.mod +++ b/source/go.mod @@ -5,22 +5,22 @@ go 1.22.0 toolchain go1.22.4 require ( - github.com/andybalholm/cascadia v1.3.2 + github.com/andybalholm/cascadia v1.3.3 github.com/charmbracelet/log v0.4.0 - github.com/evanw/esbuild v0.24.0 - github.com/tdewolff/parse/v2 v2.7.19 + github.com/evanw/esbuild v0.24.2 + github.com/tdewolff/parse/v2 v2.7.20 gitlab.schukai.com/oss/libraries/go/application/xflags.git v1.16.5 gitlab.schukai.com/oss/libraries/go/markup/html.git v0.4.7 gitlab.schukai.com/oss/libraries/go/utilities/pathfinder.git v0.9.5 // indirect - golang.org/x/crypto v0.29.0 - golang.org/x/net v0.31.0 + golang.org/x/crypto v0.32.0 + golang.org/x/net v0.34.0 gopkg.in/yaml.v3 v3.0.1 ) require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/charmbracelet/lipgloss v1.0.0 // indirect - github.com/charmbracelet/x/ansi v0.4.5 // indirect + github.com/charmbracelet/x/ansi v0.8.0 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/kr/pretty v0.3.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect @@ -30,7 +30,7 @@ require ( github.com/rivo/uniseg v0.4.7 // indirect github.com/volker-schukai/tokenizer v1.0.0 // indirect gitlab.schukai.com/oss/libraries/go/utilities/data.git v0.2.2 // indirect - golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect - golang.org/x/sys v0.27.0 // indirect + golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect + golang.org/x/sys v0.30.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect ) diff --git a/source/go.sum b/source/go.sum index 579d28e4ad171da214d7f7202505c4d7028c7d40..9efa5ccee1d80c04bbf196f0efcb590be971bc27 100644 --- a/source/go.sum +++ b/source/go.sum @@ -1,5 +1,7 @@ github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= +github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= +github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg= @@ -8,14 +10,19 @@ github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8 github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM= github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSexTdRM= github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= +github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/evanw/esbuild v0.24.0 h1:GZ78naTLp7FKr+K7eNuM/SLs5maeiHYRPsTg6kmdsSE= github.com/evanw/esbuild v0.24.0/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= +github.com/evanw/esbuild v0.24.2 h1:PQExybVBrjHjN6/JJiShRGIXh1hWVm6NepVnhZhrt0A= +github.com/evanw/esbuild v0.24.2/go.mod h1:D2vIQZqV/vIf/VRHtViaUtViZmG7o+kKmlBfVQuRi48= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -47,6 +54,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tdewolff/parse/v2 v2.7.19 h1:7Ljh26yj+gdLFEq/7q9LT4SYyKtwQX4ocNrj45UCePg= github.com/tdewolff/parse/v2 v2.7.19/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA= +github.com/tdewolff/parse/v2 v2.7.20 h1:Y33JmRLjyGhX5JRvYh+CO6Sk6pGMw3iO5eKGhUhx8JE= +github.com/tdewolff/parse/v2 v2.7.20/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA= github.com/tdewolff/test v1.0.11-0.20231101010635-f1265d231d52 h1:gAQliwn+zJrkjAHVcBEYW/RFvd2St4yYimisvozAYlA= github.com/tdewolff/test v1.0.11-0.20231101010635-f1265d231d52/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= github.com/volker-schukai/tokenizer v1.0.0 h1:wF4haFoCodq7lgAk8c+th/DZmpFpL2WVD8wDzAGU1mA= @@ -64,22 +73,44 @@ gitlab.schukai.com/oss/libraries/go/utilities/pathfinder.git v0.9.5 h1:PiDmw3O3U gitlab.schukai.com/oss/libraries/go/utilities/pathfinder.git v0.9.5/go.mod h1:HwXjaFUAxLv+qTN63xrPBO5DEVGuZNF859t29bhTsFQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= +golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo= golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak= +golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c h1:KL/ZBHXgKGVmuZBZ01Lt57yE5ws8ZPSkkihmEyq7FXc= +golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= 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/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= +golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= +golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= 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/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -89,21 +120,40 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= +golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= 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.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= 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/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/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= diff --git a/source/html/generate.go b/source/html/generate.go index 566f1da5aa9a4fbf01982d123909e21011e9201e..032ac379fd911017c875f78316884fe67da0bd1a 100644 --- a/source/html/generate.go +++ b/source/html/generate.go @@ -110,6 +110,15 @@ func Generate(data *types.PageData, name string) (string, error) { } + dataset["env"] = make(map[any]any, 0) + envVars := os.Environ() + for _, env := range envVars { + pair := strings.SplitN(env, "=", 2) + if len(pair) == 2 { + dataset["env"].(map[any]any)[pair[0]] = pair[1] + } + } + e := engine.New(dataset) template, err := os.ReadFile(name) diff --git a/source/javascript/generate.go b/source/javascript/generate.go index 55e1ea1567e2d07257f1a09dbee38d34bae8aedd..8fd1089d15285458c7165d8237de20ac2c5ee9a2 100644 --- a/source/javascript/generate.go +++ b/source/javascript/generate.go @@ -85,21 +85,6 @@ func ParseHTMLFile(p string, development bool) error { func runESBuild(source, dist, scriptDist, styleDist string, development bool, target string) { - // get temporary directory - //tempDir, err := os.MkdirTemp("", "build-bob") - //if err != nil { - // fmt.Println("Fehler beim Erstellen des temporären Verzeichnisses:", err) - // return - //} - // - //defer func() { - // err := os.RemoveAll(tempDir) - // if err != nil { - // fmt.Println("Fehler beim Löschen des temporären Verzeichnisses:", err) - // } - // - //}() - var treeShaking = api.TreeShakingTrue if development { treeShaking = api.TreeShakingFalse diff --git a/source/vendor/github.com/charmbracelet/x/ansi/background.go b/source/vendor/github.com/charmbracelet/x/ansi/background.go index 6c66e629f75bfc4ad5d9ccb241d1b503e1642df2..2383cf09f63a57e0e66771d13d5b1e8e735bed1e 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/background.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/background.go @@ -1,9 +1,73 @@ package ansi import ( + "fmt" "image/color" ) +// Colorizer is a [color.Color] interface that can be formatted as a string. +type Colorizer interface { + color.Color + fmt.Stringer +} + +// HexColorizer is a [color.Color] that can be formatted as a hex string. +type HexColorizer struct{ color.Color } + +var _ Colorizer = HexColorizer{} + +// String returns the color as a hex string. If the color is nil, an empty +// string is returned. +func (h HexColorizer) String() string { + if h.Color == nil { + return "" + } + r, g, b, _ := h.RGBA() + // Get the lower 8 bits + r &= 0xff + g &= 0xff + b &= 0xff + return fmt.Sprintf("#%02x%02x%02x", uint8(r), uint8(g), uint8(b)) //nolint:gosec +} + +// XRGBColorizer is a [color.Color] that can be formatted as an XParseColor +// rgb: string. +// +// See: https://linux.die.net/man/3/xparsecolor +type XRGBColorizer struct{ color.Color } + +var _ Colorizer = XRGBColorizer{} + +// String returns the color as an XParseColor rgb: string. If the color is nil, +// an empty string is returned. +func (x XRGBColorizer) String() string { + if x.Color == nil { + return "" + } + r, g, b, _ := x.RGBA() + // Get the lower 8 bits + return fmt.Sprintf("rgb:%04x/%04x/%04x", r, g, b) +} + +// XRGBAColorizer is a [color.Color] that can be formatted as an XParseColor +// rgba: string. +// +// See: https://linux.die.net/man/3/xparsecolor +type XRGBAColorizer struct{ color.Color } + +var _ Colorizer = XRGBAColorizer{} + +// String returns the color as an XParseColor rgba: string. If the color is nil, +// an empty string is returned. +func (x XRGBAColorizer) String() string { + if x.Color == nil { + return "" + } + r, g, b, a := x.RGBA() + // Get the lower 8 bits + return fmt.Sprintf("rgba:%04x/%04x/%04x/%04x", r, g, b, a) +} + // SetForegroundColor returns a sequence that sets the default terminal // foreground color. // @@ -14,7 +78,16 @@ import ( // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands func SetForegroundColor(c color.Color) string { - return "\x1b]10;" + colorToHexString(c) + "\x07" + var s string + switch c := c.(type) { + case Colorizer: + s = c.String() + case fmt.Stringer: + s = c.String() + default: + s = HexColorizer{c}.String() + } + return "\x1b]10;" + s + "\x07" } // RequestForegroundColor is a sequence that requests the current default @@ -39,7 +112,16 @@ const ResetForegroundColor = "\x1b]110\x07" // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands func SetBackgroundColor(c color.Color) string { - return "\x1b]11;" + colorToHexString(c) + "\x07" + var s string + switch c := c.(type) { + case Colorizer: + s = c.String() + case fmt.Stringer: + s = c.String() + default: + s = HexColorizer{c}.String() + } + return "\x1b]11;" + s + "\x07" } // RequestBackgroundColor is a sequence that requests the current default @@ -63,7 +145,16 @@ const ResetBackgroundColor = "\x1b]111\x07" // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands func SetCursorColor(c color.Color) string { - return "\x1b]12;" + colorToHexString(c) + "\x07" + var s string + switch c := c.(type) { + case Colorizer: + s = c.String() + case fmt.Stringer: + s = c.String() + default: + s = HexColorizer{c}.String() + } + return "\x1b]12;" + s + "\x07" } // RequestCursorColor is a sequence that requests the current terminal cursor diff --git a/source/vendor/github.com/charmbracelet/x/ansi/c0.go b/source/vendor/github.com/charmbracelet/x/ansi/c0.go index 13e3c6c310aefa84c250bbfbe0a3c76e6abe1212..28ff7c2a3aa192a8a46b9b4455465f9d248a76fa 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/c0.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/c0.go @@ -69,4 +69,11 @@ const ( RS = 0x1E // US is the unit separator character (Caret: ^_). US = 0x1F + + // LS0 is the locking shift 0 character. + // This is an alias for [SI]. + LS0 = SI + // LS1 is the locking shift 1 character. + // This is an alias for [SO]. + LS1 = SO ) diff --git a/source/vendor/github.com/charmbracelet/x/ansi/charset.go b/source/vendor/github.com/charmbracelet/x/ansi/charset.go new file mode 100644 index 0000000000000000000000000000000000000000..50fff51fcd836cf1debec0cf526fc882659b4d82 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/charset.go @@ -0,0 +1,55 @@ +package ansi + +// SelectCharacterSet sets the G-set character designator to the specified +// character set. +// +// ESC Ps Pd +// +// Where Ps is the G-set character designator, and Pd is the identifier. +// For 94-character sets, the designator can be one of: +// - ( G0 +// - ) G1 +// - * G2 +// - + G3 +// +// For 96-character sets, the designator can be one of: +// - - G1 +// - . G2 +// - / G3 +// +// Some common 94-character sets are: +// - 0 DEC Special Drawing Set +// - A United Kingdom (UK) +// - B United States (USASCII) +// +// Examples: +// +// ESC ( B Select character set G0 = United States (USASCII) +// ESC ( 0 Select character set G0 = Special Character and Line Drawing Set +// ESC ) 0 Select character set G1 = Special Character and Line Drawing Set +// ESC * A Select character set G2 = United Kingdom (UK) +// +// See: https://vt100.net/docs/vt510-rm/SCS.html +func SelectCharacterSet(gset byte, charset byte) string { + return "\x1b" + string(gset) + string(charset) +} + +// SCS is an alias for SelectCharacterSet. +func SCS(gset byte, charset byte) string { + return SelectCharacterSet(gset, charset) +} + +// Locking Shift 1 Right (LS1R) shifts G1 into GR character set. +const LS1R = "\x1b~" + +// Locking Shift 2 (LS2) shifts G2 into GL character set. +const LS2 = "\x1bn" + +// Locking Shift 2 Right (LS2R) shifts G2 into GR character set. +const LS2R = "\x1b}" + +// Locking Shift 3 (LS3) shifts G3 into GL character set. +const LS3 = "\x1bo" + +// Locking Shift 3 Right (LS3R) shifts G3 into GR character set. +const LS3R = "\x1b|" diff --git a/source/vendor/github.com/charmbracelet/x/ansi/color.go b/source/vendor/github.com/charmbracelet/x/ansi/color.go index 2ff78bd7f6a64b92ec780615f7485ac5c7876232..77f8a08d1f73db6fd0f6bec57a362654344fbdfc 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/color.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/color.go @@ -178,7 +178,7 @@ func ansiToRGB(ansi uint32) (uint32, uint32, uint32) { // // r, g, b := hexToRGB(0x0000FF) func hexToRGB(hex uint32) (uint32, uint32, uint32) { - return hex >> 16, hex >> 8 & 0xff, hex & 0xff + return hex >> 16 & 0xff, hex >> 8 & 0xff, hex & 0xff } // toRGBA converts an RGB 8-bit color values to 32-bit color values suitable diff --git a/source/vendor/github.com/charmbracelet/x/ansi/csi.go b/source/vendor/github.com/charmbracelet/x/ansi/csi.go deleted file mode 100644 index b7e5bd2dace6f633e36a75c6176df5b0583cf323..0000000000000000000000000000000000000000 --- a/source/vendor/github.com/charmbracelet/x/ansi/csi.go +++ /dev/null @@ -1,141 +0,0 @@ -package ansi - -import ( - "bytes" - "strconv" - - "github.com/charmbracelet/x/ansi/parser" -) - -// CsiSequence represents a control sequence introducer (CSI) sequence. -// -// The sequence starts with a CSI sequence, CSI (0x9B) in a 8-bit environment -// or ESC [ (0x1B 0x5B) in a 7-bit environment, followed by any number of -// parameters in the range of 0x30-0x3F, then by any number of intermediate -// byte in the range of 0x20-0x2F, then finally with a single final byte in the -// range of 0x20-0x7E. -// -// CSI P..P I..I F -// -// See ECMA-48 § 5.4. -type CsiSequence struct { - // Params contains the raw parameters of the sequence. - // This is a slice of integers, where each integer is a 32-bit integer - // containing the parameter value in the lower 31 bits and a flag in the - // most significant bit indicating whether there are more sub-parameters. - Params []int - - // Cmd contains the raw command of the sequence. - // The command is a 32-bit integer containing the CSI command byte in the - // lower 8 bits, the private marker in the next 8 bits, and the intermediate - // byte in the next 8 bits. - // - // CSI ? u - // - // Is represented as: - // - // 'u' | '?' << 8 - Cmd int -} - -var _ Sequence = CsiSequence{} - -// Marker returns the marker byte of the CSI sequence. -// This is always gonna be one of the following '<' '=' '>' '?' and in the -// range of 0x3C-0x3F. -// Zero is returned if the sequence does not have a marker. -func (s CsiSequence) Marker() int { - return parser.Marker(s.Cmd) -} - -// Intermediate returns the intermediate byte of the CSI sequence. -// An intermediate byte is in the range of 0x20-0x2F. This includes these -// characters from ' ', '!', '"', '#', '$', '%', '&', â€', '(', ')', '*', '+', -// ',', '-', '.', '/'. -// Zero is returned if the sequence does not have an intermediate byte. -func (s CsiSequence) Intermediate() int { - return parser.Intermediate(s.Cmd) -} - -// Command returns the command byte of the CSI sequence. -func (s CsiSequence) Command() int { - return parser.Command(s.Cmd) -} - -// Param returns the parameter at the given index. -// It returns -1 if the parameter does not exist. -func (s CsiSequence) Param(i int) int { - return parser.Param(s.Params, i) -} - -// HasMore returns true if the parameter has more sub-parameters. -func (s CsiSequence) HasMore(i int) bool { - return parser.HasMore(s.Params, i) -} - -// Subparams returns the sub-parameters of the given parameter. -// It returns nil if the parameter does not exist. -func (s CsiSequence) Subparams(i int) []int { - return parser.Subparams(s.Params, i) -} - -// Len returns the number of parameters in the sequence. -// This will return the number of parameters in the sequence, excluding any -// sub-parameters. -func (s CsiSequence) Len() int { - return parser.Len(s.Params) -} - -// Range iterates over the parameters of the sequence and calls the given -// function for each parameter. -// The function should return false to stop the iteration. -func (s CsiSequence) Range(fn func(i int, param int, hasMore bool) bool) { - parser.Range(s.Params, fn) -} - -// Clone returns a copy of the CSI sequence. -func (s CsiSequence) Clone() Sequence { - return CsiSequence{ - Params: append([]int(nil), s.Params...), - Cmd: s.Cmd, - } -} - -// String returns a string representation of the sequence. -// The string will always be in the 7-bit format i.e (ESC [ P..P I..I F). -func (s CsiSequence) String() string { - return s.buffer().String() -} - -// buffer returns a buffer containing the sequence. -func (s CsiSequence) buffer() *bytes.Buffer { - var b bytes.Buffer - b.WriteString("\x1b[") - if m := s.Marker(); m != 0 { - b.WriteByte(byte(m)) - } - s.Range(func(i, param int, hasMore bool) bool { - if param >= 0 { - b.WriteString(strconv.Itoa(param)) - } - if i < len(s.Params)-1 { - if hasMore { - b.WriteByte(':') - } else { - b.WriteByte(';') - } - } - return true - }) - if i := s.Intermediate(); i != 0 { - b.WriteByte(byte(i)) - } - b.WriteByte(byte(s.Command())) - return &b -} - -// Bytes returns the byte representation of the sequence. -// The bytes will always be in the 7-bit format i.e (ESC [ P..P I..I F). -func (s CsiSequence) Bytes() []byte { - return s.buffer().Bytes() -} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/ctrl.go b/source/vendor/github.com/charmbracelet/x/ansi/ctrl.go index 21beb9cd13c38c73d2835702191cf7ff039f8c71..8ca744cf2d7d19422f8c84dbe4c1e40d83abc947 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/ctrl.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/ctrl.go @@ -1,12 +1,62 @@ package ansi +import ( + "strconv" + "strings" +) + +// RequestNameVersion (XTVERSION) is a control sequence that requests the +// terminal's name and version. It responds with a DSR sequence identifying the +// terminal. +// +// CSI > 0 q +// DCS > | text ST +// +// See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-PC-Style-Function-Keys +const ( + RequestNameVersion = "\x1b[>q" + XTVERSION = RequestNameVersion +) + // RequestXTVersion is a control sequence that requests the terminal's XTVERSION. It responds with a DSR sequence identifying the version. // // CSI > Ps q // DCS > | text ST // // See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-PC-Style-Function-Keys -const RequestXTVersion = "\x1b[>0q" +// +// Deprecated: use [RequestNameVersion] instead. +const RequestXTVersion = RequestNameVersion + +// PrimaryDeviceAttributes (DA1) is a control sequence that reports the +// terminal's primary device attributes. +// +// CSI c +// CSI 0 c +// CSI ? Ps ; ... c +// +// If no attributes are given, or if the attribute is 0, this function returns +// the request sequence. Otherwise, it returns the response sequence. +// +// See https://vt100.net/docs/vt510-rm/DA1.html +func PrimaryDeviceAttributes(attrs ...int) string { + if len(attrs) == 0 { + return RequestPrimaryDeviceAttributes + } else if len(attrs) == 1 && attrs[0] == 0 { + return "\x1b[0c" + } + + as := make([]string, len(attrs)) + for i, a := range attrs { + as[i] = strconv.Itoa(a) + } + return "\x1b[?" + strings.Join(as, ";") + "c" +} + +// DA1 is an alias for [PrimaryDeviceAttributes]. +func DA1(attrs ...int) string { + return PrimaryDeviceAttributes(attrs...) +} // RequestPrimaryDeviceAttributes is a control sequence that requests the // terminal's primary device attributes (DA1). @@ -15,3 +65,73 @@ const RequestXTVersion = "\x1b[>0q" // // See https://vt100.net/docs/vt510-rm/DA1.html const RequestPrimaryDeviceAttributes = "\x1b[c" + +// SecondaryDeviceAttributes (DA2) is a control sequence that reports the +// terminal's secondary device attributes. +// +// CSI > c +// CSI > 0 c +// CSI > Ps ; ... c +// +// See https://vt100.net/docs/vt510-rm/DA2.html +func SecondaryDeviceAttributes(attrs ...int) string { + if len(attrs) == 0 { + return RequestSecondaryDeviceAttributes + } + + as := make([]string, len(attrs)) + for i, a := range attrs { + as[i] = strconv.Itoa(a) + } + return "\x1b[>" + strings.Join(as, ";") + "c" +} + +// DA2 is an alias for [SecondaryDeviceAttributes]. +func DA2(attrs ...int) string { + return SecondaryDeviceAttributes(attrs...) +} + +// RequestSecondaryDeviceAttributes is a control sequence that requests the +// terminal's secondary device attributes (DA2). +// +// CSI > c +// +// See https://vt100.net/docs/vt510-rm/DA2.html +const RequestSecondaryDeviceAttributes = "\x1b[>c" + +// TertiaryDeviceAttributes (DA3) is a control sequence that reports the +// terminal's tertiary device attributes. +// +// CSI = c +// CSI = 0 c +// DCS ! | Text ST +// +// Where Text is the unit ID for the terminal. +// +// If no unit ID is given, or if the unit ID is 0, this function returns the +// request sequence. Otherwise, it returns the response sequence. +// +// See https://vt100.net/docs/vt510-rm/DA3.html +func TertiaryDeviceAttributes(unitID string) string { + switch unitID { + case "": + return RequestTertiaryDeviceAttributes + case "0": + return "\x1b[=0c" + } + + return "\x1bP!|" + unitID + "\x1b\\" +} + +// DA3 is an alias for [TertiaryDeviceAttributes]. +func DA3(unitID string) string { + return TertiaryDeviceAttributes(unitID) +} + +// RequestTertiaryDeviceAttributes is a control sequence that requests the +// terminal's tertiary device attributes (DA3). +// +// CSI = c +// +// See https://vt100.net/docs/vt510-rm/DA3.html +const RequestTertiaryDeviceAttributes = "\x1b[=c" diff --git a/source/vendor/github.com/charmbracelet/x/ansi/cursor.go b/source/vendor/github.com/charmbracelet/x/ansi/cursor.go index da144b926923d4f70d840c57d0a0b699bb0e29d7..0c364d608a36bf63b2ed2c47e46a21940d610dec 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/cursor.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/cursor.go @@ -8,7 +8,10 @@ import "strconv" // ESC 7 // // See: https://vt100.net/docs/vt510-rm/DECSC.html -const SaveCursor = "\x1b7" +const ( + SaveCursor = "\x1b7" + DECSC = SaveCursor +) // RestoreCursor (DECRC) is an escape sequence that restores the cursor // position. @@ -16,10 +19,13 @@ const SaveCursor = "\x1b7" // ESC 8 // // See: https://vt100.net/docs/vt510-rm/DECRC.html -const RestoreCursor = "\x1b8" +const ( + RestoreCursor = "\x1b8" + DECRC = RestoreCursor +) -// RequestCursorPosition (CPR) is an escape sequence that requests the current -// cursor position. +// RequestCursorPosition is an escape sequence that requests the current cursor +// position. // // CSI 6 n // @@ -30,6 +36,8 @@ const RestoreCursor = "\x1b8" // // Where Pl is the line number and Pc is the column number. // See: https://vt100.net/docs/vt510-rm/CPR.html +// +// Deprecated: use [RequestCursorPositionReport] instead. const RequestCursorPosition = "\x1b[6n" // RequestExtendedCursorPosition (DECXCPR) is a sequence for requesting the @@ -45,6 +53,8 @@ const RequestCursorPosition = "\x1b[6n" // Where Pl is the line number, Pc is the column number, and Pp is the page // number. // See: https://vt100.net/docs/vt510-rm/DECXCPR.html +// +// Deprecated: use [RequestExtendedCursorPositionReport] instead. const RequestExtendedCursorPosition = "\x1b[?6n" // CursorUp (CUU) returns a sequence for moving the cursor up n cells. @@ -60,9 +70,19 @@ func CursorUp(n int) string { return "\x1b[" + s + "A" } +// CUU is an alias for [CursorUp]. +func CUU(n int) string { + return CursorUp(n) +} + +// CUU1 is a sequence for moving the cursor up one cell. +const CUU1 = "\x1b[A" + // CursorUp1 is a sequence for moving the cursor up one cell. // // This is equivalent to CursorUp(1). +// +// Deprecated: use [CUU1] instead. const CursorUp1 = "\x1b[A" // CursorDown (CUD) returns a sequence for moving the cursor down n cells. @@ -78,17 +98,27 @@ func CursorDown(n int) string { return "\x1b[" + s + "B" } +// CUD is an alias for [CursorDown]. +func CUD(n int) string { + return CursorDown(n) +} + +// CUD1 is a sequence for moving the cursor down one cell. +const CUD1 = "\x1b[B" + // CursorDown1 is a sequence for moving the cursor down one cell. // // This is equivalent to CursorDown(1). +// +// Deprecated: use [CUD1] instead. const CursorDown1 = "\x1b[B" -// CursorRight (CUF) returns a sequence for moving the cursor right n cells. +// CursorForward (CUF) returns a sequence for moving the cursor right n cells. // -// CSI n C +// # CSI n C // // See: https://vt100.net/docs/vt510-rm/CUF.html -func CursorRight(n int) string { +func CursorForward(n int) string { var s string if n > 1 { s = strconv.Itoa(n) @@ -96,17 +126,38 @@ func CursorRight(n int) string { return "\x1b[" + s + "C" } +// CUF is an alias for [CursorForward]. +func CUF(n int) string { + return CursorForward(n) +} + +// CUF1 is a sequence for moving the cursor right one cell. +const CUF1 = "\x1b[C" + +// CursorRight (CUF) returns a sequence for moving the cursor right n cells. +// +// CSI n C +// +// See: https://vt100.net/docs/vt510-rm/CUF.html +// +// Deprecated: use [CursorForward] instead. +func CursorRight(n int) string { + return CursorForward(n) +} + // CursorRight1 is a sequence for moving the cursor right one cell. // // This is equivalent to CursorRight(1). -const CursorRight1 = "\x1b[C" +// +// Deprecated: use [CUF1] instead. +const CursorRight1 = CUF1 -// CursorLeft (CUB) returns a sequence for moving the cursor left n cells. +// CursorBackward (CUB) returns a sequence for moving the cursor left n cells. // -// CSI n D +// # CSI n D // // See: https://vt100.net/docs/vt510-rm/CUB.html -func CursorLeft(n int) string { +func CursorBackward(n int) string { var s string if n > 1 { s = strconv.Itoa(n) @@ -114,10 +165,31 @@ func CursorLeft(n int) string { return "\x1b[" + s + "D" } +// CUB is an alias for [CursorBackward]. +func CUB(n int) string { + return CursorBackward(n) +} + +// CUB1 is a sequence for moving the cursor left one cell. +const CUB1 = "\x1b[D" + +// CursorLeft (CUB) returns a sequence for moving the cursor left n cells. +// +// CSI n D +// +// See: https://vt100.net/docs/vt510-rm/CUB.html +// +// Deprecated: use [CursorBackward] instead. +func CursorLeft(n int) string { + return CursorBackward(n) +} + // CursorLeft1 is a sequence for moving the cursor left one cell. // // This is equivalent to CursorLeft(1). -const CursorLeft1 = "\x1b[D" +// +// Deprecated: use [CUB1] instead. +const CursorLeft1 = CUB1 // CursorNextLine (CNL) returns a sequence for moving the cursor to the // beginning of the next line n times. @@ -133,6 +205,11 @@ func CursorNextLine(n int) string { return "\x1b[" + s + "E" } +// CNL is an alias for [CursorNextLine]. +func CNL(n int) string { + return CursorNextLine(n) +} + // CursorPreviousLine (CPL) returns a sequence for moving the cursor to the // beginning of the previous line n times. // @@ -147,25 +224,92 @@ func CursorPreviousLine(n int) string { return "\x1b[" + s + "F" } +// CPL is an alias for [CursorPreviousLine]. +func CPL(n int) string { + return CursorPreviousLine(n) +} + +// CursorHorizontalAbsolute (CHA) returns a sequence for moving the cursor to +// the given column. +// +// Default is 1. +// +// CSI n G +// +// See: https://vt100.net/docs/vt510-rm/CHA.html +func CursorHorizontalAbsolute(col int) string { + var s string + if col > 0 { + s = strconv.Itoa(col) + } + return "\x1b[" + s + "G" +} + +// CHA is an alias for [CursorHorizontalAbsolute]. +func CHA(col int) string { + return CursorHorizontalAbsolute(col) +} + +// CursorPosition (CUP) returns a sequence for setting the cursor to the +// given row and column. +// +// Default is 1,1. +// +// CSI n ; m H +// +// See: https://vt100.net/docs/vt510-rm/CUP.html +func CursorPosition(col, row int) string { + if row <= 0 && col <= 0 { + return HomeCursorPosition + } + + var r, c string + if row > 0 { + r = strconv.Itoa(row) + } + if col > 0 { + c = strconv.Itoa(col) + } + return "\x1b[" + r + ";" + c + "H" +} + +// CUP is an alias for [CursorPosition]. +func CUP(col, row int) string { + return CursorPosition(col, row) +} + +// CursorHomePosition is a sequence for moving the cursor to the upper left +// corner of the scrolling region. This is equivalent to `CursorPosition(1, 1)`. +const CursorHomePosition = "\x1b[H" + // SetCursorPosition (CUP) returns a sequence for setting the cursor to the // given row and column. // // CSI n ; m H // // See: https://vt100.net/docs/vt510-rm/CUP.html +// +// Deprecated: use [CursorPosition] instead. func SetCursorPosition(col, row int) string { - if row < 0 { - row = 0 + if row <= 0 && col <= 0 { + return HomeCursorPosition } - if col < 0 { - col = 0 + + var r, c string + if row > 0 { + r = strconv.Itoa(row) } - return "\x1b[" + strconv.Itoa(row) + ";" + strconv.Itoa(col) + "H" + if col > 0 { + c = strconv.Itoa(col) + } + return "\x1b[" + r + ";" + c + "H" } // HomeCursorPosition is a sequence for moving the cursor to the upper left // corner of the scrolling region. This is equivalent to `SetCursorPosition(1, 1)`. -const HomeCursorPosition = "\x1b[H" +// +// Deprecated: use [CursorHomePosition] instead. +const HomeCursorPosition = CursorHomePosition // MoveCursor (CUP) returns a sequence for setting the cursor to the // given row and column. @@ -174,7 +318,7 @@ const HomeCursorPosition = "\x1b[H" // // See: https://vt100.net/docs/vt510-rm/CUP.html // -// Deprecated: use SetCursorPosition instead. +// Deprecated: use [CursorPosition] instead. func MoveCursor(col, row int) string { return SetCursorPosition(col, row) } @@ -182,15 +326,165 @@ func MoveCursor(col, row int) string { // CursorOrigin is a sequence for moving the cursor to the upper left corner of // the display. This is equivalent to `SetCursorPosition(1, 1)`. // -// Deprecated: use [HomeCursorPosition] instead. +// Deprecated: use [CursorHomePosition] instead. const CursorOrigin = "\x1b[1;1H" // MoveCursorOrigin is a sequence for moving the cursor to the upper left // corner of the display. This is equivalent to `SetCursorPosition(1, 1)`. // -// Deprecated: use CursorOrigin instead. +// Deprecated: use [CursorHomePosition] instead. const MoveCursorOrigin = CursorOrigin +// CursorHorizontalForwardTab (CHT) returns a sequence for moving the cursor to +// the next tab stop n times. +// +// Default is 1. +// +// CSI n I +// +// See: https://vt100.net/docs/vt510-rm/CHT.html +func CursorHorizontalForwardTab(n int) string { + var s string + if n > 1 { + s = strconv.Itoa(n) + } + return "\x1b[" + s + "I" +} + +// CHT is an alias for [CursorHorizontalForwardTab]. +func CHT(n int) string { + return CursorHorizontalForwardTab(n) +} + +// EraseCharacter (ECH) returns a sequence for erasing n characters and moving +// the cursor to the right. This doesn't affect other cell attributes. +// +// Default is 1. +// +// CSI n X +// +// See: https://vt100.net/docs/vt510-rm/ECH.html +func EraseCharacter(n int) string { + var s string + if n > 1 { + s = strconv.Itoa(n) + } + return "\x1b[" + s + "X" +} + +// ECH is an alias for [EraseCharacter]. +func ECH(n int) string { + return EraseCharacter(n) +} + +// CursorBackwardTab (CBT) returns a sequence for moving the cursor to the +// previous tab stop n times. +// +// Default is 1. +// +// CSI n Z +// +// See: https://vt100.net/docs/vt510-rm/CBT.html +func CursorBackwardTab(n int) string { + var s string + if n > 1 { + s = strconv.Itoa(n) + } + return "\x1b[" + s + "Z" +} + +// CBT is an alias for [CursorBackwardTab]. +func CBT(n int) string { + return CursorBackwardTab(n) +} + +// VerticalPositionAbsolute (VPA) returns a sequence for moving the cursor to +// the given row. +// +// Default is 1. +// +// CSI n d +// +// See: https://vt100.net/docs/vt510-rm/VPA.html +func VerticalPositionAbsolute(row int) string { + var s string + if row > 0 { + s = strconv.Itoa(row) + } + return "\x1b[" + s + "d" +} + +// VPA is an alias for [VerticalPositionAbsolute]. +func VPA(row int) string { + return VerticalPositionAbsolute(row) +} + +// VerticalPositionRelative (VPR) returns a sequence for moving the cursor down +// n rows relative to the current position. +// +// Default is 1. +// +// CSI n e +// +// See: https://vt100.net/docs/vt510-rm/VPR.html +func VerticalPositionRelative(n int) string { + var s string + if n > 1 { + s = strconv.Itoa(n) + } + return "\x1b[" + s + "e" +} + +// VPR is an alias for [VerticalPositionRelative]. +func VPR(n int) string { + return VerticalPositionRelative(n) +} + +// HorizontalVerticalPosition (HVP) returns a sequence for moving the cursor to +// the given row and column. +// +// Default is 1,1. +// +// CSI n ; m f +// +// This has the same effect as [CursorPosition]. +// +// See: https://vt100.net/docs/vt510-rm/HVP.html +func HorizontalVerticalPosition(col, row int) string { + var r, c string + if row > 0 { + r = strconv.Itoa(row) + } + if col > 0 { + c = strconv.Itoa(col) + } + return "\x1b[" + r + ";" + c + "f" +} + +// HVP is an alias for [HorizontalVerticalPosition]. +func HVP(col, row int) string { + return HorizontalVerticalPosition(col, row) +} + +// HorizontalVerticalHomePosition is a sequence for moving the cursor to the +// upper left corner of the scrolling region. This is equivalent to +// `HorizontalVerticalPosition(1, 1)`. +const HorizontalVerticalHomePosition = "\x1b[f" + +// SaveCurrentCursorPosition (SCOSC) is a sequence for saving the current cursor +// position for SCO console mode. +// +// CSI s +// +// This acts like [DECSC], except the page number where the cursor is located +// is not saved. +// +// See: https://vt100.net/docs/vt510-rm/SCOSC.html +const ( + SaveCurrentCursorPosition = "\x1b[s" + SCOSC = SaveCurrentCursorPosition +) + // SaveCursorPosition (SCP or SCOSC) is a sequence for saving the cursor // position. // @@ -200,8 +494,24 @@ const MoveCursorOrigin = CursorOrigin // not saved. // // See: https://vt100.net/docs/vt510-rm/SCOSC.html +// +// Deprecated: use [SaveCurrentCursorPosition] instead. const SaveCursorPosition = "\x1b[s" +// RestoreCurrentCursorPosition (SCORC) is a sequence for restoring the current +// cursor position for SCO console mode. +// +// CSI u +// +// This acts like [DECRC], except the page number where the cursor was saved is +// not restored. +// +// See: https://vt100.net/docs/vt510-rm/SCORC.html +const ( + RestoreCurrentCursorPosition = "\x1b[u" + SCORC = RestoreCurrentCursorPosition +) + // RestoreCursorPosition (RCP or SCORC) is a sequence for restoring the cursor // position. // @@ -211,10 +521,14 @@ const SaveCursorPosition = "\x1b[s" // cursor was saved. // // See: https://vt100.net/docs/vt510-rm/SCORC.html +// +// Deprecated: use [RestoreCurrentCursorPosition] instead. const RestoreCursorPosition = "\x1b[u" // SetCursorStyle (DECSCUSR) returns a sequence for changing the cursor style. // +// Default is 1. +// // CSI Ps SP q // // Where Ps is the cursor style: @@ -236,6 +550,11 @@ func SetCursorStyle(style int) string { return "\x1b[" + strconv.Itoa(style) + " q" } +// DECSCUSR is an alias for [SetCursorStyle]. +func DECSCUSR(style int) string { + return SetCursorStyle(style) +} + // SetPointerShape returns a sequence for changing the mouse pointer cursor // shape. Use "default" for the default pointer shape. // @@ -257,3 +576,58 @@ func SetCursorStyle(style int) string { func SetPointerShape(shape string) string { return "\x1b]22;" + shape + "\x07" } + +// ReverseIndex (RI) is an escape sequence for moving the cursor up one line in +// the same column. If the cursor is at the top margin, the screen scrolls +// down. +// +// This has the same effect as [RI]. +const ReverseIndex = "\x1bM" + +// HorizontalPositionAbsolute (HPA) returns a sequence for moving the cursor to +// the given column. This has the same effect as [CUP]. +// +// Default is 1. +// +// CSI n ` +// +// See: https://vt100.net/docs/vt510-rm/HPA.html +func HorizontalPositionAbsolute(col int) string { + var s string + if col > 0 { + s = strconv.Itoa(col) + } + return "\x1b[" + s + "`" +} + +// HPA is an alias for [HorizontalPositionAbsolute]. +func HPA(col int) string { + return HorizontalPositionAbsolute(col) +} + +// HorizontalPositionRelative (HPR) returns a sequence for moving the cursor +// right n columns relative to the current position. This has the same effect +// as [CUP]. +// +// Default is 1. +// +// CSI n a +// +// See: https://vt100.net/docs/vt510-rm/HPR.html +func HorizontalPositionRelative(n int) string { + var s string + if n > 0 { + s = strconv.Itoa(n) + } + return "\x1b[" + s + "a" +} + +// HPR is an alias for [HorizontalPositionRelative]. +func HPR(n int) string { + return HorizontalPositionRelative(n) +} + +// Index (IND) is an escape sequence for moving the cursor down one line in the +// same column. If the cursor is at the bottom margin, the screen scrolls up. +// This has the same effect as [IND]. +const Index = "\x1bD" diff --git a/source/vendor/github.com/charmbracelet/x/ansi/cwd.go b/source/vendor/github.com/charmbracelet/x/ansi/cwd.go new file mode 100644 index 0000000000000000000000000000000000000000..b03ac1bb99479763117ecb07833b5cd84bd7fa55 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/cwd.go @@ -0,0 +1,26 @@ +package ansi + +import ( + "net/url" + "path" +) + +// NotifyWorkingDirectory returns a sequence that notifies the terminal +// of the current working directory. +// +// OSC 7 ; Pt BEL +// +// Where Pt is a URL in the format "file://[host]/[path]". +// Set host to "localhost" if this is a path on the local computer. +// +// See: https://wezfurlong.org/wezterm/shell-integration.html#osc-7-escape-sequence-to-set-the-working-directory +// See: https://iterm2.com/documentation-escape-codes.html#:~:text=RemoteHost%20and%20CurrentDir%3A-,OSC%207,-%3B%20%5BPs%5D%20ST +func NotifyWorkingDirectory(host string, paths ...string) string { + path := path.Join(paths...) + u := &url.URL{ + Scheme: "file", + Host: host, + Path: path, + } + return "\x1b]7;" + u.String() + "\x07" +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/dcs.go b/source/vendor/github.com/charmbracelet/x/ansi/dcs.go deleted file mode 100644 index 185f0b52bcac66dacda5301ec2548337ac8b70f4..0000000000000000000000000000000000000000 --- a/source/vendor/github.com/charmbracelet/x/ansi/dcs.go +++ /dev/null @@ -1,148 +0,0 @@ -package ansi - -import ( - "bytes" - "strconv" - - "github.com/charmbracelet/x/ansi/parser" -) - -// DcsSequence represents a Device Control String (DCS) escape sequence. -// -// The DCS sequence is used to send device control strings to the terminal. The -// sequence starts with the C1 control code character DCS (0x9B) or ESC P in -// 7-bit environments, followed by parameter bytes, intermediate bytes, a -// command byte, followed by data bytes, and ends with the C1 control code -// character ST (0x9C) or ESC \ in 7-bit environments. -// -// This follows the parameter string format. -// See ECMA-48 § 5.4.1 -type DcsSequence struct { - // Params contains the raw parameters of the sequence. - // This is a slice of integers, where each integer is a 32-bit integer - // containing the parameter value in the lower 31 bits and a flag in the - // most significant bit indicating whether there are more sub-parameters. - Params []int - - // Data contains the string raw data of the sequence. - // This is the data between the final byte and the escape sequence terminator. - Data []byte - - // Cmd contains the raw command of the sequence. - // The command is a 32-bit integer containing the DCS command byte in the - // lower 8 bits, the private marker in the next 8 bits, and the intermediate - // byte in the next 8 bits. - // - // DCS > 0 ; 1 $ r <data> ST - // - // Is represented as: - // - // 'r' | '>' << 8 | '$' << 16 - Cmd int -} - -var _ Sequence = DcsSequence{} - -// Marker returns the marker byte of the DCS sequence. -// This is always gonna be one of the following '<' '=' '>' '?' and in the -// range of 0x3C-0x3F. -// Zero is returned if the sequence does not have a marker. -func (s DcsSequence) Marker() int { - return parser.Marker(s.Cmd) -} - -// Intermediate returns the intermediate byte of the DCS sequence. -// An intermediate byte is in the range of 0x20-0x2F. This includes these -// characters from ' ', '!', '"', '#', '$', '%', '&', â€', '(', ')', '*', '+', -// ',', '-', '.', '/'. -// Zero is returned if the sequence does not have an intermediate byte. -func (s DcsSequence) Intermediate() int { - return parser.Intermediate(s.Cmd) -} - -// Command returns the command byte of the CSI sequence. -func (s DcsSequence) Command() int { - return parser.Command(s.Cmd) -} - -// Param returns the parameter at the given index. -// It returns -1 if the parameter does not exist. -func (s DcsSequence) Param(i int) int { - return parser.Param(s.Params, i) -} - -// HasMore returns true if the parameter has more sub-parameters. -func (s DcsSequence) HasMore(i int) bool { - return parser.HasMore(s.Params, i) -} - -// Subparams returns the sub-parameters of the given parameter. -// It returns nil if the parameter does not exist. -func (s DcsSequence) Subparams(i int) []int { - return parser.Subparams(s.Params, i) -} - -// Len returns the number of parameters in the sequence. -// This will return the number of parameters in the sequence, excluding any -// sub-parameters. -func (s DcsSequence) Len() int { - return parser.Len(s.Params) -} - -// Range iterates over the parameters of the sequence and calls the given -// function for each parameter. -// The function should return false to stop the iteration. -func (s DcsSequence) Range(fn func(i int, param int, hasMore bool) bool) { - parser.Range(s.Params, fn) -} - -// Clone returns a copy of the DCS sequence. -func (s DcsSequence) Clone() Sequence { - return DcsSequence{ - Params: append([]int(nil), s.Params...), - Data: append([]byte(nil), s.Data...), - Cmd: s.Cmd, - } -} - -// String returns a string representation of the sequence. -// The string will always be in the 7-bit format i.e (ESC P p..p i..i f <data> ESC \). -func (s DcsSequence) String() string { - return s.buffer().String() -} - -// buffer returns a buffer containing the sequence. -func (s DcsSequence) buffer() *bytes.Buffer { - var b bytes.Buffer - b.WriteString("\x1bP") - if m := s.Marker(); m != 0 { - b.WriteByte(byte(m)) - } - s.Range(func(i, param int, hasMore bool) bool { - if param >= -1 { - b.WriteString(strconv.Itoa(param)) - } - if i < len(s.Params)-1 { - if hasMore { - b.WriteByte(':') - } else { - b.WriteByte(';') - } - } - return true - }) - if i := s.Intermediate(); i != 0 { - b.WriteByte(byte(i)) - } - b.WriteByte(byte(s.Command())) - b.Write(s.Data) - b.WriteByte(ESC) - b.WriteByte('\\') - return &b -} - -// Bytes returns the byte representation of the sequence. -// The bytes will always be in the 7-bit format i.e (ESC P p..p i..i F <data> ESC \). -func (s DcsSequence) Bytes() []byte { - return s.buffer().Bytes() -} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/focus.go b/source/vendor/github.com/charmbracelet/x/ansi/focus.go new file mode 100644 index 0000000000000000000000000000000000000000..4e0207cebb5688ba965cbd272142b3ccca6ed7ff --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/focus.go @@ -0,0 +1,9 @@ +package ansi + +// Focus is an escape sequence to notify the terminal that it has focus. +// This is used with [FocusEventMode]. +const Focus = "\x1b[I" + +// Blur is an escape sequence to notify the terminal that it has lost focus. +// This is used with [FocusEventMode]. +const Blur = "\x1b[O" diff --git a/source/vendor/github.com/charmbracelet/x/ansi/graphics.go b/source/vendor/github.com/charmbracelet/x/ansi/graphics.go new file mode 100644 index 0000000000000000000000000000000000000000..604fef47cf5c63e2c63978ad12e8f2235dd73ac8 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/graphics.go @@ -0,0 +1,199 @@ +package ansi + +import ( + "bytes" + "encoding/base64" + "errors" + "fmt" + "image" + "io" + "os" + "strings" + + "github.com/charmbracelet/x/ansi/kitty" +) + +// KittyGraphics returns a sequence that encodes the given image in the Kitty +// graphics protocol. +// +// APC G [comma separated options] ; [base64 encoded payload] ST +// +// See https://sw.kovidgoyal.net/kitty/graphics-protocol/ +func KittyGraphics(payload []byte, opts ...string) string { + var buf bytes.Buffer + buf.WriteString("\x1b_G") + buf.WriteString(strings.Join(opts, ",")) + if len(payload) > 0 { + buf.WriteString(";") + buf.Write(payload) + } + buf.WriteString("\x1b\\") + return buf.String() +} + +var ( + // KittyGraphicsTempDir is the directory where temporary files are stored. + // This is used in [WriteKittyGraphics] along with [os.CreateTemp]. + KittyGraphicsTempDir = "" + + // KittyGraphicsTempPattern is the pattern used to create temporary files. + // This is used in [WriteKittyGraphics] along with [os.CreateTemp]. + // The Kitty Graphics protocol requires the file path to contain the + // substring "tty-graphics-protocol". + KittyGraphicsTempPattern = "tty-graphics-protocol-*" +) + +// WriteKittyGraphics writes an image using the Kitty Graphics protocol with +// the given options to w. It chunks the written data if o.Chunk is true. +// +// You can omit m and use nil when rendering an image from a file. In this +// case, you must provide a file path in o.File and use o.Transmission = +// [kitty.File]. You can also use o.Transmission = [kitty.TempFile] to write +// the image to a temporary file. In that case, the file path is ignored, and +// the image is written to a temporary file that is automatically deleted by +// the terminal. +// +// See https://sw.kovidgoyal.net/kitty/graphics-protocol/ +func WriteKittyGraphics(w io.Writer, m image.Image, o *kitty.Options) error { + if o == nil { + o = &kitty.Options{} + } + + if o.Transmission == 0 && len(o.File) != 0 { + o.Transmission = kitty.File + } + + var data bytes.Buffer // the data to be encoded into base64 + e := &kitty.Encoder{ + Compress: o.Compression == kitty.Zlib, + Format: o.Format, + } + + switch o.Transmission { + case kitty.Direct: + if err := e.Encode(&data, m); err != nil { + return fmt.Errorf("failed to encode direct image: %w", err) + } + + case kitty.SharedMemory: + // TODO: Implement shared memory + return fmt.Errorf("shared memory transmission is not yet implemented") + + case kitty.File: + if len(o.File) == 0 { + return kitty.ErrMissingFile + } + + f, err := os.Open(o.File) + if err != nil { + return fmt.Errorf("failed to open file: %w", err) + } + + defer f.Close() //nolint:errcheck + + stat, err := f.Stat() + if err != nil { + return fmt.Errorf("failed to get file info: %w", err) + } + + mode := stat.Mode() + if !mode.IsRegular() { + return fmt.Errorf("file is not a regular file") + } + + // Write the file path to the buffer + if _, err := data.WriteString(f.Name()); err != nil { + return fmt.Errorf("failed to write file path to buffer: %w", err) + } + + case kitty.TempFile: + f, err := os.CreateTemp(KittyGraphicsTempDir, KittyGraphicsTempPattern) + if err != nil { + return fmt.Errorf("failed to create file: %w", err) + } + + defer f.Close() //nolint:errcheck + + if err := e.Encode(f, m); err != nil { + return fmt.Errorf("failed to encode image to file: %w", err) + } + + // Write the file path to the buffer + if _, err := data.WriteString(f.Name()); err != nil { + return fmt.Errorf("failed to write file path to buffer: %w", err) + } + } + + // Encode image to base64 + var payload bytes.Buffer // the base64 encoded image to be written to w + b64 := base64.NewEncoder(base64.StdEncoding, &payload) + if _, err := data.WriteTo(b64); err != nil { + return fmt.Errorf("failed to write base64 encoded image to payload: %w", err) + } + if err := b64.Close(); err != nil { + return err + } + + // If not chunking, write all at once + if !o.Chunk { + _, err := io.WriteString(w, KittyGraphics(payload.Bytes(), o.Options()...)) + return err + } + + // Write in chunks + var ( + err error + n int + ) + chunk := make([]byte, kitty.MaxChunkSize) + isFirstChunk := true + + for { + // Stop if we read less than the chunk size [kitty.MaxChunkSize]. + n, err = io.ReadFull(&payload, chunk) + if errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, io.EOF) { + break + } + if err != nil { + return fmt.Errorf("failed to read chunk: %w", err) + } + + opts := buildChunkOptions(o, isFirstChunk, false) + if _, err := io.WriteString(w, KittyGraphics(chunk[:n], opts...)); err != nil { + return err + } + + isFirstChunk = false + } + + // Write the last chunk + opts := buildChunkOptions(o, isFirstChunk, true) + _, err = io.WriteString(w, KittyGraphics(chunk[:n], opts...)) + return err +} + +// buildChunkOptions creates the options slice for a chunk +func buildChunkOptions(o *kitty.Options, isFirstChunk, isLastChunk bool) []string { + var opts []string + if isFirstChunk { + opts = o.Options() + } else { + // These options are allowed in subsequent chunks + if o.Quite > 0 { + opts = append(opts, fmt.Sprintf("q=%d", o.Quite)) + } + if o.Action == kitty.Frame { + opts = append(opts, "a=f") + } + } + + if !isFirstChunk || !isLastChunk { + // We don't need to encode the (m=) option when we only have one chunk. + if isLastChunk { + opts = append(opts, "m=0") + } else { + opts = append(opts, "m=1") + } + } + return opts +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/iterm2.go b/source/vendor/github.com/charmbracelet/x/ansi/iterm2.go new file mode 100644 index 0000000000000000000000000000000000000000..0ecb336da1693690e34536cd4d72a685e5411d3b --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/iterm2.go @@ -0,0 +1,18 @@ +package ansi + +import "fmt" + +// ITerm2 returns a sequence that uses the iTerm2 proprietary protocol. Use the +// iterm2 package for a more convenient API. +// +// OSC 1337 ; key = value ST +// +// Example: +// +// ITerm2(iterm2.File{...}) +// +// See https://iterm2.com/documentation-escape-codes.html +// See https://iterm2.com/documentation-images.html +func ITerm2(data any) string { + return "\x1b]1337;" + fmt.Sprint(data) + "\x07" +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/keypad.go b/source/vendor/github.com/charmbracelet/x/ansi/keypad.go new file mode 100644 index 0000000000000000000000000000000000000000..9183c6a7ec4d3d2a23bd5b4078e21d86d16027b0 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/keypad.go @@ -0,0 +1,28 @@ +package ansi + +// Keypad Application Mode (DECKPAM) is a mode that determines whether the +// keypad sends application sequences or ANSI sequences. +// +// This works like enabling [DECNKM]. +// Use [NumericKeypadMode] to set the numeric keypad mode. +// +// ESC = +// +// See: https://vt100.net/docs/vt510-rm/DECKPAM.html +const ( + KeypadApplicationMode = "\x1b=" + DECKPAM = KeypadApplicationMode +) + +// Keypad Numeric Mode (DECKPNM) is a mode that determines whether the keypad +// sends application sequences or ANSI sequences. +// +// This works the same as disabling [DECNKM]. +// +// ESC > +// +// See: https://vt100.net/docs/vt510-rm/DECKPNM.html +const ( + KeypadNumericMode = "\x1b>" + DECKPNM = KeypadNumericMode +) diff --git a/source/vendor/github.com/charmbracelet/x/ansi/kitty.go b/source/vendor/github.com/charmbracelet/x/ansi/kitty.go index c56d8d1c9c0d40b9cf6969c77eca6c39d86cb346..124ab839e23ec8f84a91d5e98370491133c0f3b5 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/kitty.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/kitty.go @@ -72,7 +72,7 @@ func PushKittyKeyboard(flags int) string { // Keyboard stack to disable the protocol. // // This is equivalent to PushKittyKeyboard(0). -const DisableKittyKeyboard = "\x1b[>0u" +const DisableKittyKeyboard = "\x1b[>u" // PopKittyKeyboard returns a sequence to pop n number of flags from the // terminal Kitty Keyboard stack. diff --git a/source/vendor/github.com/charmbracelet/x/ansi/kitty/decoder.go b/source/vendor/github.com/charmbracelet/x/ansi/kitty/decoder.go new file mode 100644 index 0000000000000000000000000000000000000000..fbd08441f4141b8f93c54c97667aadd69cf53c93 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/kitty/decoder.go @@ -0,0 +1,85 @@ +package kitty + +import ( + "compress/zlib" + "fmt" + "image" + "image/color" + "image/png" + "io" +) + +// Decoder is a decoder for the Kitty graphics protocol. It supports decoding +// images in the 24-bit [RGB], 32-bit [RGBA], and [PNG] formats. It can also +// decompress data using zlib. +// The default format is 32-bit [RGBA]. +type Decoder struct { + // Uses zlib decompression. + Decompress bool + + // Can be one of [RGB], [RGBA], or [PNG]. + Format int + + // Width of the image in pixels. This can be omitted if the image is [PNG] + // formatted. + Width int + + // Height of the image in pixels. This can be omitted if the image is [PNG] + // formatted. + Height int +} + +// Decode decodes the image data from r in the specified format. +func (d *Decoder) Decode(r io.Reader) (image.Image, error) { + if d.Decompress { + zr, err := zlib.NewReader(r) + if err != nil { + return nil, fmt.Errorf("failed to create zlib reader: %w", err) + } + + defer zr.Close() //nolint:errcheck + r = zr + } + + if d.Format == 0 { + d.Format = RGBA + } + + switch d.Format { + case RGBA, RGB: + return d.decodeRGBA(r, d.Format == RGBA) + + case PNG: + return png.Decode(r) + + default: + return nil, fmt.Errorf("unsupported format: %d", d.Format) + } +} + +// decodeRGBA decodes the image data in 32-bit RGBA or 24-bit RGB formats. +func (d *Decoder) decodeRGBA(r io.Reader, alpha bool) (image.Image, error) { + m := image.NewRGBA(image.Rect(0, 0, d.Width, d.Height)) + + var buf []byte + if alpha { + buf = make([]byte, 4) + } else { + buf = make([]byte, 3) + } + + for y := 0; y < d.Height; y++ { + for x := 0; x < d.Width; x++ { + if _, err := io.ReadFull(r, buf[:]); err != nil { + return nil, fmt.Errorf("failed to read pixel data: %w", err) + } + if alpha { + m.SetRGBA(x, y, color.RGBA{buf[0], buf[1], buf[2], buf[3]}) + } else { + m.SetRGBA(x, y, color.RGBA{buf[0], buf[1], buf[2], 0xff}) + } + } + } + + return m, nil +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/kitty/encoder.go b/source/vendor/github.com/charmbracelet/x/ansi/kitty/encoder.go new file mode 100644 index 0000000000000000000000000000000000000000..f668b9e31006578ccc1202646557fd0a760f2092 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/kitty/encoder.go @@ -0,0 +1,64 @@ +package kitty + +import ( + "compress/zlib" + "fmt" + "image" + "image/png" + "io" +) + +// Encoder is an encoder for the Kitty graphics protocol. It supports encoding +// images in the 24-bit [RGB], 32-bit [RGBA], and [PNG] formats, and +// compressing the data using zlib. +// The default format is 32-bit [RGBA]. +type Encoder struct { + // Uses zlib compression. + Compress bool + + // Can be one of [RGBA], [RGB], or [PNG]. + Format int +} + +// Encode encodes the image data in the specified format and writes it to w. +func (e *Encoder) Encode(w io.Writer, m image.Image) error { + if m == nil { + return nil + } + + if e.Compress { + zw := zlib.NewWriter(w) + defer zw.Close() //nolint:errcheck + w = zw + } + + if e.Format == 0 { + e.Format = RGBA + } + + switch e.Format { + case RGBA, RGB: + bounds := m.Bounds() + for y := bounds.Min.Y; y < bounds.Max.Y; y++ { + for x := bounds.Min.X; x < bounds.Max.X; x++ { + r, g, b, a := m.At(x, y).RGBA() + switch e.Format { + case RGBA: + w.Write([]byte{byte(r >> 8), byte(g >> 8), byte(b >> 8), byte(a >> 8)}) //nolint:errcheck + case RGB: + w.Write([]byte{byte(r >> 8), byte(g >> 8), byte(b >> 8)}) //nolint:errcheck + } + } + } + + case PNG: + if err := png.Encode(w, m); err != nil { + return fmt.Errorf("failed to encode PNG: %w", err) + } + + default: + return fmt.Errorf("unsupported format: %d", e.Format) + } + + return nil +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/kitty/graphics.go b/source/vendor/github.com/charmbracelet/x/ansi/kitty/graphics.go new file mode 100644 index 0000000000000000000000000000000000000000..490e7a8a35cfee0ff7d7d7f7a6158edd1b6eeea5 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/kitty/graphics.go @@ -0,0 +1,414 @@ +package kitty + +import "errors" + +// ErrMissingFile is returned when the file path is missing. +var ErrMissingFile = errors.New("missing file path") + +// MaxChunkSize is the maximum chunk size for the image data. +const MaxChunkSize = 1024 * 4 + +// Placeholder is a special Unicode character that can be used as a placeholder +// for an image. +const Placeholder = '\U0010EEEE' + +// Graphics image format. +const ( + // 32-bit RGBA format. + RGBA = 32 + + // 24-bit RGB format. + RGB = 24 + + // PNG format. + PNG = 100 +) + +// Compression types. +const ( + Zlib = 'z' +) + +// Transmission types. +const ( + // The data transmitted directly in the escape sequence. + Direct = 'd' + + // The data transmitted in a regular file. + File = 'f' + + // A temporary file is used and deleted after transmission. + TempFile = 't' + + // A shared memory object. + // For POSIX see https://pubs.opengroup.org/onlinepubs/9699919799/functions/shm_open.html + // For Windows see https://docs.microsoft.com/en-us/windows/win32/memory/creating-named-shared-memory + SharedMemory = 's' +) + +// Action types. +const ( + // Transmit image data. + Transmit = 't' + // TransmitAndPut transmit image data and display (put) it. + TransmitAndPut = 'T' + // Query terminal for image info. + Query = 'q' + // Put (display) previously transmitted image. + Put = 'p' + // Delete image. + Delete = 'd' + // Frame transmits data for animation frames. + Frame = 'f' + // Animate controls animation. + Animate = 'a' + // Compose composes animation frames. + Compose = 'c' +) + +// Delete types. +const ( + // Delete all placements visible on screen + DeleteAll = 'a' + // Delete all images with the specified id, specified using the i key. If + // you specify a p key for the placement id as well, then only the + // placement with the specified image id and placement id will be deleted. + DeleteID = 'i' + // Delete newest image with the specified number, specified using the I + // key. If you specify a p key for the placement id as well, then only the + // placement with the specified number and placement id will be deleted. + DeleteNumber = 'n' + // Delete all placements that intersect with the current cursor position. + DeleteCursor = 'c' + // Delete animation frames. + DeleteFrames = 'f' + // Delete all placements that intersect a specific cell, the cell is + // specified using the x and y keys + DeleteCell = 'p' + // Delete all placements that intersect a specific cell having a specific + // z-index. The cell and z-index is specified using the x, y and z keys. + DeleteCellZ = 'q' + // Delete all images whose id is greater than or equal to the value of the x + // key and less than or equal to the value of the y. + DeleteRange = 'r' + // Delete all placements that intersect the specified column, specified using + // the x key. + DeleteColumn = 'x' + // Delete all placements that intersect the specified row, specified using + // the y key. + DeleteRow = 'y' + // Delete all placements that have the specified z-index, specified using the + // z key. + DeleteZ = 'z' +) + +// Diacritic returns the diacritic rune at the specified index. If the index is +// out of bounds, the first diacritic rune is returned. +func Diacritic(i int) rune { + if i < 0 || i >= len(diacritics) { + return diacritics[0] + } + return diacritics[i] +} + +// From https://sw.kovidgoyal.net/kitty/_downloads/f0a0de9ec8d9ff4456206db8e0814937/rowcolumn-diacritics.txt +// See https://sw.kovidgoyal.net/kitty/graphics-protocol/#unicode-placeholders for further explanation. +var diacritics = []rune{ + '\u0305', + '\u030D', + '\u030E', + '\u0310', + '\u0312', + '\u033D', + '\u033E', + '\u033F', + '\u0346', + '\u034A', + '\u034B', + '\u034C', + '\u0350', + '\u0351', + '\u0352', + '\u0357', + '\u035B', + '\u0363', + '\u0364', + '\u0365', + '\u0366', + '\u0367', + '\u0368', + '\u0369', + '\u036A', + '\u036B', + '\u036C', + '\u036D', + '\u036E', + '\u036F', + '\u0483', + '\u0484', + '\u0485', + '\u0486', + '\u0487', + '\u0592', + '\u0593', + '\u0594', + '\u0595', + '\u0597', + '\u0598', + '\u0599', + '\u059C', + '\u059D', + '\u059E', + '\u059F', + '\u05A0', + '\u05A1', + '\u05A8', + '\u05A9', + '\u05AB', + '\u05AC', + '\u05AF', + '\u05C4', + '\u0610', + '\u0611', + '\u0612', + '\u0613', + '\u0614', + '\u0615', + '\u0616', + '\u0617', + '\u0657', + '\u0658', + '\u0659', + '\u065A', + '\u065B', + '\u065D', + '\u065E', + '\u06D6', + '\u06D7', + '\u06D8', + '\u06D9', + '\u06DA', + '\u06DB', + '\u06DC', + '\u06DF', + '\u06E0', + '\u06E1', + '\u06E2', + '\u06E4', + '\u06E7', + '\u06E8', + '\u06EB', + '\u06EC', + '\u0730', + '\u0732', + '\u0733', + '\u0735', + '\u0736', + '\u073A', + '\u073D', + '\u073F', + '\u0740', + '\u0741', + '\u0743', + '\u0745', + '\u0747', + '\u0749', + '\u074A', + '\u07EB', + '\u07EC', + '\u07ED', + '\u07EE', + '\u07EF', + '\u07F0', + '\u07F1', + '\u07F3', + '\u0816', + '\u0817', + '\u0818', + '\u0819', + '\u081B', + '\u081C', + '\u081D', + '\u081E', + '\u081F', + '\u0820', + '\u0821', + '\u0822', + '\u0823', + '\u0825', + '\u0826', + '\u0827', + '\u0829', + '\u082A', + '\u082B', + '\u082C', + '\u082D', + '\u0951', + '\u0953', + '\u0954', + '\u0F82', + '\u0F83', + '\u0F86', + '\u0F87', + '\u135D', + '\u135E', + '\u135F', + '\u17DD', + '\u193A', + '\u1A17', + '\u1A75', + '\u1A76', + '\u1A77', + '\u1A78', + '\u1A79', + '\u1A7A', + '\u1A7B', + '\u1A7C', + '\u1B6B', + '\u1B6D', + '\u1B6E', + '\u1B6F', + '\u1B70', + '\u1B71', + '\u1B72', + '\u1B73', + '\u1CD0', + '\u1CD1', + '\u1CD2', + '\u1CDA', + '\u1CDB', + '\u1CE0', + '\u1DC0', + '\u1DC1', + '\u1DC3', + '\u1DC4', + '\u1DC5', + '\u1DC6', + '\u1DC7', + '\u1DC8', + '\u1DC9', + '\u1DCB', + '\u1DCC', + '\u1DD1', + '\u1DD2', + '\u1DD3', + '\u1DD4', + '\u1DD5', + '\u1DD6', + '\u1DD7', + '\u1DD8', + '\u1DD9', + '\u1DDA', + '\u1DDB', + '\u1DDC', + '\u1DDD', + '\u1DDE', + '\u1DDF', + '\u1DE0', + '\u1DE1', + '\u1DE2', + '\u1DE3', + '\u1DE4', + '\u1DE5', + '\u1DE6', + '\u1DFE', + '\u20D0', + '\u20D1', + '\u20D4', + '\u20D5', + '\u20D6', + '\u20D7', + '\u20DB', + '\u20DC', + '\u20E1', + '\u20E7', + '\u20E9', + '\u20F0', + '\u2CEF', + '\u2CF0', + '\u2CF1', + '\u2DE0', + '\u2DE1', + '\u2DE2', + '\u2DE3', + '\u2DE4', + '\u2DE5', + '\u2DE6', + '\u2DE7', + '\u2DE8', + '\u2DE9', + '\u2DEA', + '\u2DEB', + '\u2DEC', + '\u2DED', + '\u2DEE', + '\u2DEF', + '\u2DF0', + '\u2DF1', + '\u2DF2', + '\u2DF3', + '\u2DF4', + '\u2DF5', + '\u2DF6', + '\u2DF7', + '\u2DF8', + '\u2DF9', + '\u2DFA', + '\u2DFB', + '\u2DFC', + '\u2DFD', + '\u2DFE', + '\u2DFF', + '\uA66F', + '\uA67C', + '\uA67D', + '\uA6F0', + '\uA6F1', + '\uA8E0', + '\uA8E1', + '\uA8E2', + '\uA8E3', + '\uA8E4', + '\uA8E5', + '\uA8E6', + '\uA8E7', + '\uA8E8', + '\uA8E9', + '\uA8EA', + '\uA8EB', + '\uA8EC', + '\uA8ED', + '\uA8EE', + '\uA8EF', + '\uA8F0', + '\uA8F1', + '\uAAB0', + '\uAAB2', + '\uAAB3', + '\uAAB7', + '\uAAB8', + '\uAABE', + '\uAABF', + '\uAAC1', + '\uFE20', + '\uFE21', + '\uFE22', + '\uFE23', + '\uFE24', + '\uFE25', + '\uFE26', + '\U00010A0F', + '\U00010A38', + '\U0001D185', + '\U0001D186', + '\U0001D187', + '\U0001D188', + '\U0001D189', + '\U0001D1AA', + '\U0001D1AB', + '\U0001D1AC', + '\U0001D1AD', + '\U0001D242', + '\U0001D243', + '\U0001D244', +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/kitty/options.go b/source/vendor/github.com/charmbracelet/x/ansi/kitty/options.go new file mode 100644 index 0000000000000000000000000000000000000000..a8d907bdd2b0a85c3d47c379e741644cc4ae2986 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/kitty/options.go @@ -0,0 +1,367 @@ +package kitty + +import ( + "encoding" + "fmt" + "strconv" + "strings" +) + +var ( + _ encoding.TextMarshaler = Options{} + _ encoding.TextUnmarshaler = &Options{} +) + +// Options represents a Kitty Graphics Protocol options. +type Options struct { + // Common options. + + // Action (a=t) is the action to be performed on the image. Can be one of + // [Transmit], [TransmitDisplay], [Query], [Put], [Delete], [Frame], + // [Animate], [Compose]. + Action byte + + // Quite mode (q=0) is the quiet mode. Can be either zero, one, or two + // where zero is the default, 1 suppresses OK responses, and 2 suppresses + // both OK and error responses. + Quite byte + + // Transmission options. + + // ID (i=) is the image ID. The ID is a unique identifier for the image. + // Must be a positive integer up to [math.MaxUint32]. + ID int + + // PlacementID (p=) is the placement ID. The placement ID is a unique + // identifier for the placement of the image. Must be a positive integer up + // to [math.MaxUint32]. + PlacementID int + + // Number (I=0) is the number of images to be transmitted. + Number int + + // Format (f=32) is the image format. One of [RGBA], [RGB], [PNG]. + Format int + + // ImageWidth (s=0) is the transmitted image width. + ImageWidth int + + // ImageHeight (v=0) is the transmitted image height. + ImageHeight int + + // Compression (o=) is the image compression type. Can be [Zlib] or zero. + Compression byte + + // Transmission (t=d) is the image transmission type. Can be [Direct], [File], + // [TempFile], or[SharedMemory]. + Transmission byte + + // File is the file path to be used when the transmission type is [File]. + // If [Options.Transmission] is omitted i.e. zero and this is non-empty, + // the transmission type is set to [File]. + File string + + // Size (S=0) is the size to be read from the transmission medium. + Size int + + // Offset (O=0) is the offset byte to start reading from the transmission + // medium. + Offset int + + // Chunk (m=) whether the image is transmitted in chunks. Can be either + // zero or one. When true, the image is transmitted in chunks. Each chunk + // must be a multiple of 4, and up to [MaxChunkSize] bytes. Each chunk must + // have the m=1 option except for the last chunk which must have m=0. + Chunk bool + + // Display options. + + // X (x=0) is the pixel X coordinate of the image to start displaying. + X int + + // Y (y=0) is the pixel Y coordinate of the image to start displaying. + Y int + + // Z (z=0) is the Z coordinate of the image to display. + Z int + + // Width (w=0) is the width of the image to display. + Width int + + // Height (h=0) is the height of the image to display. + Height int + + // OffsetX (X=0) is the OffsetX coordinate of the cursor cell to start + // displaying the image. OffsetX=0 is the leftmost cell. This must be + // smaller than the terminal cell width. + OffsetX int + + // OffsetY (Y=0) is the OffsetY coordinate of the cursor cell to start + // displaying the image. OffsetY=0 is the topmost cell. This must be + // smaller than the terminal cell height. + OffsetY int + + // Columns (c=0) is the number of columns to display the image. The image + // will be scaled to fit the number of columns. + Columns int + + // Rows (r=0) is the number of rows to display the image. The image will be + // scaled to fit the number of rows. + Rows int + + // VirtualPlacement (U=0) whether to use virtual placement. This is used + // with Unicode [Placeholder] to display images. + VirtualPlacement bool + + // DoNotMoveCursor (C=0) whether to move the cursor after displaying the + // image. + DoNotMoveCursor bool + + // ParentID (P=0) is the parent image ID. The parent ID is the ID of the + // image that is the parent of the current image. This is used with Unicode + // [Placeholder] to display images relative to the parent image. + ParentID int + + // ParentPlacementID (Q=0) is the parent placement ID. The parent placement + // ID is the ID of the placement of the parent image. This is used with + // Unicode [Placeholder] to display images relative to the parent image. + ParentPlacementID int + + // Delete options. + + // Delete (d=a) is the delete action. Can be one of [DeleteAll], + // [DeleteID], [DeleteNumber], [DeleteCursor], [DeleteFrames], + // [DeleteCell], [DeleteCellZ], [DeleteRange], [DeleteColumn], [DeleteRow], + // [DeleteZ]. + Delete byte + + // DeleteResources indicates whether to delete the resources associated + // with the image. + DeleteResources bool +} + +// Options returns the options as a slice of a key-value pairs. +func (o *Options) Options() (opts []string) { + opts = []string{} + if o.Format == 0 { + o.Format = RGBA + } + + if o.Action == 0 { + o.Action = Transmit + } + + if o.Delete == 0 { + o.Delete = DeleteAll + } + + if o.Transmission == 0 { + if len(o.File) > 0 { + o.Transmission = File + } else { + o.Transmission = Direct + } + } + + if o.Format != RGBA { + opts = append(opts, fmt.Sprintf("f=%d", o.Format)) + } + + if o.Quite > 0 { + opts = append(opts, fmt.Sprintf("q=%d", o.Quite)) + } + + if o.ID > 0 { + opts = append(opts, fmt.Sprintf("i=%d", o.ID)) + } + + if o.PlacementID > 0 { + opts = append(opts, fmt.Sprintf("p=%d", o.PlacementID)) + } + + if o.Number > 0 { + opts = append(opts, fmt.Sprintf("I=%d", o.Number)) + } + + if o.ImageWidth > 0 { + opts = append(opts, fmt.Sprintf("s=%d", o.ImageWidth)) + } + + if o.ImageHeight > 0 { + opts = append(opts, fmt.Sprintf("v=%d", o.ImageHeight)) + } + + if o.Transmission != Direct { + opts = append(opts, fmt.Sprintf("t=%c", o.Transmission)) + } + + if o.Size > 0 { + opts = append(opts, fmt.Sprintf("S=%d", o.Size)) + } + + if o.Offset > 0 { + opts = append(opts, fmt.Sprintf("O=%d", o.Offset)) + } + + if o.Compression == Zlib { + opts = append(opts, fmt.Sprintf("o=%c", o.Compression)) + } + + if o.VirtualPlacement { + opts = append(opts, "U=1") + } + + if o.DoNotMoveCursor { + opts = append(opts, "C=1") + } + + if o.ParentID > 0 { + opts = append(opts, fmt.Sprintf("P=%d", o.ParentID)) + } + + if o.ParentPlacementID > 0 { + opts = append(opts, fmt.Sprintf("Q=%d", o.ParentPlacementID)) + } + + if o.X > 0 { + opts = append(opts, fmt.Sprintf("x=%d", o.X)) + } + + if o.Y > 0 { + opts = append(opts, fmt.Sprintf("y=%d", o.Y)) + } + + if o.Z > 0 { + opts = append(opts, fmt.Sprintf("z=%d", o.Z)) + } + + if o.Width > 0 { + opts = append(opts, fmt.Sprintf("w=%d", o.Width)) + } + + if o.Height > 0 { + opts = append(opts, fmt.Sprintf("h=%d", o.Height)) + } + + if o.OffsetX > 0 { + opts = append(opts, fmt.Sprintf("X=%d", o.OffsetX)) + } + + if o.OffsetY > 0 { + opts = append(opts, fmt.Sprintf("Y=%d", o.OffsetY)) + } + + if o.Columns > 0 { + opts = append(opts, fmt.Sprintf("c=%d", o.Columns)) + } + + if o.Rows > 0 { + opts = append(opts, fmt.Sprintf("r=%d", o.Rows)) + } + + if o.Delete != DeleteAll || o.DeleteResources { + da := o.Delete + if o.DeleteResources { + da = da - ' ' // to uppercase + } + + opts = append(opts, fmt.Sprintf("d=%c", da)) + } + + if o.Action != Transmit { + opts = append(opts, fmt.Sprintf("a=%c", o.Action)) + } + + return +} + +// String returns the string representation of the options. +func (o Options) String() string { + return strings.Join(o.Options(), ",") +} + +// MarshalText returns the string representation of the options. +func (o Options) MarshalText() ([]byte, error) { + return []byte(o.String()), nil +} + +// UnmarshalText parses the options from the given string. +func (o *Options) UnmarshalText(text []byte) error { + opts := strings.Split(string(text), ",") + for _, opt := range opts { + ps := strings.SplitN(opt, "=", 2) + if len(ps) != 2 || len(ps[1]) == 0 { + continue + } + + switch ps[0] { + case "a": + o.Action = ps[1][0] + case "o": + o.Compression = ps[1][0] + case "t": + o.Transmission = ps[1][0] + case "d": + d := ps[1][0] + if d >= 'A' && d <= 'Z' { + o.DeleteResources = true + d = d + ' ' // to lowercase + } + o.Delete = d + case "i", "q", "p", "I", "f", "s", "v", "S", "O", "m", "x", "y", "z", "w", "h", "X", "Y", "c", "r", "U", "P", "Q": + v, err := strconv.Atoi(ps[1]) + if err != nil { + continue + } + + switch ps[0] { + case "i": + o.ID = v + case "q": + o.Quite = byte(v) + case "p": + o.PlacementID = v + case "I": + o.Number = v + case "f": + o.Format = v + case "s": + o.ImageWidth = v + case "v": + o.ImageHeight = v + case "S": + o.Size = v + case "O": + o.Offset = v + case "m": + o.Chunk = v == 0 || v == 1 + case "x": + o.X = v + case "y": + o.Y = v + case "z": + o.Z = v + case "w": + o.Width = v + case "h": + o.Height = v + case "X": + o.OffsetX = v + case "Y": + o.OffsetY = v + case "c": + o.Columns = v + case "r": + o.Rows = v + case "U": + o.VirtualPlacement = v == 1 + case "P": + o.ParentID = v + case "Q": + o.ParentPlacementID = v + } + } + } + + return nil +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/method.go b/source/vendor/github.com/charmbracelet/x/ansi/method.go new file mode 100644 index 0000000000000000000000000000000000000000..0218809c9a2f2209f8ece49d1edb4e7d5a74478e --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/method.go @@ -0,0 +1,172 @@ +package ansi + +// Method is a type that represents the how the renderer should calculate the +// display width of cells. +type Method uint8 + +// Display width modes. +const ( + WcWidth Method = iota + GraphemeWidth +) + +// StringWidth returns the width of a string in cells. This is the number of +// cells that the string will occupy when printed in a terminal. ANSI escape +// codes are ignored and wide characters (such as East Asians and emojis) are +// accounted for. +func (m Method) StringWidth(s string) int { + return stringWidth(m, s) +} + +// Truncate truncates a string to a given length, adding a tail to the end if +// the string is longer than the given length. This function is aware of ANSI +// escape codes and will not break them, and accounts for wide-characters (such +// as East-Asian characters and emojis). +func (m Method) Truncate(s string, length int, tail string) string { + return truncate(m, s, length, tail) +} + +// TruncateLeft truncates a string to a given length, adding a prefix to the +// beginning if the string is longer than the given length. This function is +// aware of ANSI escape codes and will not break them, and accounts for +// wide-characters (such as East-Asian characters and emojis). +func (m Method) TruncateLeft(s string, length int, prefix string) string { + return truncateLeft(m, s, length, prefix) +} + +// Cut the string, without adding any prefix or tail strings. This function is +// aware of ANSI escape codes and will not break them, and accounts for +// wide-characters (such as East-Asian characters and emojis). Note that the +// [left] parameter is inclusive, while [right] isn't. +func (m Method) Cut(s string, left, right int) string { + return cut(m, s, left, right) +} + +// Hardwrap wraps a string or a block of text to a given line length, breaking +// word boundaries. This will preserve ANSI escape codes and will account for +// wide-characters in the string. +// When preserveSpace is true, spaces at the beginning of a line will be +// preserved. +// This treats the text as a sequence of graphemes. +func (m Method) Hardwrap(s string, length int, preserveSpace bool) string { + return hardwrap(m, s, length, preserveSpace) +} + +// Wordwrap wraps a string or a block of text to a given line length, not +// breaking word boundaries. This will preserve ANSI escape codes and will +// account for wide-characters in the string. +// The breakpoints string is a list of characters that are considered +// breakpoints for word wrapping. A hyphen (-) is always considered a +// breakpoint. +// +// Note: breakpoints must be a string of 1-cell wide rune characters. +func (m Method) Wordwrap(s string, length int, breakpoints string) string { + return wordwrap(m, s, length, breakpoints) +} + +// Wrap wraps a string or a block of text to a given line length, breaking word +// boundaries if necessary. This will preserve ANSI escape codes and will +// account for wide-characters in the string. The breakpoints string is a list +// of characters that are considered breakpoints for word wrapping. A hyphen +// (-) is always considered a breakpoint. +// +// Note: breakpoints must be a string of 1-cell wide rune characters. +func (m Method) Wrap(s string, length int, breakpoints string) string { + return wrap(m, s, length, breakpoints) +} + +// DecodeSequence decodes the first ANSI escape sequence or a printable +// grapheme from the given data. It returns the sequence slice, the number of +// bytes read, the cell width for each sequence, and the new state. +// +// The cell width will always be 0 for control and escape sequences, 1 for +// ASCII printable characters, and the number of cells other Unicode characters +// occupy. It uses the uniseg package to calculate the width of Unicode +// graphemes and characters. This means it will always do grapheme clustering +// (mode 2027). +// +// Passing a non-nil [*Parser] as the last argument will allow the decoder to +// collect sequence parameters, data, and commands. The parser cmd will have +// the packed command value that contains intermediate and prefix characters. +// In the case of a OSC sequence, the cmd will be the OSC command number. Use +// [Cmd] and [Param] types to unpack command intermediates and prefixes as well +// as parameters. +// +// Zero [Cmd] means the CSI, DCS, or ESC sequence is invalid. Moreover, checking the +// validity of other data sequences, OSC, DCS, etc, will require checking for +// the returned sequence terminator bytes such as ST (ESC \\) and BEL). +// +// We store the command byte in [Cmd] in the most significant byte, the +// prefix byte in the next byte, and the intermediate byte in the least +// significant byte. This is done to avoid using a struct to store the command +// and its intermediates and prefixes. The command byte is always the least +// significant byte i.e. [Cmd & 0xff]. Use the [Cmd] type to unpack the +// command, intermediate, and prefix bytes. Note that we only collect the last +// prefix character and intermediate byte. +// +// The [p.Params] slice will contain the parameters of the sequence. Any +// sub-parameter will have the [parser.HasMoreFlag] set. Use the [Param] type +// to unpack the parameters. +// +// Example: +// +// var state byte // the initial state is always zero [NormalState] +// p := NewParser(32, 1024) // create a new parser with a 32 params buffer and 1024 data buffer (optional) +// input := []byte("\x1b[31mHello, World!\x1b[0m") +// for len(input) > 0 { +// seq, width, n, newState := DecodeSequence(input, state, p) +// log.Printf("seq: %q, width: %d", seq, width) +// state = newState +// input = input[n:] +// } +func (m Method) DecodeSequence(data []byte, state byte, p *Parser) (seq []byte, width, n int, newState byte) { + return decodeSequence(m, data, state, p) +} + +// DecodeSequenceInString decodes the first ANSI escape sequence or a printable +// grapheme from the given data. It returns the sequence slice, the number of +// bytes read, the cell width for each sequence, and the new state. +// +// The cell width will always be 0 for control and escape sequences, 1 for +// ASCII printable characters, and the number of cells other Unicode characters +// occupy. It uses the uniseg package to calculate the width of Unicode +// graphemes and characters. This means it will always do grapheme clustering +// (mode 2027). +// +// Passing a non-nil [*Parser] as the last argument will allow the decoder to +// collect sequence parameters, data, and commands. The parser cmd will have +// the packed command value that contains intermediate and prefix characters. +// In the case of a OSC sequence, the cmd will be the OSC command number. Use +// [Cmd] and [Param] types to unpack command intermediates and prefixes as well +// as parameters. +// +// Zero [Cmd] means the CSI, DCS, or ESC sequence is invalid. Moreover, checking the +// validity of other data sequences, OSC, DCS, etc, will require checking for +// the returned sequence terminator bytes such as ST (ESC \\) and BEL). +// +// We store the command byte in [Cmd] in the most significant byte, the +// prefix byte in the next byte, and the intermediate byte in the least +// significant byte. This is done to avoid using a struct to store the command +// and its intermediates and prefixes. The command byte is always the least +// significant byte i.e. [Cmd & 0xff]. Use the [Cmd] type to unpack the +// command, intermediate, and prefix bytes. Note that we only collect the last +// prefix character and intermediate byte. +// +// The [p.Params] slice will contain the parameters of the sequence. Any +// sub-parameter will have the [parser.HasMoreFlag] set. Use the [Param] type +// to unpack the parameters. +// +// Example: +// +// var state byte // the initial state is always zero [NormalState] +// p := NewParser(32, 1024) // create a new parser with a 32 params buffer and 1024 data buffer (optional) +// input := []byte("\x1b[31mHello, World!\x1b[0m") +// for len(input) > 0 { +// seq, width, n, newState := DecodeSequenceInString(input, state, p) +// log.Printf("seq: %q, width: %d", seq, width) +// state = newState +// input = input[n:] +// } +func (m Method) DecodeSequenceInString(data string, state byte, p *Parser) (seq string, width, n int, newState byte) { + return decodeSequence(m, data, state, p) +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/mode.go b/source/vendor/github.com/charmbracelet/x/ansi/mode.go index 10dfcf5af858f0d048f21efd7828a0cd2246c7fe..57f3f0a8e33377d098f116e672adf354feb55320 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/mode.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/mode.go @@ -1,144 +1,676 @@ package ansi -import "strconv" +import ( + "strconv" + "strings" +) + +// ModeSetting represents a mode setting. +type ModeSetting byte + +// ModeSetting constants. +const ( + ModeNotRecognized ModeSetting = iota + ModeSet + ModeReset + ModePermanentlySet + ModePermanentlyReset +) + +// IsNotRecognized returns true if the mode is not recognized. +func (m ModeSetting) IsNotRecognized() bool { + return m == ModeNotRecognized +} + +// IsSet returns true if the mode is set or permanently set. +func (m ModeSetting) IsSet() bool { + return m == ModeSet || m == ModePermanentlySet +} + +// IsReset returns true if the mode is reset or permanently reset. +func (m ModeSetting) IsReset() bool { + return m == ModeReset || m == ModePermanentlyReset +} + +// IsPermanentlySet returns true if the mode is permanently set. +func (m ModeSetting) IsPermanentlySet() bool { + return m == ModePermanentlySet +} + +// IsPermanentlyReset returns true if the mode is permanently reset. +func (m ModeSetting) IsPermanentlyReset() bool { + return m == ModePermanentlyReset +} -// This file define uses multiple sequences to set (SM), reset (RM), and request -// (DECRQM) different ANSI and DEC modes. +// Mode represents an interface for terminal modes. +// Modes can be set, reset, and requested. +type Mode interface { + Mode() int +} + +// SetMode (SM) returns a sequence to set a mode. +// The mode arguments are a list of modes to set. +// +// If one of the modes is a [DECMode], the function will returns two escape +// sequences. +// +// ANSI format: +// +// CSI Pd ; ... ; Pd h +// +// DEC format: +// +// CSI ? Pd ; ... ; Pd h // // See: https://vt100.net/docs/vt510-rm/SM.html +func SetMode(modes ...Mode) string { + return setMode(false, modes...) +} + +// SM is an alias for [SetMode]. +func SM(modes ...Mode) string { + return SetMode(modes...) +} + +// ResetMode (RM) returns a sequence to reset a mode. +// The mode arguments are a list of modes to reset. +// +// If one of the modes is a [DECMode], the function will returns two escape +// sequences. +// +// ANSI format: +// +// CSI Pd ; ... ; Pd l +// +// DEC format: +// +// CSI ? Pd ; ... ; Pd l +// // See: https://vt100.net/docs/vt510-rm/RM.html -// See: https://vt100.net/docs/vt510-rm/DECRQM.html +func ResetMode(modes ...Mode) string { + return setMode(true, modes...) +} + +// RM is an alias for [ResetMode]. +func RM(modes ...Mode) string { + return ResetMode(modes...) +} + +func setMode(reset bool, modes ...Mode) (s string) { + if len(modes) == 0 { + return + } + + cmd := "h" + if reset { + cmd = "l" + } + + seq := "\x1b[" + if len(modes) == 1 { + switch modes[0].(type) { + case DECMode: + seq += "?" + } + return seq + strconv.Itoa(modes[0].Mode()) + cmd + } + + dec := make([]string, 0, len(modes)/2) + ansi := make([]string, 0, len(modes)/2) + for _, m := range modes { + switch m.(type) { + case DECMode: + dec = append(dec, strconv.Itoa(m.Mode())) + case ANSIMode: + ansi = append(ansi, strconv.Itoa(m.Mode())) + } + } + + if len(ansi) > 0 { + s += seq + strings.Join(ansi, ";") + cmd + } + if len(dec) > 0 { + s += seq + "?" + strings.Join(dec, ";") + cmd + } + return +} + +// RequestMode (DECRQM) returns a sequence to request a mode from the terminal. +// The terminal responds with a report mode function [DECRPM]. // -// The terminal then responds to the request with a Report Mode function -// (DECRPM) in the format: +// ANSI format: +// +// CSI Pa $ p +// +// DEC format: +// +// CSI ? Pa $ p +// +// See: https://vt100.net/docs/vt510-rm/DECRQM.html +func RequestMode(m Mode) string { + seq := "\x1b[" + switch m.(type) { + case DECMode: + seq += "?" + } + return seq + strconv.Itoa(m.Mode()) + "$p" +} + +// DECRQM is an alias for [RequestMode]. +func DECRQM(m Mode) string { + return RequestMode(m) +} + +// ReportMode (DECRPM) returns a sequence that the terminal sends to the host +// in response to a mode request [DECRQM]. // // ANSI format: // -// CSI Pa ; Ps ; $ y +// CSI Pa ; Ps ; $ y // // DEC format: // -// CSI ? Pa ; Ps $ y +// CSI ? Pa ; Ps $ y // // Where Pa is the mode number, and Ps is the mode value. +// +// 0: Not recognized +// 1: Set +// 2: Reset +// 3: Permanent set +// 4: Permanent reset +// // See: https://vt100.net/docs/vt510-rm/DECRPM.html +func ReportMode(mode Mode, value ModeSetting) string { + if value > 4 { + value = 0 + } + switch mode.(type) { + case DECMode: + return "\x1b[?" + strconv.Itoa(mode.Mode()) + ";" + strconv.Itoa(int(value)) + "$y" + } + return "\x1b[" + strconv.Itoa(mode.Mode()) + ";" + strconv.Itoa(int(value)) + "$y" +} -// Mode represents an ANSI terminal mode. -type Mode int +// DECRPM is an alias for [ReportMode]. +func DECRPM(mode Mode, value ModeSetting) string { + return ReportMode(mode, value) +} + +// ANSIMode represents an ANSI terminal mode. +type ANSIMode int //nolint:revive -// String returns the mode as a string. -func (m Mode) String() string { - return strconv.Itoa(int(m)) +// Mode returns the ANSI mode as an integer. +func (m ANSIMode) Mode() int { + return int(m) } -// PrivateMode represents a private DEC terminal mode. -type PrivateMode int +// DECMode represents a private DEC terminal mode. +type DECMode int -// String returns the private mode as a string. -func (m PrivateMode) String() string { - return "?" + strconv.Itoa(int(m)) +// Mode returns the DEC mode as an integer. +func (m DECMode) Mode() int { + return int(m) } -// Application Cursor Keys (DECCKM) is a mode that determines whether the -// cursor keys send ANSI cursor sequences or application sequences. +// Keyboard Action Mode (KAM) is a mode that controls locking of the keyboard. +// When the keyboard is locked, it cannot send data to the terminal. +// +// See: https://vt100.net/docs/vt510-rm/KAM.html +const ( + KeyboardActionMode = ANSIMode(2) + KAM = KeyboardActionMode + + SetKeyboardActionMode = "\x1b[2h" + ResetKeyboardActionMode = "\x1b[2l" + RequestKeyboardActionMode = "\x1b[2$p" +) + +// Insert/Replace Mode (IRM) is a mode that determines whether characters are +// inserted or replaced when typed. +// +// When enabled, characters are inserted at the cursor position pushing the +// characters to the right. When disabled, characters replace the character at +// the cursor position. +// +// See: https://vt100.net/docs/vt510-rm/IRM.html +const ( + InsertReplaceMode = ANSIMode(4) + IRM = InsertReplaceMode + + SetInsertReplaceMode = "\x1b[4h" + ResetInsertReplaceMode = "\x1b[4l" + RequestInsertReplaceMode = "\x1b[4$p" +) + +// Send Receive Mode (SRM) or Local Echo Mode is a mode that determines whether +// the terminal echoes characters back to the host. When enabled, the terminal +// sends characters to the host as they are typed. +// +// See: https://vt100.net/docs/vt510-rm/SRM.html +const ( + SendReceiveMode = ANSIMode(12) + LocalEchoMode = SendReceiveMode + SRM = SendReceiveMode + + SetSendReceiveMode = "\x1b[12h" + ResetSendReceiveMode = "\x1b[12l" + RequestSendReceiveMode = "\x1b[12$p" + + SetLocalEchoMode = "\x1b[12h" + ResetLocalEchoMode = "\x1b[12l" + RequestLocalEchoMode = "\x1b[12$p" +) + +// Line Feed/New Line Mode (LNM) is a mode that determines whether the terminal +// interprets the line feed character as a new line. +// +// When enabled, the terminal interprets the line feed character as a new line. +// When disabled, the terminal interprets the line feed character as a line feed. +// +// A new line moves the cursor to the first position of the next line. +// A line feed moves the cursor down one line without changing the column +// scrolling the screen if necessary. +// +// See: https://vt100.net/docs/vt510-rm/LNM.html +const ( + LineFeedNewLineMode = ANSIMode(20) + LNM = LineFeedNewLineMode + + SetLineFeedNewLineMode = "\x1b[20h" + ResetLineFeedNewLineMode = "\x1b[20l" + RequestLineFeedNewLineMode = "\x1b[20$p" +) + +// Cursor Keys Mode (DECCKM) is a mode that determines whether the cursor keys +// send ANSI cursor sequences or application sequences. // // See: https://vt100.net/docs/vt510-rm/DECCKM.html const ( - CursorKeysMode = PrivateMode(1) + CursorKeysMode = DECMode(1) + DECCKM = CursorKeysMode + + SetCursorKeysMode = "\x1b[?1h" + ResetCursorKeysMode = "\x1b[?1l" + RequestCursorKeysMode = "\x1b[?1$p" +) +// Deprecated: use [SetCursorKeysMode] and [ResetCursorKeysMode] instead. +const ( EnableCursorKeys = "\x1b[?1h" DisableCursorKeys = "\x1b[?1l" - RequestCursorKeys = "\x1b[?1$p" +) + +// Origin Mode (DECOM) is a mode that determines whether the cursor moves to the +// home position or the margin position. +// +// See: https://vt100.net/docs/vt510-rm/DECOM.html +const ( + OriginMode = DECMode(6) + DECOM = OriginMode + + SetOriginMode = "\x1b[?6h" + ResetOriginMode = "\x1b[?6l" + RequestOriginMode = "\x1b[?6$p" +) + +// Auto Wrap Mode (DECAWM) is a mode that determines whether the cursor wraps +// to the next line when it reaches the right margin. +// +// See: https://vt100.net/docs/vt510-rm/DECAWM.html +const ( + AutoWrapMode = DECMode(7) + DECAWM = AutoWrapMode + + SetAutoWrapMode = "\x1b[?7h" + ResetAutoWrapMode = "\x1b[?7l" + RequestAutoWrapMode = "\x1b[?7$p" +) + +// X10 Mouse Mode is a mode that determines whether the mouse reports on button +// presses. +// +// The terminal responds with the following encoding: +// +// CSI M CbCxCy +// +// Where Cb is the button-1, where it can be 1, 2, or 3. +// Cx and Cy are the x and y coordinates of the mouse event. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +const ( + X10MouseMode = DECMode(9) + + SetX10MouseMode = "\x1b[?9h" + ResetX10MouseMode = "\x1b[?9l" + RequestX10MouseMode = "\x1b[?9$p" ) // Text Cursor Enable Mode (DECTCEM) is a mode that shows/hides the cursor. // // See: https://vt100.net/docs/vt510-rm/DECTCEM.html const ( - CursorEnableMode = PrivateMode(25) + TextCursorEnableMode = DECMode(25) + DECTCEM = TextCursorEnableMode + + SetTextCursorEnableMode = "\x1b[?25h" + ResetTextCursorEnableMode = "\x1b[?25l" + RequestTextCursorEnableMode = "\x1b[?25$p" +) + +// These are aliases for [SetTextCursorEnableMode] and [ResetTextCursorEnableMode]. +const ( + ShowCursor = SetTextCursorEnableMode + HideCursor = ResetTextCursorEnableMode +) - ShowCursor = "\x1b[?25h" - HideCursor = "\x1b[?25l" +// Text Cursor Enable Mode (DECTCEM) is a mode that shows/hides the cursor. +// +// See: https://vt100.net/docs/vt510-rm/DECTCEM.html +// +// Deprecated: use [SetTextCursorEnableMode] and [ResetTextCursorEnableMode] instead. +const ( + CursorEnableMode = DECMode(25) RequestCursorVisibility = "\x1b[?25$p" ) +// Numeric Keypad Mode (DECNKM) is a mode that determines whether the keypad +// sends application sequences or numeric sequences. +// +// This works like [DECKPAM] and [DECKPNM], but uses different sequences. +// +// See: https://vt100.net/docs/vt510-rm/DECNKM.html +const ( + NumericKeypadMode = DECMode(66) + DECNKM = NumericKeypadMode + + SetNumericKeypadMode = "\x1b[?66h" + ResetNumericKeypadMode = "\x1b[?66l" + RequestNumericKeypadMode = "\x1b[?66$p" +) + +// Backarrow Key Mode (DECBKM) is a mode that determines whether the backspace +// key sends a backspace or delete character. Disabled by default. +// +// See: https://vt100.net/docs/vt510-rm/DECBKM.html +const ( + BackarrowKeyMode = DECMode(67) + DECBKM = BackarrowKeyMode + + SetBackarrowKeyMode = "\x1b[?67h" + ResetBackarrowKeyMode = "\x1b[?67l" + RequestBackarrowKeyMode = "\x1b[?67$p" +) + +// Left Right Margin Mode (DECLRMM) is a mode that determines whether the left +// and right margins can be set with [DECSLRM]. +// +// See: https://vt100.net/docs/vt510-rm/DECLRMM.html +const ( + LeftRightMarginMode = DECMode(69) + DECLRMM = LeftRightMarginMode + + SetLeftRightMarginMode = "\x1b[?69h" + ResetLeftRightMarginMode = "\x1b[?69l" + RequestLeftRightMarginMode = "\x1b[?69$p" +) + +// Normal Mouse Mode is a mode that determines whether the mouse reports on +// button presses and releases. It will also report modifier keys, wheel +// events, and extra buttons. +// +// It uses the same encoding as [X10MouseMode] with a few differences: +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +const ( + NormalMouseMode = DECMode(1000) + + SetNormalMouseMode = "\x1b[?1000h" + ResetNormalMouseMode = "\x1b[?1000l" + RequestNormalMouseMode = "\x1b[?1000$p" +) + // VT Mouse Tracking is a mode that determines whether the mouse reports on // button press and release. // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +// +// Deprecated: use [NormalMouseMode] instead. const ( - MouseMode = PrivateMode(1000) + MouseMode = DECMode(1000) EnableMouse = "\x1b[?1000h" DisableMouse = "\x1b[?1000l" RequestMouse = "\x1b[?1000$p" ) +// Highlight Mouse Tracking is a mode that determines whether the mouse reports +// on button presses, releases, and highlighted cells. +// +// It uses the same encoding as [NormalMouseMode] with a few differences: +// +// On highlight events, the terminal responds with the following encoding: +// +// CSI t CxCy +// CSI T CxCyCxCyCxCy +// +// Where the parameters are startx, starty, endx, endy, mousex, and mousey. +const ( + HighlightMouseMode = DECMode(1001) + + SetHighlightMouseMode = "\x1b[?1001h" + ResetHighlightMouseMode = "\x1b[?1001l" + RequestHighlightMouseMode = "\x1b[?1001$p" +) + // VT Hilite Mouse Tracking is a mode that determines whether the mouse reports on // button presses, releases, and highlighted cells. // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +// +// Deprecated: use [HighlightMouseMode] instead. const ( - MouseHiliteMode = PrivateMode(1001) + MouseHiliteMode = DECMode(1001) EnableMouseHilite = "\x1b[?1001h" DisableMouseHilite = "\x1b[?1001l" RequestMouseHilite = "\x1b[?1001$p" ) +// Button Event Mouse Tracking is essentially the same as [NormalMouseMode], +// but it also reports button-motion events when a button is pressed. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +const ( + ButtonEventMouseMode = DECMode(1002) + + SetButtonEventMouseMode = "\x1b[?1002h" + ResetButtonEventMouseMode = "\x1b[?1002l" + RequestButtonEventMouseMode = "\x1b[?1002$p" +) + // Cell Motion Mouse Tracking is a mode that determines whether the mouse // reports on button press, release, and motion events. // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +// +// Deprecated: use [ButtonEventMouseMode] instead. const ( - MouseCellMotionMode = PrivateMode(1002) + MouseCellMotionMode = DECMode(1002) EnableMouseCellMotion = "\x1b[?1002h" DisableMouseCellMotion = "\x1b[?1002l" RequestMouseCellMotion = "\x1b[?1002$p" ) +// Any Event Mouse Tracking is the same as [ButtonEventMouseMode], except that +// all motion events are reported even if no mouse buttons are pressed. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +const ( + AnyEventMouseMode = DECMode(1003) + + SetAnyEventMouseMode = "\x1b[?1003h" + ResetAnyEventMouseMode = "\x1b[?1003l" + RequestAnyEventMouseMode = "\x1b[?1003$p" +) + // All Mouse Tracking is a mode that determines whether the mouse reports on // button press, release, motion, and highlight events. // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +// +// Deprecated: use [AnyEventMouseMode] instead. const ( - MouseAllMotionMode = PrivateMode(1003) + MouseAllMotionMode = DECMode(1003) EnableMouseAllMotion = "\x1b[?1003h" DisableMouseAllMotion = "\x1b[?1003l" RequestMouseAllMotion = "\x1b[?1003$p" ) -// Report Focus is a mode that makes the terminal report focus-in and focus-out events. +// Focus Event Mode is a mode that determines whether the terminal reports focus +// and blur events. +// +// The terminal sends the following encoding: // -// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-FocusIn_FocusOut +// CSI I // Focus In +// CSI O // Focus Out +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Focus-Tracking const ( - ReportFocusMode = PrivateMode(1004) + FocusEventMode = DECMode(1004) + + SetFocusEventMode = "\x1b[?1004h" + ResetFocusEventMode = "\x1b[?1004l" + RequestFocusEventMode = "\x1b[?1004$p" +) + +// Deprecated: use [SetFocusEventMode], [ResetFocusEventMode], and +// [RequestFocusEventMode] instead. +const ( + ReportFocusMode = DECMode(1004) EnableReportFocus = "\x1b[?1004h" DisableReportFocus = "\x1b[?1004l" RequestReportFocus = "\x1b[?1004$p" ) -// SGR Mouse Extension is a mode that determines whether the mouse reports events -// formatted with SGR parameters. +// SGR Extended Mouse Mode is a mode that changes the mouse tracking encoding +// to use SGR parameters. +// +// The terminal responds with the following encoding: +// +// CSI < Cb ; Cx ; Cy M +// +// Where Cb is the same as [NormalMouseMode], and Cx and Cy are the x and y. // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking const ( - MouseSgrExtMode = PrivateMode(1006) + SgrExtMouseMode = DECMode(1006) + + SetSgrExtMouseMode = "\x1b[?1006h" + ResetSgrExtMouseMode = "\x1b[?1006l" + RequestSgrExtMouseMode = "\x1b[?1006$p" +) +// Deprecated: use [SgrExtMouseMode] [SetSgrExtMouseMode], +// [ResetSgrExtMouseMode], and [RequestSgrExtMouseMode] instead. +const ( + MouseSgrExtMode = DECMode(1006) EnableMouseSgrExt = "\x1b[?1006h" DisableMouseSgrExt = "\x1b[?1006l" RequestMouseSgrExt = "\x1b[?1006$p" ) +// UTF-8 Extended Mouse Mode is a mode that changes the mouse tracking encoding +// to use UTF-8 parameters. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +const ( + Utf8ExtMouseMode = DECMode(1005) + + SetUtf8ExtMouseMode = "\x1b[?1005h" + ResetUtf8ExtMouseMode = "\x1b[?1005l" + RequestUtf8ExtMouseMode = "\x1b[?1005$p" +) + +// URXVT Extended Mouse Mode is a mode that changes the mouse tracking encoding +// to use an alternate encoding. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +const ( + UrxvtExtMouseMode = DECMode(1015) + + SetUrxvtExtMouseMode = "\x1b[?1015h" + ResetUrxvtExtMouseMode = "\x1b[?1015l" + RequestUrxvtExtMouseMode = "\x1b[?1015$p" +) + +// SGR Pixel Extended Mouse Mode is a mode that changes the mouse tracking +// encoding to use SGR parameters with pixel coordinates. +// +// This is similar to [SgrExtMouseMode], but also reports pixel coordinates. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking +const ( + SgrPixelExtMouseMode = DECMode(1016) + + SetSgrPixelExtMouseMode = "\x1b[?1016h" + ResetSgrPixelExtMouseMode = "\x1b[?1016l" + RequestSgrPixelExtMouseMode = "\x1b[?1016$p" +) + +// Alternate Screen Mode is a mode that determines whether the alternate screen +// buffer is active. When this mode is enabled, the alternate screen buffer is +// cleared. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer +const ( + AltScreenMode = DECMode(1047) + + SetAltScreenMode = "\x1b[?1047h" + ResetAltScreenMode = "\x1b[?1047l" + RequestAltScreenMode = "\x1b[?1047$p" +) + +// Save Cursor Mode is a mode that saves the cursor position. +// This is equivalent to [SaveCursor] and [RestoreCursor]. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer +const ( + SaveCursorMode = DECMode(1048) + + SetSaveCursorMode = "\x1b[?1048h" + ResetSaveCursorMode = "\x1b[?1048l" + RequestSaveCursorMode = "\x1b[?1048$p" +) + +// Alternate Screen Save Cursor Mode is a mode that saves the cursor position as in +// [SaveCursorMode], switches to the alternate screen buffer as in [AltScreenMode], +// and clears the screen on switch. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer +const ( + AltScreenSaveCursorMode = DECMode(1049) + + SetAltScreenSaveCursorMode = "\x1b[?1049h" + ResetAltScreenSaveCursorMode = "\x1b[?1049l" + RequestAltScreenSaveCursorMode = "\x1b[?1049$p" +) + // Alternate Screen Buffer is a mode that determines whether the alternate screen // buffer is active. // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-The-Alternate-Screen-Buffer +// +// Deprecated: use [AltScreenSaveCursorMode] instead. const ( - AltScreenBufferMode = PrivateMode(1049) + AltScreenBufferMode = DECMode(1049) + + SetAltScreenBufferMode = "\x1b[?1049h" + ResetAltScreenBufferMode = "\x1b[?1049l" + RequestAltScreenBufferMode = "\x1b[?1049$p" EnableAltScreenBuffer = "\x1b[?1049h" DisableAltScreenBuffer = "\x1b[?1049l" @@ -151,8 +683,16 @@ const ( // See: https://cirw.in/blog/bracketed-paste // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode const ( - BracketedPasteMode = PrivateMode(2004) + BracketedPasteMode = DECMode(2004) + + SetBracketedPasteMode = "\x1b[?2004h" + ResetBracketedPasteMode = "\x1b[?2004l" + RequestBracketedPasteMode = "\x1b[?2004$p" +) +// Deprecated: use [SetBracketedPasteMode], [ResetBracketedPasteMode], and +// [RequestBracketedPasteMode] instead. +const ( EnableBracketedPaste = "\x1b[?2004h" DisableBracketedPaste = "\x1b[?2004l" RequestBracketedPaste = "\x1b[?2004$p" @@ -163,7 +703,17 @@ const ( // // See: https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036 const ( - SyncdOutputMode = PrivateMode(2026) + SynchronizedOutputMode = DECMode(2026) + + SetSynchronizedOutputMode = "\x1b[?2026h" + ResetSynchronizedOutputMode = "\x1b[?2026l" + RequestSynchronizedOutputMode = "\x1b[?2026$p" +) + +// Deprecated: use [SynchronizedOutputMode], [SetSynchronizedOutputMode], and +// [ResetSynchronizedOutputMode], and [RequestSynchronizedOutputMode] instead. +const ( + SyncdOutputMode = DECMode(2026) EnableSyncdOutput = "\x1b[?2026h" DisableSyncdOutput = "\x1b[?2026l" @@ -177,8 +727,16 @@ const ( // // See: https://github.com/contour-terminal/terminal-unicode-core const ( - GraphemeClusteringMode = PrivateMode(2027) + GraphemeClusteringMode = DECMode(2027) + + SetGraphemeClusteringMode = "\x1b[?2027h" + ResetGraphemeClusteringMode = "\x1b[?2027l" + RequestGraphemeClusteringMode = "\x1b[?2027$p" +) +// Deprecated: use [SetGraphemeClusteringMode], [ResetGraphemeClusteringMode], and +// [RequestGraphemeClusteringMode] instead. +const ( EnableGraphemeClustering = "\x1b[?2027h" DisableGraphemeClustering = "\x1b[?2027l" RequestGraphemeClustering = "\x1b[?2027$p" @@ -189,8 +747,16 @@ const ( // // See: https://github.com/microsoft/terminal/blob/main/doc/specs/%234999%20-%20Improved%20keyboard%20handling%20in%20Conpty.md const ( - Win32InputMode = PrivateMode(9001) + Win32InputMode = DECMode(9001) + SetWin32InputMode = "\x1b[?9001h" + ResetWin32InputMode = "\x1b[?9001l" + RequestWin32InputMode = "\x1b[?9001$p" +) + +// Deprecated: use [SetWin32InputMode], [ResetWin32InputMode], and +// [RequestWin32InputMode] instead. +const ( EnableWin32Input = "\x1b[?9001h" DisableWin32Input = "\x1b[?9001l" RequestWin32Input = "\x1b[?9001$p" diff --git a/source/vendor/github.com/charmbracelet/x/ansi/modes.go b/source/vendor/github.com/charmbracelet/x/ansi/modes.go new file mode 100644 index 0000000000000000000000000000000000000000..1bec5bc8070d4aa443372cce3f229026f14c2c61 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/modes.go @@ -0,0 +1,71 @@ +package ansi + +// Modes represents the terminal modes that can be set or reset. By default, +// all modes are [ModeNotRecognized]. +type Modes map[Mode]ModeSetting + +// NewModes creates a new Modes map. By default, all modes are +// [ModeNotRecognized]. +func NewModes() Modes { + return make(Modes) +} + +// Get returns the setting of a terminal mode. If the mode is not set, it +// returns [ModeNotRecognized]. +func (m Modes) Get(mode Mode) ModeSetting { + return m[mode] +} + +// Delete deletes a terminal mode. This has the same effect as setting the mode +// to [ModeNotRecognized]. +func (m Modes) Delete(mode Mode) { + delete(m, mode) +} + +// Set sets a terminal mode to [ModeSet]. +func (m Modes) Set(modes ...Mode) { + for _, mode := range modes { + m[mode] = ModeSet + } +} + +// PermanentlySet sets a terminal mode to [ModePermanentlySet]. +func (m Modes) PermanentlySet(modes ...Mode) { + for _, mode := range modes { + m[mode] = ModePermanentlySet + } +} + +// Reset sets a terminal mode to [ModeReset]. +func (m Modes) Reset(modes ...Mode) { + for _, mode := range modes { + m[mode] = ModeReset + } +} + +// PermanentlyReset sets a terminal mode to [ModePermanentlyReset]. +func (m Modes) PermanentlyReset(modes ...Mode) { + for _, mode := range modes { + m[mode] = ModePermanentlyReset + } +} + +// IsSet returns true if the mode is set to [ModeSet] or [ModePermanentlySet]. +func (m Modes) IsSet(mode Mode) bool { + return m[mode].IsSet() +} + +// IsPermanentlySet returns true if the mode is set to [ModePermanentlySet]. +func (m Modes) IsPermanentlySet(mode Mode) bool { + return m[mode].IsPermanentlySet() +} + +// IsReset returns true if the mode is set to [ModeReset] or [ModePermanentlyReset]. +func (m Modes) IsReset(mode Mode) bool { + return m[mode].IsReset() +} + +// IsPermanentlyReset returns true if the mode is set to [ModePermanentlyReset]. +func (m Modes) IsPermanentlyReset(mode Mode) bool { + return m[mode].IsPermanentlyReset() +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/mouse.go b/source/vendor/github.com/charmbracelet/x/ansi/mouse.go new file mode 100644 index 0000000000000000000000000000000000000000..95b0127fd9e6ca516b86efb1f2456019d78987fd --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/mouse.go @@ -0,0 +1,172 @@ +package ansi + +import ( + "fmt" +) + +// MouseButton represents the button that was pressed during a mouse message. +type MouseButton byte + +// Mouse event buttons +// +// This is based on X11 mouse button codes. +// +// 1 = left button +// 2 = middle button (pressing the scroll wheel) +// 3 = right button +// 4 = turn scroll wheel up +// 5 = turn scroll wheel down +// 6 = push scroll wheel left +// 7 = push scroll wheel right +// 8 = 4th button (aka browser backward button) +// 9 = 5th button (aka browser forward button) +// 10 +// 11 +// +// Other buttons are not supported. +const ( + MouseNone MouseButton = iota + MouseButton1 + MouseButton2 + MouseButton3 + MouseButton4 + MouseButton5 + MouseButton6 + MouseButton7 + MouseButton8 + MouseButton9 + MouseButton10 + MouseButton11 + + MouseLeft = MouseButton1 + MouseMiddle = MouseButton2 + MouseRight = MouseButton3 + MouseWheelUp = MouseButton4 + MouseWheelDown = MouseButton5 + MouseWheelLeft = MouseButton6 + MouseWheelRight = MouseButton7 + MouseBackward = MouseButton8 + MouseForward = MouseButton9 + MouseRelease = MouseNone +) + +var mouseButtons = map[MouseButton]string{ + MouseNone: "none", + MouseLeft: "left", + MouseMiddle: "middle", + MouseRight: "right", + MouseWheelUp: "wheelup", + MouseWheelDown: "wheeldown", + MouseWheelLeft: "wheelleft", + MouseWheelRight: "wheelright", + MouseBackward: "backward", + MouseForward: "forward", + MouseButton10: "button10", + MouseButton11: "button11", +} + +// String returns a string representation of the mouse button. +func (b MouseButton) String() string { + return mouseButtons[b] +} + +// EncodeMouseButton returns a byte representing a mouse button. +// The button is a bitmask of the following leftmost values: +// +// - The first two bits are the button number: +// 0 = left button, wheel up, or button no. 8 aka (backwards) +// 1 = middle button, wheel down, or button no. 9 aka (forwards) +// 2 = right button, wheel left, or button no. 10 +// 3 = release event, wheel right, or button no. 11 +// +// - The third bit indicates whether the shift key was pressed. +// +// - The fourth bit indicates the alt key was pressed. +// +// - The fifth bit indicates the control key was pressed. +// +// - The sixth bit indicates motion events. Combined with button number 3, i.e. +// release event, it represents a drag event. +// +// - The seventh bit indicates a wheel event. +// +// - The eighth bit indicates additional buttons. +// +// If button is [MouseNone], and motion is false, this returns a release event. +// If button is undefined, this function returns 0xff. +func EncodeMouseButton(b MouseButton, motion, shift, alt, ctrl bool) (m byte) { + // mouse bit shifts + const ( + bitShift = 0b0000_0100 + bitAlt = 0b0000_1000 + bitCtrl = 0b0001_0000 + bitMotion = 0b0010_0000 + bitWheel = 0b0100_0000 + bitAdd = 0b1000_0000 // additional buttons 8-11 + + bitsMask = 0b0000_0011 + ) + + if b == MouseNone { + m = bitsMask + } else if b >= MouseLeft && b <= MouseRight { + m = byte(b - MouseLeft) + } else if b >= MouseWheelUp && b <= MouseWheelRight { + m = byte(b - MouseWheelUp) + m |= bitWheel + } else if b >= MouseBackward && b <= MouseButton11 { + m = byte(b - MouseBackward) + m |= bitAdd + } else { + m = 0xff // invalid button + } + + if shift { + m |= bitShift + } + if alt { + m |= bitAlt + } + if ctrl { + m |= bitCtrl + } + if motion { + m |= bitMotion + } + + return +} + +// x10Offset is the offset for X10 mouse events. +// See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking +const x10Offset = 32 + +// MouseX10 returns an escape sequence representing a mouse event in X10 mode. +// Note that this requires the terminal support X10 mouse modes. +// +// CSI M Cb Cx Cy +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking +func MouseX10(b byte, x, y int) string { + return "\x1b[M" + string(b+x10Offset) + string(byte(x)+x10Offset+1) + string(byte(y)+x10Offset+1) +} + +// MouseSgr returns an escape sequence representing a mouse event in SGR mode. +// +// CSI < Cb ; Cx ; Cy M +// CSI < Cb ; Cx ; Cy m (release) +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Mouse%20Tracking +func MouseSgr(b byte, x, y int, release bool) string { + s := 'M' + if release { + s = 'm' + } + if x < 0 { + x = -x + } + if y < 0 { + y = -y + } + return fmt.Sprintf("\x1b[<%d;%d;%d%c", b, x+1, y+1, s) +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/notification.go b/source/vendor/github.com/charmbracelet/x/ansi/notification.go index 4943366f5348940fb47e630f2cb2e8a098a9887f..c712f34059fe59f5c76a6a2a715ce36cb2b12c63 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/notification.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/notification.go @@ -2,8 +2,8 @@ package ansi // Notify sends a desktop notification using iTerm's OSC 9. // -// OSC 9 ; Mc ST -// OSC 9 ; Mc BEL +// OSC 9 ; Mc ST +// OSC 9 ; Mc BEL // // Where Mc is the notification body. // diff --git a/source/vendor/github.com/charmbracelet/x/ansi/osc.go b/source/vendor/github.com/charmbracelet/x/ansi/osc.go deleted file mode 100644 index 40b543c2940029cf70db8015c1c0754f09c5b3bf..0000000000000000000000000000000000000000 --- a/source/vendor/github.com/charmbracelet/x/ansi/osc.go +++ /dev/null @@ -1,69 +0,0 @@ -package ansi - -import ( - "bytes" - "strings" -) - -// OscSequence represents an OSC sequence. -// -// The sequence starts with a OSC sequence, OSC (0x9D) in a 8-bit environment -// or ESC ] (0x1B 0x5D) in a 7-bit environment, followed by positive integer identifier, -// then by arbitrary data terminated by a ST (0x9C) in a 8-bit environment, -// ESC \ (0x1B 0x5C) in a 7-bit environment, or BEL (0x07) for backwards compatibility. -// -// OSC Ps ; Pt ST -// OSC Ps ; Pt BEL -// -// See ECMA-48 § 5.7. -type OscSequence struct { - // Data contains the raw data of the sequence including the identifier - // command. - Data []byte - - // Cmd contains the raw command of the sequence. - Cmd int -} - -var _ Sequence = OscSequence{} - -// Command returns the command of the OSC sequence. -func (s OscSequence) Command() int { - return s.Cmd -} - -// Params returns the parameters of the OSC sequence split by ';'. -// The first element is the identifier command. -func (s OscSequence) Params() []string { - return strings.Split(string(s.Data), ";") -} - -// Clone returns a copy of the OSC sequence. -func (s OscSequence) Clone() Sequence { - return OscSequence{ - Data: append([]byte(nil), s.Data...), - Cmd: s.Cmd, - } -} - -// String returns the string representation of the OSC sequence. -// To be more compatible with different terminal, this will always return a -// 7-bit formatted sequence, terminated by BEL. -func (s OscSequence) String() string { - return s.buffer().String() -} - -// Bytes returns the byte representation of the OSC sequence. -// To be more compatible with different terminal, this will always return a -// 7-bit formatted sequence, terminated by BEL. -func (s OscSequence) Bytes() []byte { - return s.buffer().Bytes() -} - -func (s OscSequence) buffer() *bytes.Buffer { - var b bytes.Buffer - b.WriteString("\x1b]") - b.Write(s.Data) - b.WriteByte(BEL) - return &b -} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/params.go b/source/vendor/github.com/charmbracelet/x/ansi/params.go deleted file mode 100644 index a1bb42498c5d53f97c57377bbd2533bdcab7c68d..0000000000000000000000000000000000000000 --- a/source/vendor/github.com/charmbracelet/x/ansi/params.go +++ /dev/null @@ -1,45 +0,0 @@ -package ansi - -import ( - "bytes" -) - -// Params parses and returns a list of control sequence parameters. -// -// Parameters are positive integers separated by semicolons. Empty parameters -// default to zero. Parameters can have sub-parameters separated by colons. -// -// Any non-parameter bytes are ignored. This includes bytes that are not in the -// range of 0x30-0x3B. -// -// See ECMA-48 § 5.4.1. -func Params(p []byte) [][]uint { - if len(p) == 0 { - return [][]uint{} - } - - // Filter out non-parameter bytes i.e. non 0x30-0x3B. - p = bytes.TrimFunc(p, func(r rune) bool { - return r < 0x30 || r > 0x3B - }) - - parts := bytes.Split(p, []byte{';'}) - params := make([][]uint, len(parts)) - for i, part := range parts { - sparts := bytes.Split(part, []byte{':'}) - params[i] = make([]uint, len(sparts)) - for j, spart := range sparts { - params[i][j] = bytesToUint16(spart) - } - } - - return params -} - -func bytesToUint16(b []byte) uint { - var n uint - for _, c := range b { - n = n*10 + uint(c-'0') - } - return n -} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/parser.go b/source/vendor/github.com/charmbracelet/x/ansi/parser.go index e1a09df70f042a53491e60f5f51dc7c9ad70ed41..882e1ed7a0aced3a5b7acd270c2f3b1e2aefb389 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/parser.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/parser.go @@ -7,9 +7,6 @@ import ( "github.com/charmbracelet/x/ansi/parser" ) -// ParserDispatcher is a function that dispatches a sequence. -type ParserDispatcher func(Sequence) - // Parser represents a DEC ANSI compatible sequence parser. // // It uses a state machine to parse ANSI escape sequences and control @@ -20,130 +17,194 @@ type ParserDispatcher func(Sequence) // //go:generate go run ./gen.go type Parser struct { - // Params contains the raw parameters of the sequence. + handler Handler + + // params contains the raw parameters of the sequence. // These parameters used when constructing CSI and DCS sequences. - Params []int + params []int - // Data contains the raw data of the sequence. + // data contains the raw data of the sequence. // These data used when constructing OSC, DCS, SOS, PM, and APC sequences. - Data []byte + data []byte - // DataLen keeps track of the length of the data buffer. - // If DataLen is -1, the data buffer is unlimited and will grow as needed. - // Otherwise, DataLen is limited by the size of the Data buffer. - DataLen int + // dataLen keeps track of the length of the data buffer. + // If dataLen is -1, the data buffer is unlimited and will grow as needed. + // Otherwise, dataLen is limited by the size of the data buffer. + dataLen int - // ParamsLen keeps track of the number of parameters. - // This is limited by the size of the Params buffer. + // paramsLen keeps track of the number of parameters. + // This is limited by the size of the params buffer. // // This is also used when collecting UTF-8 runes to keep track of the // number of rune bytes collected. - ParamsLen int + paramsLen int - // Cmd contains the raw command along with the private marker and + // cmd contains the raw command along with the private prefix and // intermediate bytes of the sequence. // The first lower byte contains the command byte, the next byte contains - // the private marker, and the next byte contains the intermediate byte. + // the private prefix, and the next byte contains the intermediate byte. // // This is also used when collecting UTF-8 runes treating it as a slice of // 4 bytes. - Cmd int + cmd int + + // state is the current state of the parser. + state byte +} + +// NewParser returns a new parser with the default settings. +// The [Parser] uses a default size of 32 for the parameters and 64KB for the +// data buffer. Use [Parser.SetParamsSize] and [Parser.SetDataSize] to set the +// size of the parameters and data buffer respectively. +func NewParser() *Parser { + p := new(Parser) + p.SetParamsSize(parser.MaxParamsSize) + p.SetDataSize(1024 * 64) // 64KB data buffer + return p +} - // State is the current state of the parser. - State byte +// SetParamsSize sets the size of the parameters buffer. +// This is used when constructing CSI and DCS sequences. +func (p *Parser) SetParamsSize(size int) { + p.params = make([]int, size) } -// NewParser returns a new parser with the given sizes allocated. -// If dataSize is zero, the underlying data buffer will be unlimited and will +// SetDataSize sets the size of the data buffer. +// This is used when constructing OSC, DCS, SOS, PM, and APC sequences. +// If size is less than or equal to 0, the data buffer is unlimited and will // grow as needed. -func NewParser(paramsSize, dataSize int) *Parser { - s := new(Parser) - if dataSize <= 0 { - dataSize = 0 - s.DataLen = -1 +func (p *Parser) SetDataSize(size int) { + if size <= 0 { + size = 0 + p.dataLen = -1 + } + p.data = make([]byte, size) +} + +// Params returns the list of parsed packed parameters. +func (p *Parser) Params() Params { + return unsafe.Slice((*Param)(unsafe.Pointer(&p.params[0])), p.paramsLen) +} + +// Param returns the parameter at the given index and falls back to the default +// value if the parameter is missing. If the index is out of bounds, it returns +// the default value and false. +func (p *Parser) Param(i, def int) (int, bool) { + if i < 0 || i >= p.paramsLen { + return def, false + } + return Param(p.params[i]).Param(def), true +} + +// Command returns the packed command of the last dispatched sequence. Use +// [Cmd] to unpack the command. +func (p *Parser) Command() int { + return p.cmd +} + +// Rune returns the last dispatched sequence as a rune. +func (p *Parser) Rune() rune { + rw := utf8ByteLen(byte(p.cmd & 0xff)) + if rw == -1 { + return utf8.RuneError } - s.Params = make([]int, paramsSize) - s.Data = make([]byte, dataSize) - return s + r, _ := utf8.DecodeRune((*[utf8.UTFMax]byte)(unsafe.Pointer(&p.cmd))[:rw]) + return r +} + +// Control returns the last dispatched sequence as a control code. +func (p *Parser) Control() byte { + return byte(p.cmd & 0xff) +} + +// Data returns the raw data of the last dispatched sequence. +func (p *Parser) Data() []byte { + return p.data[:p.dataLen] } // Reset resets the parser to its initial state. func (p *Parser) Reset() { p.clear() - p.State = parser.GroundState + p.state = parser.GroundState } // clear clears the parser parameters and command. func (p *Parser) clear() { - if len(p.Params) > 0 { - p.Params[0] = parser.MissingParam + if len(p.params) > 0 { + p.params[0] = parser.MissingParam } - p.ParamsLen = 0 - p.Cmd = 0 + p.paramsLen = 0 + p.cmd = 0 +} + +// State returns the current state of the parser. +func (p *Parser) State() parser.State { + return p.state } // StateName returns the name of the current state. func (p *Parser) StateName() string { - return parser.StateNames[p.State] + return parser.StateNames[p.state] } // Parse parses the given dispatcher and byte buffer. -func (p *Parser) Parse(dispatcher ParserDispatcher, b []byte) { +// Deprecated: Loop over the buffer and call [Parser.Advance] instead. +func (p *Parser) Parse(b []byte) { for i := 0; i < len(b); i++ { - p.Advance(dispatcher, b[i], i < len(b)-1) + p.Advance(b[i]) } } -// Advance advances the parser with the given dispatcher and byte. -func (p *Parser) Advance(dispatcher ParserDispatcher, b byte, more bool) parser.Action { - switch p.State { +// Advance advances the parser using the given byte. It returns the action +// performed by the parser. +func (p *Parser) Advance(b byte) parser.Action { + switch p.state { case parser.Utf8State: // We handle UTF-8 here. - return p.advanceUtf8(dispatcher, b) + return p.advanceUtf8(b) default: - return p.advance(dispatcher, b, more) + return p.advance(b) } } func (p *Parser) collectRune(b byte) { - if p.ParamsLen >= utf8.UTFMax { + if p.paramsLen >= utf8.UTFMax { return } - shift := p.ParamsLen * 8 - p.Cmd &^= 0xff << shift - p.Cmd |= int(b) << shift - p.ParamsLen++ + shift := p.paramsLen * 8 + p.cmd &^= 0xff << shift + p.cmd |= int(b) << shift + p.paramsLen++ } -func (p *Parser) advanceUtf8(dispatcher ParserDispatcher, b byte) parser.Action { +func (p *Parser) advanceUtf8(b byte) parser.Action { // Collect UTF-8 rune bytes. p.collectRune(b) - rw := utf8ByteLen(byte(p.Cmd & 0xff)) + rw := utf8ByteLen(byte(p.cmd & 0xff)) if rw == -1 { // We panic here because the first byte comes from the state machine, // if this panics, it means there is a bug in the state machine! panic("invalid rune") // unreachable } - if p.ParamsLen < rw { + if p.paramsLen < rw { return parser.CollectAction } // We have enough bytes to decode the rune using unsafe - r, _ := utf8.DecodeRune((*[utf8.UTFMax]byte)(unsafe.Pointer(&p.Cmd))[:rw]) - if dispatcher != nil { - dispatcher(Rune(r)) + if p.handler.Print != nil { + p.handler.Print(p.Rune()) } - p.State = parser.GroundState - p.ParamsLen = 0 + p.state = parser.GroundState + p.paramsLen = 0 return parser.PrintAction } -func (p *Parser) advance(d ParserDispatcher, b byte, more bool) parser.Action { - state, action := parser.Table.Transition(p.State, b) +func (p *Parser) advance(b byte) parser.Action { + state, action := parser.Table.Transition(p.state, b) // We need to clear the parser state if the state changes from EscapeState. // This is because when we enter the EscapeState, we don't get a chance to @@ -151,59 +212,53 @@ func (p *Parser) advance(d ParserDispatcher, b byte, more bool) parser.Action { // ST (\x1b\\ or \x9c), we dispatch the current sequence and transition to // EscapeState. However, the parser state is not cleared in this case and // we need to clear it here before dispatching the esc sequence. - if p.State != state { - if p.State == parser.EscapeState { - p.performAction(d, parser.ClearAction, state, b) + if p.state != state { + if p.state == parser.EscapeState { + p.performAction(parser.ClearAction, state, b) } if action == parser.PutAction && - p.State == parser.DcsEntryState && state == parser.DcsStringState { + p.state == parser.DcsEntryState && state == parser.DcsStringState { // XXX: This is a special case where we need to start collecting // non-string parameterized data i.e. doesn't follow the ECMA-48 § // 5.4.1 string parameters format. - p.performAction(d, parser.StartAction, state, 0) + p.performAction(parser.StartAction, state, 0) } } // Handle special cases switch { - case b == ESC && p.State == parser.EscapeState: + case b == ESC && p.state == parser.EscapeState: // Two ESCs in a row - p.performAction(d, parser.ExecuteAction, state, b) - if !more { - // Two ESCs at the end of the buffer - p.performAction(d, parser.ExecuteAction, state, b) - } - case b == ESC && !more: - // Last byte is an ESC - p.performAction(d, parser.ExecuteAction, state, b) - case p.State == parser.EscapeState && b == 'P' && !more: - // ESC P (DCS) at the end of the buffer - p.performAction(d, parser.DispatchAction, state, b) - case p.State == parser.EscapeState && b == 'X' && !more: - // ESC X (SOS) at the end of the buffer - p.performAction(d, parser.DispatchAction, state, b) - case p.State == parser.EscapeState && b == '[' && !more: - // ESC [ (CSI) at the end of the buffer - p.performAction(d, parser.DispatchAction, state, b) - case p.State == parser.EscapeState && b == ']' && !more: - // ESC ] (OSC) at the end of the buffer - p.performAction(d, parser.DispatchAction, state, b) - case p.State == parser.EscapeState && b == '^' && !more: - // ESC ^ (PM) at the end of the buffer - p.performAction(d, parser.DispatchAction, state, b) - case p.State == parser.EscapeState && b == '_' && !more: - // ESC _ (APC) at the end of the buffer - p.performAction(d, parser.DispatchAction, state, b) + p.performAction(parser.ExecuteAction, state, b) default: - p.performAction(d, action, state, b) + p.performAction(action, state, b) } - p.State = state + p.state = state return action } -func (p *Parser) performAction(dispatcher ParserDispatcher, action parser.Action, state parser.State, b byte) { +func (p *Parser) parseStringCmd() { + // Try to parse the command + datalen := len(p.data) + if p.dataLen >= 0 { + datalen = p.dataLen + } + for i := 0; i < datalen; i++ { + d := p.data[i] + if d < '0' || d > '9' { + break + } + if p.cmd == parser.MissingCommand { + p.cmd = 0 + } + p.cmd *= 10 + p.cmd += int(d - '0') + } +} + +func (p *Parser) performAction(action parser.Action, state parser.State, b byte) { switch action { case parser.IgnoreAction: break @@ -212,140 +267,139 @@ func (p *Parser) performAction(dispatcher ParserDispatcher, action parser.Action p.clear() case parser.PrintAction: - if dispatcher != nil { - dispatcher(Rune(b)) + p.cmd = int(b) + if p.handler.Print != nil { + p.handler.Print(rune(b)) } case parser.ExecuteAction: - if dispatcher != nil { - dispatcher(ControlCode(b)) + p.cmd = int(b) + if p.handler.Execute != nil { + p.handler.Execute(b) } - case parser.MarkerAction: - // Collect private marker - // we only store the last marker - p.Cmd &^= 0xff << parser.MarkerShift - p.Cmd |= int(b) << parser.MarkerShift + case parser.PrefixAction: + // Collect private prefix + // we only store the last prefix + p.cmd &^= 0xff << parser.PrefixShift + p.cmd |= int(b) << parser.PrefixShift case parser.CollectAction: if state == parser.Utf8State { // Reset the UTF-8 counter - p.ParamsLen = 0 + p.paramsLen = 0 p.collectRune(b) } else { // Collect intermediate bytes // we only store the last intermediate byte - p.Cmd &^= 0xff << parser.IntermedShift - p.Cmd |= int(b) << parser.IntermedShift + p.cmd &^= 0xff << parser.IntermedShift + p.cmd |= int(b) << parser.IntermedShift } case parser.ParamAction: // Collect parameters - if p.ParamsLen >= len(p.Params) { + if p.paramsLen >= len(p.params) { break } if b >= '0' && b <= '9' { - if p.Params[p.ParamsLen] == parser.MissingParam { - p.Params[p.ParamsLen] = 0 + if p.params[p.paramsLen] == parser.MissingParam { + p.params[p.paramsLen] = 0 } - p.Params[p.ParamsLen] *= 10 - p.Params[p.ParamsLen] += int(b - '0') + p.params[p.paramsLen] *= 10 + p.params[p.paramsLen] += int(b - '0') } if b == ':' { - p.Params[p.ParamsLen] |= parser.HasMoreFlag + p.params[p.paramsLen] |= parser.HasMoreFlag } if b == ';' || b == ':' { - p.ParamsLen++ - if p.ParamsLen < len(p.Params) { - p.Params[p.ParamsLen] = parser.MissingParam + p.paramsLen++ + if p.paramsLen < len(p.params) { + p.params[p.paramsLen] = parser.MissingParam } } case parser.StartAction: - if p.DataLen < 0 && p.Data != nil { - p.Data = p.Data[:0] + if p.dataLen < 0 && p.data != nil { + p.data = p.data[:0] } else { - p.DataLen = 0 + p.dataLen = 0 } - if p.State >= parser.DcsEntryState && p.State <= parser.DcsStringState { + if p.state >= parser.DcsEntryState && p.state <= parser.DcsStringState { // Collect the command byte for DCS - p.Cmd |= int(b) + p.cmd |= int(b) } else { - p.Cmd = parser.MissingCommand + p.cmd = parser.MissingCommand } case parser.PutAction: - switch p.State { + switch p.state { case parser.OscStringState: - if b == ';' && p.Cmd == parser.MissingCommand { - // Try to parse the command - datalen := len(p.Data) - if p.DataLen >= 0 { - datalen = p.DataLen - } - for i := 0; i < datalen; i++ { - d := p.Data[i] - if d < '0' || d > '9' { - break - } - if p.Cmd == parser.MissingCommand { - p.Cmd = 0 - } - p.Cmd *= 10 - p.Cmd += int(d - '0') - } + if b == ';' && p.cmd == parser.MissingCommand { + p.parseStringCmd() } } - if p.DataLen < 0 { - p.Data = append(p.Data, b) + if p.dataLen < 0 { + p.data = append(p.data, b) } else { - if p.DataLen < len(p.Data) { - p.Data[p.DataLen] = b - p.DataLen++ + if p.dataLen < len(p.data) { + p.data[p.dataLen] = b + p.dataLen++ } } case parser.DispatchAction: // Increment the last parameter - if p.ParamsLen > 0 && p.ParamsLen < len(p.Params)-1 || - p.ParamsLen == 0 && len(p.Params) > 0 && p.Params[0] != parser.MissingParam { - p.ParamsLen++ + if p.paramsLen > 0 && p.paramsLen < len(p.params)-1 || + p.paramsLen == 0 && len(p.params) > 0 && p.params[0] != parser.MissingParam { + p.paramsLen++ } - if dispatcher == nil { - break + if p.state == parser.OscStringState && p.cmd == parser.MissingCommand { + // Ensure we have a command for OSC + p.parseStringCmd() } - var seq Sequence - data := p.Data - if p.DataLen >= 0 { - data = data[:p.DataLen] + data := p.data + if p.dataLen >= 0 { + data = data[:p.dataLen] } - switch p.State { + switch p.state { case parser.CsiEntryState, parser.CsiParamState, parser.CsiIntermediateState: - p.Cmd |= int(b) - seq = CsiSequence{Cmd: p.Cmd, Params: p.Params[:p.ParamsLen]} + p.cmd |= int(b) + if p.handler.HandleCsi != nil { + p.handler.HandleCsi(Cmd(p.cmd), p.Params()) + } case parser.EscapeState, parser.EscapeIntermediateState: - p.Cmd |= int(b) - seq = EscSequence(p.Cmd) + p.cmd |= int(b) + if p.handler.HandleEsc != nil { + p.handler.HandleEsc(Cmd(p.cmd)) + } case parser.DcsEntryState, parser.DcsParamState, parser.DcsIntermediateState, parser.DcsStringState: - seq = DcsSequence{Cmd: p.Cmd, Params: p.Params[:p.ParamsLen], Data: data} + if p.handler.HandleDcs != nil { + p.handler.HandleDcs(Cmd(p.cmd), p.Params(), data) + } case parser.OscStringState: - seq = OscSequence{Cmd: p.Cmd, Data: data} + if p.handler.HandleOsc != nil { + p.handler.HandleOsc(p.cmd, data) + } case parser.SosStringState: - seq = SosSequence{Data: data} + if p.handler.HandleSos != nil { + p.handler.HandleSos(data) + } case parser.PmStringState: - seq = PmSequence{Data: data} + if p.handler.HandlePm != nil { + p.handler.HandlePm(data) + } case parser.ApcStringState: - seq = ApcSequence{Data: data} + if p.handler.HandleApc != nil { + p.handler.HandleApc(data) + } } - - dispatcher(seq) } } diff --git a/source/vendor/github.com/charmbracelet/x/ansi/parser/const.go b/source/vendor/github.com/charmbracelet/x/ansi/parser/const.go index 54b7383b44b3a6d96d2e2d4bb2fe4da79aefc4c3..d62dbf379eca38cb7fec3dfcea71277c5a0b6409 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/parser/const.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/parser/const.go @@ -8,7 +8,7 @@ const ( NoneAction Action = iota ClearAction CollectAction - MarkerAction + PrefixAction DispatchAction ExecuteAction StartAction // Start of a data string @@ -24,7 +24,7 @@ var ActionNames = []string{ "NoneAction", "ClearAction", "CollectAction", - "MarkerAction", + "PrefixAction", "DispatchAction", "ExecuteAction", "StartAction", diff --git a/source/vendor/github.com/charmbracelet/x/ansi/parser/seq.go b/source/vendor/github.com/charmbracelet/x/ansi/parser/seq.go index c99f1632f7e2f26782bb9f001a60f6992b076782..29f491d1c484e501446daaaca3635676f79ad930 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/parser/seq.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/parser/seq.go @@ -4,9 +4,9 @@ import "math" // Shift and masks for sequence parameters and intermediates. const ( - MarkerShift = 8 + PrefixShift = 8 IntermedShift = 16 - CommandMask = 0xff + FinalMask = 0xff HasMoreFlag = math.MinInt32 ParamMask = ^HasMoreFlag MissingParam = ParamMask @@ -22,12 +22,12 @@ const ( DefaultParamValue = 0 ) -// Marker returns the marker byte of the sequence. +// Prefix returns the prefix byte of the sequence. // This is always gonna be one of the following '<' '=' '>' '?' and in the // range of 0x3C-0x3F. -// Zero is returned if the sequence does not have a marker. -func Marker(cmd int) int { - return (cmd >> MarkerShift) & CommandMask +// Zero is returned if the sequence does not have a prefix. +func Prefix(cmd int) int { + return (cmd >> PrefixShift) & FinalMask } // Intermediate returns the intermediate byte of the sequence. @@ -36,12 +36,12 @@ func Marker(cmd int) int { // ',', '-', '.', '/'. // Zero is returned if the sequence does not have an intermediate byte. func Intermediate(cmd int) int { - return (cmd >> IntermedShift) & CommandMask + return (cmd >> IntermedShift) & FinalMask } // Command returns the command byte of the CSI sequence. func Command(cmd int) int { - return cmd & CommandMask + return cmd & FinalMask } // Param returns the parameter at the given index. diff --git a/source/vendor/github.com/charmbracelet/x/ansi/parser/transition_table.go b/source/vendor/github.com/charmbracelet/x/ansi/parser/transition_table.go index 5d368ebf133f01f95acbce1858e74500f9f389de..558a5eaccab4ca0973fbbcb4650aeeefc596a2ae 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/parser/transition_table.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/parser/transition_table.go @@ -178,7 +178,7 @@ func GenerateTransitionTable() TransitionTable { table.AddRange(0x20, 0x2F, DcsEntryState, CollectAction, DcsIntermediateState) // Dcs_entry -> Dcs_param table.AddRange(0x30, 0x3B, DcsEntryState, ParamAction, DcsParamState) - table.AddRange(0x3C, 0x3F, DcsEntryState, MarkerAction, DcsParamState) + table.AddRange(0x3C, 0x3F, DcsEntryState, PrefixAction, DcsParamState) // Dcs_entry -> Dcs_passthrough table.AddRange(0x08, 0x0D, DcsEntryState, PutAction, DcsStringState) // Follows ECMA-48 § 8.3.27 // XXX: allows passing ESC (not a ECMA-48 standard) this to allow for @@ -254,7 +254,7 @@ func GenerateTransitionTable() TransitionTable { table.AddRange(0x20, 0x2F, CsiEntryState, CollectAction, CsiIntermediateState) // Csi_entry -> Csi_param table.AddRange(0x30, 0x3B, CsiEntryState, ParamAction, CsiParamState) - table.AddRange(0x3C, 0x3F, CsiEntryState, MarkerAction, CsiParamState) + table.AddRange(0x3C, 0x3F, CsiEntryState, PrefixAction, CsiParamState) // Osc_string table.AddRange(0x00, 0x06, OscStringState, IgnoreAction, OscStringState) diff --git a/source/vendor/github.com/charmbracelet/x/ansi/parser_decode.go b/source/vendor/github.com/charmbracelet/x/ansi/parser_decode.go index 0ed802cbcfc34cb553c650e167ab6f54f1735e43..3e504739477a39237ae7f78679fa7ccb709c4ac8 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/parser_decode.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/parser_decode.go @@ -1,11 +1,10 @@ package ansi import ( - "bytes" - "strings" "unicode/utf8" "github.com/charmbracelet/x/ansi/parser" + "github.com/mattn/go-runewidth" "github.com/rivo/uniseg" ) @@ -16,7 +15,7 @@ type State = byte // ANSI escape sequence states used by [DecodeSequence]. const ( NormalState State = iota - MarkerState + PrefixState ParamsState IntermedState EscapeState @@ -35,9 +34,9 @@ const ( // // Passing a non-nil [*Parser] as the last argument will allow the decoder to // collect sequence parameters, data, and commands. The parser cmd will have -// the packed command value that contains intermediate and marker characters. +// the packed command value that contains intermediate and prefix characters. // In the case of a OSC sequence, the cmd will be the OSC command number. Use -// [Cmd] and [Param] types to unpack command intermediates and markers as well +// [Cmd] and [Param] types to unpack command intermediates and prefixes as well // as parameters. // // Zero [Cmd] means the CSI, DCS, or ESC sequence is invalid. Moreover, checking the @@ -45,12 +44,12 @@ const ( // the returned sequence terminator bytes such as ST (ESC \\) and BEL). // // We store the command byte in [Cmd] in the most significant byte, the -// marker byte in the next byte, and the intermediate byte in the least +// prefix byte in the next byte, and the intermediate byte in the least // significant byte. This is done to avoid using a struct to store the command -// and its intermediates and markers. The command byte is always the least +// and its intermediates and prefixes. The command byte is always the least // significant byte i.e. [Cmd & 0xff]. Use the [Cmd] type to unpack the -// command, intermediate, and marker bytes. Note that we only collect the last -// marker character and intermediate byte. +// command, intermediate, and prefix bytes. Note that we only collect the last +// prefix character and intermediate byte. // // The [p.Params] slice will contain the parameters of the sequence. Any // sub-parameter will have the [parser.HasMoreFlag] set. Use the [Param] type @@ -67,7 +66,63 @@ const ( // state = newState // input = input[n:] // } +// +// This function treats the text as a sequence of grapheme clusters. func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width int, n int, newState byte) { + return decodeSequence(GraphemeWidth, b, state, p) +} + +// DecodeSequenceWc decodes the first ANSI escape sequence or a printable +// grapheme from the given data. It returns the sequence slice, the number of +// bytes read, the cell width for each sequence, and the new state. +// +// The cell width will always be 0 for control and escape sequences, 1 for +// ASCII printable characters, and the number of cells other Unicode characters +// occupy. It uses the uniseg package to calculate the width of Unicode +// graphemes and characters. This means it will always do grapheme clustering +// (mode 2027). +// +// Passing a non-nil [*Parser] as the last argument will allow the decoder to +// collect sequence parameters, data, and commands. The parser cmd will have +// the packed command value that contains intermediate and prefix characters. +// In the case of a OSC sequence, the cmd will be the OSC command number. Use +// [Cmd] and [Param] types to unpack command intermediates and prefixes as well +// as parameters. +// +// Zero [Cmd] means the CSI, DCS, or ESC sequence is invalid. Moreover, checking the +// validity of other data sequences, OSC, DCS, etc, will require checking for +// the returned sequence terminator bytes such as ST (ESC \\) and BEL). +// +// We store the command byte in [Cmd] in the most significant byte, the +// prefix byte in the next byte, and the intermediate byte in the least +// significant byte. This is done to avoid using a struct to store the command +// and its intermediates and prefixes. The command byte is always the least +// significant byte i.e. [Cmd & 0xff]. Use the [Cmd] type to unpack the +// command, intermediate, and prefix bytes. Note that we only collect the last +// prefix character and intermediate byte. +// +// The [p.Params] slice will contain the parameters of the sequence. Any +// sub-parameter will have the [parser.HasMoreFlag] set. Use the [Param] type +// to unpack the parameters. +// +// Example: +// +// var state byte // the initial state is always zero [NormalState] +// p := NewParser(32, 1024) // create a new parser with a 32 params buffer and 1024 data buffer (optional) +// input := []byte("\x1b[31mHello, World!\x1b[0m") +// for len(input) > 0 { +// seq, width, n, newState := DecodeSequenceWc(input, state, p) +// log.Printf("seq: %q, width: %d", seq, width) +// state = newState +// input = input[n:] +// } +// +// This function treats the text as a sequence of wide characters and runes. +func DecodeSequenceWc[T string | []byte](b T, state byte, p *Parser) (seq T, width int, n int, newState byte) { + return decodeSequence(WcWidth, b, state, p) +} + +func decodeSequence[T string | []byte](m Method, b T, state State, p *Parser) (seq T, width int, n int, newState byte) { for i := 0; i < len(b); i++ { c := b[i] @@ -76,39 +131,39 @@ func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width switch c { case ESC: if p != nil { - if len(p.Params) > 0 { - p.Params[0] = parser.MissingParam + if len(p.params) > 0 { + p.params[0] = parser.MissingParam } - p.Cmd = 0 - p.ParamsLen = 0 - p.DataLen = 0 + p.cmd = 0 + p.paramsLen = 0 + p.dataLen = 0 } state = EscapeState continue case CSI, DCS: if p != nil { - if len(p.Params) > 0 { - p.Params[0] = parser.MissingParam + if len(p.params) > 0 { + p.params[0] = parser.MissingParam } - p.Cmd = 0 - p.ParamsLen = 0 - p.DataLen = 0 + p.cmd = 0 + p.paramsLen = 0 + p.dataLen = 0 } - state = MarkerState + state = PrefixState continue case OSC, APC, SOS, PM: if p != nil { - p.Cmd = parser.MissingCommand - p.DataLen = 0 + p.cmd = parser.MissingCommand + p.dataLen = 0 } state = StringState continue } if p != nil { - p.DataLen = 0 - p.ParamsLen = 0 - p.Cmd = 0 + p.dataLen = 0 + p.paramsLen = 0 + p.cmd = 0 } if c > US && c < DEL { // ASCII printable characters @@ -122,18 +177,21 @@ func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width if utf8.RuneStart(c) { seq, _, width, _ = FirstGraphemeCluster(b, -1) + if m == WcWidth { + width = runewidth.StringWidth(string(seq)) + } i += len(seq) return b[:i], width, i, NormalState } // Invalid UTF-8 sequence return b[:i], 0, i, NormalState - case MarkerState: + case PrefixState: if c >= '<' && c <= '?' { if p != nil { - // We only collect the last marker character. - p.Cmd &^= 0xff << parser.MarkerShift - p.Cmd |= int(c) << parser.MarkerShift + // We only collect the last prefix character. + p.cmd &^= 0xff << parser.PrefixShift + p.cmd |= int(c) << parser.PrefixShift } break } @@ -143,27 +201,27 @@ func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width case ParamsState: if c >= '0' && c <= '9' { if p != nil { - if p.Params[p.ParamsLen] == parser.MissingParam { - p.Params[p.ParamsLen] = 0 + if p.params[p.paramsLen] == parser.MissingParam { + p.params[p.paramsLen] = 0 } - p.Params[p.ParamsLen] *= 10 - p.Params[p.ParamsLen] += int(c - '0') + p.params[p.paramsLen] *= 10 + p.params[p.paramsLen] += int(c - '0') } break } if c == ':' { if p != nil { - p.Params[p.ParamsLen] |= parser.HasMoreFlag + p.params[p.paramsLen] |= parser.HasMoreFlag } } if c == ';' || c == ':' { if p != nil { - p.ParamsLen++ - if p.ParamsLen < len(p.Params) { - p.Params[p.ParamsLen] = parser.MissingParam + p.paramsLen++ + if p.paramsLen < len(p.params) { + p.params[p.paramsLen] = parser.MissingParam } } break @@ -174,35 +232,36 @@ func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width case IntermedState: if c >= ' ' && c <= '/' { if p != nil { - p.Cmd &^= 0xff << parser.IntermedShift - p.Cmd |= int(c) << parser.IntermedShift + p.cmd &^= 0xff << parser.IntermedShift + p.cmd |= int(c) << parser.IntermedShift } break } - state = NormalState + if p != nil { + // Increment the last parameter + if p.paramsLen > 0 && p.paramsLen < len(p.params)-1 || + p.paramsLen == 0 && len(p.params) > 0 && p.params[0] != parser.MissingParam { + p.paramsLen++ + } + } + if c >= '@' && c <= '~' { if p != nil { - // Increment the last parameter - if p.ParamsLen > 0 && p.ParamsLen < len(p.Params)-1 || - p.ParamsLen == 0 && len(p.Params) > 0 && p.Params[0] != parser.MissingParam { - p.ParamsLen++ - } - - p.Cmd &^= 0xff - p.Cmd |= int(c) + p.cmd &^= 0xff + p.cmd |= int(c) } if HasDcsPrefix(b) { // Continue to collect DCS data if p != nil { - p.DataLen = 0 + p.dataLen = 0 } state = StringState continue } - return b[:i+1], 0, i + 1, state + return b[:i+1], 0, i + 1, NormalState } // Invalid CSI/DCS sequence @@ -211,18 +270,18 @@ func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width switch c { case '[', 'P': if p != nil { - if len(p.Params) > 0 { - p.Params[0] = parser.MissingParam + if len(p.params) > 0 { + p.params[0] = parser.MissingParam } - p.ParamsLen = 0 - p.Cmd = 0 + p.paramsLen = 0 + p.cmd = 0 } - state = MarkerState + state = PrefixState continue case ']', 'X', '^', '_': if p != nil { - p.Cmd = parser.MissingCommand - p.DataLen = 0 + p.cmd = parser.MissingCommand + p.dataLen = 0 } state = StringState continue @@ -230,14 +289,14 @@ func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width if c >= ' ' && c <= '/' { if p != nil { - p.Cmd &^= 0xff << parser.IntermedShift - p.Cmd |= int(c) << parser.IntermedShift + p.cmd &^= 0xff << parser.IntermedShift + p.cmd |= int(c) << parser.IntermedShift } continue } else if c >= '0' && c <= '~' { if p != nil { - p.Cmd &^= 0xff - p.Cmd |= int(c) + p.cmd &^= 0xff + p.cmd |= int(c) } return b[:i+1], 0, i + 1, NormalState } @@ -281,9 +340,9 @@ func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width return b[:i], 0, i, NormalState } - if p != nil && p.DataLen < len(p.Data) { - p.Data[p.DataLen] = c - p.DataLen++ + if p != nil && p.dataLen < len(p.data) { + p.data[p.dataLen] = c + p.dataLen++ // Parse the OSC command number if c == ';' && HasOscPrefix(b) { @@ -297,32 +356,20 @@ func DecodeSequence[T string | []byte](b T, state byte, p *Parser) (seq T, width } func parseOscCmd(p *Parser) { - if p == nil || p.Cmd != parser.MissingCommand { + if p == nil || p.cmd != parser.MissingCommand { return } - for j := 0; j < p.DataLen; j++ { - d := p.Data[j] + for j := 0; j < p.dataLen; j++ { + d := p.data[j] if d < '0' || d > '9' { break } - if p.Cmd == parser.MissingCommand { - p.Cmd = 0 + if p.cmd == parser.MissingCommand { + p.cmd = 0 } - p.Cmd *= 10 - p.Cmd += int(d - '0') - } -} - -// Index returns the index of the first occurrence of the given byte slice in -// the data. It returns -1 if the byte slice is not found. -func Index[T string | []byte](data, b T) int { - switch data := any(data).(type) { - case string: - return strings.Index(data, string(b)) - case []byte: - return bytes.Index(data, []byte(b)) + p.cmd *= 10 + p.cmd += int(d - '0') } - panic("unreachable") } // Equal returns true if the given byte slices are equal. @@ -403,30 +450,47 @@ func FirstGraphemeCluster[T string | []byte](b T, state int) (T, T, int, int) { } // Cmd represents a sequence command. This is used to pack/unpack a sequence -// command with its intermediate and marker characters. Those are commonly +// command with its intermediate and prefix characters. Those are commonly // found in CSI and DCS sequences. type Cmd int -// Marker returns the marker byte of the CSI sequence. +// Prefix returns the unpacked prefix byte of the CSI sequence. // This is always gonna be one of the following '<' '=' '>' '?' and in the // range of 0x3C-0x3F. -// Zero is returned if the sequence does not have a marker. -func (c Cmd) Marker() int { - return parser.Marker(int(c)) +// Zero is returned if the sequence does not have a prefix. +func (c Cmd) Prefix() byte { + return byte(parser.Prefix(int(c))) } -// Intermediate returns the intermediate byte of the CSI sequence. +// Intermediate returns the unpacked intermediate byte of the CSI sequence. // An intermediate byte is in the range of 0x20-0x2F. This includes these // characters from ' ', '!', '"', '#', '$', '%', '&', â€', '(', ')', '*', '+', // ',', '-', '.', '/'. // Zero is returned if the sequence does not have an intermediate byte. -func (c Cmd) Intermediate() int { - return parser.Intermediate(int(c)) +func (c Cmd) Intermediate() byte { + return byte(parser.Intermediate(int(c))) } -// Command returns the command byte of the CSI sequence. -func (c Cmd) Command() int { - return parser.Command(int(c)) +// Final returns the unpacked command byte of the CSI sequence. +func (c Cmd) Final() byte { + return byte(parser.Command(int(c))) +} + +// Command packs a command with the given prefix, intermediate, and final. A +// zero byte means the sequence does not have a prefix or intermediate. +// +// Prefixes are in the range of 0x3C-0x3F that is one of `<=>?`. +// +// Intermediates are in the range of 0x20-0x2F that is anything in +// `!"#$%&'()*+,-./`. +// +// Final bytes are in the range of 0x40-0x7E that is anything in the range +// `@A–Z[\]^_`a–z{|}~`. +func Command(prefix, inter, final byte) (c int) { + c = int(final) + c |= int(prefix) << parser.PrefixShift + c |= int(inter) << parser.IntermedShift + return } // Param represents a sequence parameter. Sequence parameters with @@ -434,17 +498,27 @@ func (c Cmd) Command() int { // the parameters from a CSI and DCS sequences. type Param int -// Param returns the parameter at the given index. -// It returns -1 if the parameter does not exist. -func (s Param) Param() int { +// Param returns the unpacked parameter at the given index. +// It returns the default value if the parameter is missing. +func (s Param) Param(def int) int { p := int(s) & parser.ParamMask if p == parser.MissingParam { - return -1 + return def } return p } -// HasMore returns true if the parameter has more sub-parameters. +// HasMore unpacks the HasMoreFlag from the parameter. func (s Param) HasMore() bool { - return int(s)&parser.HasMoreFlag != 0 + return s&parser.HasMoreFlag != 0 +} + +// Parameter packs an escape code parameter with the given parameter and +// whether this parameter has following sub-parameters. +func Parameter(p int, hasMore bool) (s int) { + s = p & parser.ParamMask + if hasMore { + s |= parser.HasMoreFlag + } + return } diff --git a/source/vendor/github.com/charmbracelet/x/ansi/parser_handler.go b/source/vendor/github.com/charmbracelet/x/ansi/parser_handler.go new file mode 100644 index 0000000000000000000000000000000000000000..03f9ed4cbdd4da3c46870d1f7ae36e1e4a9e0d2c --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/parser_handler.go @@ -0,0 +1,60 @@ +package ansi + +import "unsafe" + +// Params represents a list of packed parameters. +type Params []Param + +// Param returns the parameter at the given index and if it is part of a +// sub-parameters. It falls back to the default value if the parameter is +// missing. If the index is out of bounds, it returns the default value and +// false. +func (p Params) Param(i, def int) (int, bool, bool) { + if i < 0 || i >= len(p) { + return def, false, false + } + return p[i].Param(def), p[i].HasMore(), true +} + +// ForEach iterates over the parameters and calls the given function for each +// parameter. If a parameter is part of a sub-parameter, it will be called with +// hasMore set to true. +// Use def to set a default value for missing parameters. +func (p Params) ForEach(def int, f func(i, param int, hasMore bool)) { + for i := range p { + f(i, p[i].Param(def), p[i].HasMore()) + } +} + +// ToParams converts a list of integers to a list of parameters. +func ToParams(params []int) Params { + return unsafe.Slice((*Param)(unsafe.Pointer(¶ms[0])), len(params)) +} + +// Handler handles actions performed by the parser. +// It is used to handle ANSI escape sequences, control characters, and runes. +type Handler struct { + // Print is called when a printable rune is encountered. + Print func(r rune) + // Execute is called when a control character is encountered. + Execute func(b byte) + // HandleCsi is called when a CSI sequence is encountered. + HandleCsi func(cmd Cmd, params Params) + // HandleEsc is called when an ESC sequence is encountered. + HandleEsc func(cmd Cmd) + // HandleDcs is called when a DCS sequence is encountered. + HandleDcs func(cmd Cmd, params Params, data []byte) + // HandleOsc is called when an OSC sequence is encountered. + HandleOsc func(cmd int, data []byte) + // HandlePm is called when a PM sequence is encountered. + HandlePm func(data []byte) + // HandleApc is called when an APC sequence is encountered. + HandleApc func(data []byte) + // HandleSos is called when a SOS sequence is encountered. + HandleSos func(data []byte) +} + +// SetHandler sets the handler for the parser. +func (p *Parser) SetHandler(h Handler) { + p.handler = h +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/parser_sync.go b/source/vendor/github.com/charmbracelet/x/ansi/parser_sync.go index c6f24d35548b905d30b8ca7962b672a9e032b0b4..65d25a9a6a316a958d58f994fa469e571126e186 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/parser_sync.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/parser_sync.go @@ -8,7 +8,10 @@ import ( var parserPool = sync.Pool{ New: func() any { - return NewParser(parser.MaxParamsSize, 1024*1024*4) // 4MB of data buffer + p := NewParser() + p.SetParamsSize(parser.MaxParamsSize) + p.SetDataSize(1024 * 1024 * 4) // 4MB of data buffer + return p }, } @@ -21,6 +24,6 @@ func GetParser() *Parser { // automatically. func PutParser(p *Parser) { p.Reset() - p.DataLen = 0 + p.dataLen = 0 parserPool.Put(p) } diff --git a/source/vendor/github.com/charmbracelet/x/ansi/paste.go b/source/vendor/github.com/charmbracelet/x/ansi/paste.go new file mode 100644 index 0000000000000000000000000000000000000000..2f9ea6f79e631479fa5ca4fb666f6257f33f6d45 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/paste.go @@ -0,0 +1,7 @@ +package ansi + +// BracketedPasteStart is the control sequence to enable bracketed paste mode. +const BracketedPasteStart = "\x1b[200~" + +// BracketedPasteEnd is the control sequence to disable bracketed paste mode. +const BracketedPasteEnd = "\x1b[201~" diff --git a/source/vendor/github.com/charmbracelet/x/ansi/reset.go b/source/vendor/github.com/charmbracelet/x/ansi/reset.go new file mode 100644 index 0000000000000000000000000000000000000000..c1b89ea493f61fdc97b49b604ca108246117ba0e --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/reset.go @@ -0,0 +1,11 @@ +package ansi + +// ResetInitialState (RIS) resets the terminal to its initial state. +// +// ESC c +// +// See: https://vt100.net/docs/vt510-rm/RIS.html +const ( + ResetInitialState = "\x1bc" + RIS = ResetInitialState +) diff --git a/source/vendor/github.com/charmbracelet/x/ansi/screen.go b/source/vendor/github.com/charmbracelet/x/ansi/screen.go index a37eed7a3f7fd828ab45282a2a5e80f1f16de3b1..c76e4f0d687949c9c00f818bf3d46908c7be0c0b 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/screen.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/screen.go @@ -1,11 +1,16 @@ package ansi -import "strconv" +import ( + "strconv" + "strings" +) // EraseDisplay (ED) clears the display or parts of the display. A screen is // the shown part of the terminal display excluding the scrollback buffer. // Possible values: // +// Default is 0. +// // 0: Clear from cursor to end of screen. // 1: Clear from cursor to beginning of the screen. // 2: Clear entire screen (and moves cursor to upper left on DOS). @@ -15,16 +20,22 @@ import "strconv" // // See: https://vt100.net/docs/vt510-rm/ED.html func EraseDisplay(n int) string { - if n < 0 { - n = 0 + var s string + if n > 0 { + s = strconv.Itoa(n) } - return "\x1b[" + strconv.Itoa(n) + "J" + return "\x1b[" + s + "J" +} + +// ED is an alias for [EraseDisplay]. +func ED(n int) string { + return EraseDisplay(n) } // EraseDisplay constants. // These are the possible values for the EraseDisplay function. const ( - EraseScreenBelow = "\x1b[0J" + EraseScreenBelow = "\x1b[J" EraseScreenAbove = "\x1b[1J" EraseEntireScreen = "\x1b[2J" EraseEntireDisplay = "\x1b[3J" @@ -42,16 +53,22 @@ const ( // // See: https://vt100.net/docs/vt510-rm/EL.html func EraseLine(n int) string { - if n < 0 { - n = 0 + var s string + if n > 0 { + s = strconv.Itoa(n) } - return "\x1b[" + strconv.Itoa(n) + "K" + return "\x1b[" + s + "K" +} + +// EL is an alias for [EraseLine]. +func EL(n int) string { + return EraseLine(n) } // EraseLine constants. // These are the possible values for the EraseLine function. const ( - EraseLineRight = "\x1b[0K" + EraseLineRight = "\x1b[K" EraseLineLeft = "\x1b[1K" EraseEntireLine = "\x1b[2K" ) @@ -59,7 +76,7 @@ const ( // ScrollUp (SU) scrolls the screen up n lines. New lines are added at the // bottom of the screen. // -// CSI <n> S +// CSI Pn S // // See: https://vt100.net/docs/vt510-rm/SU.html func ScrollUp(n int) string { @@ -70,10 +87,20 @@ func ScrollUp(n int) string { return "\x1b[" + s + "S" } +// PanDown is an alias for [ScrollUp]. +func PanDown(n int) string { + return ScrollUp(n) +} + +// SU is an alias for [ScrollUp]. +func SU(n int) string { + return ScrollUp(n) +} + // ScrollDown (SD) scrolls the screen down n lines. New lines are added at the // top of the screen. // -// CSI <n> T +// CSI Pn T // // See: https://vt100.net/docs/vt510-rm/SD.html func ScrollDown(n int) string { @@ -84,10 +111,20 @@ func ScrollDown(n int) string { return "\x1b[" + s + "T" } +// PanUp is an alias for [ScrollDown]. +func PanUp(n int) string { + return ScrollDown(n) +} + +// SD is an alias for [ScrollDown]. +func SD(n int) string { + return ScrollDown(n) +} + // InsertLine (IL) inserts n blank lines at the current cursor position. // Existing lines are moved down. // -// CSI <n> L +// CSI Pn L // // See: https://vt100.net/docs/vt510-rm/IL.html func InsertLine(n int) string { @@ -98,10 +135,15 @@ func InsertLine(n int) string { return "\x1b[" + s + "L" } +// IL is an alias for [InsertLine]. +func IL(n int) string { + return InsertLine(n) +} + // DeleteLine (DL) deletes n lines at the current cursor position. Existing // lines are moved up. // -// CSI <n> M +// CSI Pn M // // See: https://vt100.net/docs/vt510-rm/DL.html func DeleteLine(n int) string { @@ -112,12 +154,67 @@ func DeleteLine(n int) string { return "\x1b[" + s + "M" } +// DL is an alias for [DeleteLine]. +func DL(n int) string { + return DeleteLine(n) +} + +// SetTopBottomMargins (DECSTBM) sets the top and bottom margins for the scrolling +// region. The default is the entire screen. +// +// Default is 1 and the bottom of the screen. +// +// CSI Pt ; Pb r +// +// See: https://vt100.net/docs/vt510-rm/DECSTBM.html +func SetTopBottomMargins(top, bot int) string { + var t, b string + if top > 0 { + t = strconv.Itoa(top) + } + if bot > 0 { + b = strconv.Itoa(bot) + } + return "\x1b[" + t + ";" + b + "r" +} + +// DECSTBM is an alias for [SetTopBottomMargins]. +func DECSTBM(top, bot int) string { + return SetTopBottomMargins(top, bot) +} + +// SetLeftRightMargins (DECSLRM) sets the left and right margins for the scrolling +// region. +// +// Default is 1 and the right of the screen. +// +// CSI Pl ; Pr s +// +// See: https://vt100.net/docs/vt510-rm/DECSLRM.html +func SetLeftRightMargins(left, right int) string { + var l, r string + if left > 0 { + l = strconv.Itoa(left) + } + if right > 0 { + r = strconv.Itoa(right) + } + return "\x1b[" + l + ";" + r + "s" +} + +// DECSLRM is an alias for [SetLeftRightMargins]. +func DECSLRM(left, right int) string { + return SetLeftRightMargins(left, right) +} + // SetScrollingRegion (DECSTBM) sets the top and bottom margins for the scrolling // region. The default is the entire screen. // // CSI <top> ; <bottom> r // // See: https://vt100.net/docs/vt510-rm/DECSTBM.html +// +// Deprecated: use [SetTopBottomMargins] instead. func SetScrollingRegion(t, b int) string { if t < 0 { t = 0 @@ -127,3 +224,187 @@ func SetScrollingRegion(t, b int) string { } return "\x1b[" + strconv.Itoa(t) + ";" + strconv.Itoa(b) + "r" } + +// InsertCharacter (ICH) inserts n blank characters at the current cursor +// position. Existing characters move to the right. Characters moved past the +// right margin are lost. ICH has no effect outside the scrolling margins. +// +// Default is 1. +// +// CSI Pn @ +// +// See: https://vt100.net/docs/vt510-rm/ICH.html +func InsertCharacter(n int) string { + var s string + if n > 1 { + s = strconv.Itoa(n) + } + return "\x1b[" + s + "@" +} + +// ICH is an alias for [InsertCharacter]. +func ICH(n int) string { + return InsertCharacter(n) +} + +// DeleteCharacter (DCH) deletes n characters at the current cursor position. +// As the characters are deleted, the remaining characters move to the left and +// the cursor remains at the same position. +// +// Default is 1. +// +// CSI Pn P +// +// See: https://vt100.net/docs/vt510-rm/DCH.html +func DeleteCharacter(n int) string { + var s string + if n > 1 { + s = strconv.Itoa(n) + } + return "\x1b[" + s + "P" +} + +// DCH is an alias for [DeleteCharacter]. +func DCH(n int) string { + return DeleteCharacter(n) +} + +// SetTabEvery8Columns (DECST8C) sets the tab stops at every 8 columns. +// +// CSI ? 5 W +// +// See: https://vt100.net/docs/vt510-rm/DECST8C.html +const ( + SetTabEvery8Columns = "\x1b[?5W" + DECST8C = SetTabEvery8Columns +) + +// HorizontalTabSet (HTS) sets a horizontal tab stop at the current cursor +// column. +// +// This is equivalent to [HTS]. +// +// ESC H +// +// See: https://vt100.net/docs/vt510-rm/HTS.html +const HorizontalTabSet = "\x1bH" + +// TabClear (TBC) clears tab stops. +// +// Default is 0. +// +// Possible values: +// 0: Clear tab stop at the current column. (default) +// 3: Clear all tab stops. +// +// CSI Pn g +// +// See: https://vt100.net/docs/vt510-rm/TBC.html +func TabClear(n int) string { + var s string + if n > 0 { + s = strconv.Itoa(n) + } + return "\x1b[" + s + "g" +} + +// TBC is an alias for [TabClear]. +func TBC(n int) string { + return TabClear(n) +} + +// RequestPresentationStateReport (DECRQPSR) requests the terminal to send a +// report of the presentation state. This includes the cursor information [DECCIR], +// and tab stop [DECTABSR] reports. +// +// Default is 0. +// +// Possible values: +// 0: Error, request ignored. +// 1: Cursor information report [DECCIR]. +// 2: Tab stop report [DECTABSR]. +// +// CSI Ps $ w +// +// See: https://vt100.net/docs/vt510-rm/DECRQPSR.html +func RequestPresentationStateReport(n int) string { + var s string + if n > 0 { + s = strconv.Itoa(n) + } + return "\x1b[" + s + "$w" +} + +// DECRQPSR is an alias for [RequestPresentationStateReport]. +func DECRQPSR(n int) string { + return RequestPresentationStateReport(n) +} + +// TabStopReport (DECTABSR) is the response to a tab stop report request. +// It reports the tab stops set in the terminal. +// +// The response is a list of tab stops separated by a slash (/) character. +// +// DCS 2 $ u D ... D ST +// +// Where D is a decimal number representing a tab stop. +// +// See: https://vt100.net/docs/vt510-rm/DECTABSR.html +func TabStopReport(stops ...int) string { + var s []string + for _, v := range stops { + s = append(s, strconv.Itoa(v)) + } + return "\x1bP2$u" + strings.Join(s, "/") + "\x1b\\" +} + +// DECTABSR is an alias for [TabStopReport]. +func DECTABSR(stops ...int) string { + return TabStopReport(stops...) +} + +// CursorInformationReport (DECCIR) is the response to a cursor information +// report request. It reports the cursor position, visual attributes, and +// character protection attributes. It also reports the status of origin mode +// [DECOM] and the current active character set. +// +// The response is a list of values separated by a semicolon (;) character. +// +// DCS 1 $ u D ... D ST +// +// Where D is a decimal number representing a value. +// +// See: https://vt100.net/docs/vt510-rm/DECCIR.html +func CursorInformationReport(values ...int) string { + var s []string + for _, v := range values { + s = append(s, strconv.Itoa(v)) + } + return "\x1bP1$u" + strings.Join(s, ";") + "\x1b\\" +} + +// DECCIR is an alias for [CursorInformationReport]. +func DECCIR(values ...int) string { + return CursorInformationReport(values...) +} + +// RepeatPreviousCharacter (REP) repeats the previous character n times. +// This is identical to typing the same character n times. +// +// Default is 1. +// +// CSI Pn b +// +// See: ECMA-48 § 8.3.103 +func RepeatPreviousCharacter(n int) string { + var s string + if n > 1 { + s = strconv.Itoa(n) + } + return "\x1b[" + s + "b" +} + +// REP is an alias for [RepeatPreviousCharacter]. +func REP(n int) string { + return RepeatPreviousCharacter(n) +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/sequence.go b/source/vendor/github.com/charmbracelet/x/ansi/sequence.go deleted file mode 100644 index f294a229a32d82b2ddcf9ddee5b66776fc4cf84e..0000000000000000000000000000000000000000 --- a/source/vendor/github.com/charmbracelet/x/ansi/sequence.go +++ /dev/null @@ -1,199 +0,0 @@ -package ansi - -import ( - "bytes" - - "github.com/charmbracelet/x/ansi/parser" -) - -// Sequence represents an ANSI sequence. This can be a control sequence, escape -// sequence, a printable character, etc. -type Sequence interface { - // String returns the string representation of the sequence. - String() string - // Bytes returns the byte representation of the sequence. - Bytes() []byte - // Clone returns a copy of the sequence. - Clone() Sequence -} - -// Rune represents a printable character. -type Rune rune - -var _ Sequence = Rune(0) - -// Bytes implements Sequence. -func (r Rune) Bytes() []byte { - return []byte(string(r)) -} - -// String implements Sequence. -func (r Rune) String() string { - return string(r) -} - -// Clone implements Sequence. -func (r Rune) Clone() Sequence { - return r -} - -// ControlCode represents a control code character. This is a character that -// is not printable and is used to control the terminal. This would be a -// character in the C0 or C1 set in the range of 0x00-0x1F and 0x80-0x9F. -type ControlCode byte - -var _ Sequence = ControlCode(0) - -// Bytes implements Sequence. -func (c ControlCode) Bytes() []byte { - return []byte{byte(c)} -} - -// String implements Sequence. -func (c ControlCode) String() string { - return string(c) -} - -// Clone implements Sequence. -func (c ControlCode) Clone() Sequence { - return c -} - -// EscSequence represents an escape sequence. -type EscSequence int - -var _ Sequence = EscSequence(0) - -// buffer returns the buffer of the escape sequence. -func (e EscSequence) buffer() *bytes.Buffer { - var b bytes.Buffer - b.WriteByte('\x1b') - if i := parser.Intermediate(int(e)); i != 0 { - b.WriteByte(byte(i)) - } - b.WriteByte(byte(e.Command())) - return &b -} - -// Bytes implements Sequence. -func (e EscSequence) Bytes() []byte { - return e.buffer().Bytes() -} - -// String implements Sequence. -func (e EscSequence) String() string { - return e.buffer().String() -} - -// Clone implements Sequence. -func (e EscSequence) Clone() Sequence { - return e -} - -// Command returns the command byte of the escape sequence. -func (e EscSequence) Command() int { - return parser.Command(int(e)) -} - -// Intermediate returns the intermediate byte of the escape sequence. -func (e EscSequence) Intermediate() int { - return parser.Intermediate(int(e)) -} - -// SosSequence represents a SOS sequence. -type SosSequence struct { - // Data contains the raw data of the sequence. - Data []byte -} - -var _ Sequence = &SosSequence{} - -// Clone implements Sequence. -func (s SosSequence) Clone() Sequence { - return SosSequence{Data: append([]byte(nil), s.Data...)} -} - -// Bytes implements Sequence. -func (s SosSequence) Bytes() []byte { - return s.buffer().Bytes() -} - -// String implements Sequence. -func (s SosSequence) String() string { - return s.buffer().String() -} - -func (s SosSequence) buffer() *bytes.Buffer { - var b bytes.Buffer - b.WriteByte('\x1b') - b.WriteByte('X') - b.Write(s.Data) - b.WriteString("\x1b\\") - return &b -} - -// PmSequence represents a PM sequence. -type PmSequence struct { - // Data contains the raw data of the sequence. - Data []byte -} - -var _ Sequence = &PmSequence{} - -// Clone implements Sequence. -func (s PmSequence) Clone() Sequence { - return PmSequence{Data: append([]byte(nil), s.Data...)} -} - -// Bytes implements Sequence. -func (s PmSequence) Bytes() []byte { - return s.buffer().Bytes() -} - -// String implements Sequence. -func (s PmSequence) String() string { - return s.buffer().String() -} - -// buffer returns the buffer of the PM sequence. -func (s PmSequence) buffer() *bytes.Buffer { - var b bytes.Buffer - b.WriteByte('\x1b') - b.WriteByte('^') - b.Write(s.Data) - b.WriteString("\x1b\\") - return &b -} - -// ApcSequence represents an APC sequence. -type ApcSequence struct { - // Data contains the raw data of the sequence. - Data []byte -} - -var _ Sequence = &ApcSequence{} - -// Clone implements Sequence. -func (s ApcSequence) Clone() Sequence { - return ApcSequence{Data: append([]byte(nil), s.Data...)} -} - -// Bytes implements Sequence. -func (s ApcSequence) Bytes() []byte { - return s.buffer().Bytes() -} - -// String implements Sequence. -func (s ApcSequence) String() string { - return s.buffer().String() -} - -// buffer returns the buffer of the APC sequence. -func (s ApcSequence) buffer() *bytes.Buffer { - var b bytes.Buffer - b.WriteByte('\x1b') - b.WriteByte('_') - b.Write(s.Data) - b.WriteString("\x1b\\") - return &b -} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/sgr.go b/source/vendor/github.com/charmbracelet/x/ansi/sgr.go new file mode 100644 index 0000000000000000000000000000000000000000..1a18c98ef4cc9ff03b279c1b3003b3f4252022bc --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/sgr.go @@ -0,0 +1,95 @@ +package ansi + +import "strconv" + +// Select Graphic Rendition (SGR) is a command that sets display attributes. +// +// Default is 0. +// +// CSI Ps ; Ps ... m +// +// See: https://vt100.net/docs/vt510-rm/SGR.html +func SelectGraphicRendition(ps ...Attr) string { + if len(ps) == 0 { + return ResetStyle + } + + var s Style + for _, p := range ps { + attr, ok := attrStrings[p] + if ok { + s = append(s, attr) + } else { + if p < 0 { + p = 0 + } + s = append(s, strconv.Itoa(p)) + } + } + + return s.String() +} + +// SGR is an alias for [SelectGraphicRendition]. +func SGR(ps ...Attr) string { + return SelectGraphicRendition(ps...) +} + +var attrStrings = map[int]string{ + ResetAttr: "0", + BoldAttr: "1", + FaintAttr: "2", + ItalicAttr: "3", + UnderlineAttr: "4", + SlowBlinkAttr: "5", + RapidBlinkAttr: "6", + ReverseAttr: "7", + ConcealAttr: "8", + StrikethroughAttr: "9", + NoBoldAttr: "21", + NormalIntensityAttr: "22", + NoItalicAttr: "23", + NoUnderlineAttr: "24", + NoBlinkAttr: "25", + NoReverseAttr: "27", + NoConcealAttr: "28", + NoStrikethroughAttr: "29", + BlackForegroundColorAttr: "30", + RedForegroundColorAttr: "31", + GreenForegroundColorAttr: "32", + YellowForegroundColorAttr: "33", + BlueForegroundColorAttr: "34", + MagentaForegroundColorAttr: "35", + CyanForegroundColorAttr: "36", + WhiteForegroundColorAttr: "37", + ExtendedForegroundColorAttr: "38", + DefaultForegroundColorAttr: "39", + BlackBackgroundColorAttr: "40", + RedBackgroundColorAttr: "41", + GreenBackgroundColorAttr: "42", + YellowBackgroundColorAttr: "43", + BlueBackgroundColorAttr: "44", + MagentaBackgroundColorAttr: "45", + CyanBackgroundColorAttr: "46", + WhiteBackgroundColorAttr: "47", + ExtendedBackgroundColorAttr: "48", + DefaultBackgroundColorAttr: "49", + ExtendedUnderlineColorAttr: "58", + DefaultUnderlineColorAttr: "59", + BrightBlackForegroundColorAttr: "90", + BrightRedForegroundColorAttr: "91", + BrightGreenForegroundColorAttr: "92", + BrightYellowForegroundColorAttr: "93", + BrightBlueForegroundColorAttr: "94", + BrightMagentaForegroundColorAttr: "95", + BrightCyanForegroundColorAttr: "96", + BrightWhiteForegroundColorAttr: "97", + BrightBlackBackgroundColorAttr: "100", + BrightRedBackgroundColorAttr: "101", + BrightGreenBackgroundColorAttr: "102", + BrightYellowBackgroundColorAttr: "103", + BrightBlueBackgroundColorAttr: "104", + BrightMagentaBackgroundColorAttr: "105", + BrightCyanBackgroundColorAttr: "106", + BrightWhiteBackgroundColorAttr: "107", +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/status.go b/source/vendor/github.com/charmbracelet/x/ansi/status.go new file mode 100644 index 0000000000000000000000000000000000000000..4337e189d434ad8522c2a37381425bc6aac03607 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/status.go @@ -0,0 +1,144 @@ +package ansi + +import ( + "strconv" + "strings" +) + +// StatusReport represents a terminal status report. +type StatusReport interface { + // StatusReport returns the status report identifier. + StatusReport() int +} + +// ANSIReport represents an ANSI terminal status report. +type ANSIStatusReport int //nolint:revive + +// Report returns the status report identifier. +func (s ANSIStatusReport) StatusReport() int { + return int(s) +} + +// DECStatusReport represents a DEC terminal status report. +type DECStatusReport int + +// Status returns the status report identifier. +func (s DECStatusReport) StatusReport() int { + return int(s) +} + +// DeviceStatusReport (DSR) is a control sequence that reports the terminal's +// status. +// The terminal responds with a DSR sequence. +// +// CSI Ps n +// CSI ? Ps n +// +// If one of the statuses is a [DECStatus], the sequence will use the DEC +// format. +// +// See also https://vt100.net/docs/vt510-rm/DSR.html +func DeviceStatusReport(statues ...StatusReport) string { + var dec bool + list := make([]string, len(statues)) + seq := "\x1b[" + for i, status := range statues { + list[i] = strconv.Itoa(status.StatusReport()) + switch status.(type) { + case DECStatusReport: + dec = true + } + } + if dec { + seq += "?" + } + return seq + strings.Join(list, ";") + "n" +} + +// DSR is an alias for [DeviceStatusReport]. +func DSR(status StatusReport) string { + return DeviceStatusReport(status) +} + +// RequestCursorPositionReport is an escape sequence that requests the current +// cursor position. +// +// CSI 6 n +// +// The terminal will report the cursor position as a CSI sequence in the +// following format: +// +// CSI Pl ; Pc R +// +// Where Pl is the line number and Pc is the column number. +// See: https://vt100.net/docs/vt510-rm/CPR.html +const RequestCursorPositionReport = "\x1b[6n" + +// RequestExtendedCursorPositionReport (DECXCPR) is a sequence for requesting +// the cursor position report including the current page number. +// +// CSI ? 6 n +// +// The terminal will report the cursor position as a CSI sequence in the +// following format: +// +// CSI ? Pl ; Pc ; Pp R +// +// Where Pl is the line number, Pc is the column number, and Pp is the page +// number. +// See: https://vt100.net/docs/vt510-rm/DECXCPR.html +const RequestExtendedCursorPositionReport = "\x1b[?6n" + +// CursorPositionReport (CPR) is a control sequence that reports the cursor's +// position. +// +// CSI Pl ; Pc R +// +// Where Pl is the line number and Pc is the column number. +// +// See also https://vt100.net/docs/vt510-rm/CPR.html +func CursorPositionReport(line, column int) string { + if line < 1 { + line = 1 + } + if column < 1 { + column = 1 + } + return "\x1b[" + strconv.Itoa(line) + ";" + strconv.Itoa(column) + "R" +} + +// CPR is an alias for [CursorPositionReport]. +func CPR(line, column int) string { + return CursorPositionReport(line, column) +} + +// ExtendedCursorPositionReport (DECXCPR) is a control sequence that reports the +// cursor's position along with the page number (optional). +// +// CSI ? Pl ; Pc R +// CSI ? Pl ; Pc ; Pv R +// +// Where Pl is the line number, Pc is the column number, and Pv is the page +// number. +// +// If the page number is zero or negative, the returned sequence won't include +// the page number. +// +// See also https://vt100.net/docs/vt510-rm/DECXCPR.html +func ExtendedCursorPositionReport(line, column, page int) string { + if line < 1 { + line = 1 + } + if column < 1 { + column = 1 + } + if page < 1 { + return "\x1b[?" + strconv.Itoa(line) + ";" + strconv.Itoa(column) + "R" + } + return "\x1b[?" + strconv.Itoa(line) + ";" + strconv.Itoa(column) + ";" + strconv.Itoa(page) + "R" +} + +// DECXCPR is an alias for [ExtendedCursorPositionReport]. +func DECXCPR(line, column, page int) string { + return ExtendedCursorPositionReport(line, column, page) +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/style.go b/source/vendor/github.com/charmbracelet/x/ansi/style.go index 5ab3dd473f02e4a92d3035f3d2935a50d1b14b56..46ddcaa99b376a12495957d5b91d9c60e14e2846 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/style.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/style.go @@ -199,7 +199,7 @@ func (s Style) UnderlineColor(c Color) Style { // UnderlineStyle represents an ANSI SGR (Select Graphic Rendition) underline // style. -type UnderlineStyle = int +type UnderlineStyle = byte const ( doubleUnderlineStyle = "4:2" @@ -488,9 +488,173 @@ func underlineColorString(c Color) string { return defaultUnderlineColorAttr } -func shift(v uint32) uint32 { - if v > 0xff { - return v >> 8 +// ReadStyleColor decodes a color from a slice of parameters. It returns the +// number of parameters read and the color. This function is used to read SGR +// color parameters following the ITU T.416 standard. +// +// It supports reading the following color types: +// - 0: implementation defined +// - 1: transparent +// - 2: RGB direct color +// - 3: CMY direct color +// - 4: CMYK direct color +// - 5: indexed color +// - 6: RGBA direct color (WezTerm extension) +// +// The parameters can be separated by semicolons (;) or colons (:). Mixing +// separators is not allowed. +// +// The specs supports defining a color space id, a color tolerance value, and a +// tolerance color space id. However, these values have no effect on the +// returned color and will be ignored. +// +// This implementation includes a few modifications to the specs: +// 1. Support for legacy color values separated by semicolons (;) with respect to RGB, and indexed colors +// 2. Support ignoring and omitting the color space id (second parameter) with respect to RGB colors +// 3. Support ignoring and omitting the 6th parameter with respect to RGB and CMY colors +// 4. Support reading RGBA colors +func ReadStyleColor(params Params, co *color.Color) (n int) { + if len(params) < 2 { // Need at least SGR type and color type + return 0 + } + + // First parameter indicates one of 38, 48, or 58 (foreground, background, or underline) + s := params[0] + p := params[1] + colorType := p.Param(0) + n = 2 + + paramsfn := func() (p1, p2, p3, p4 int) { + // Where should we start reading the color? + switch { + case s.HasMore() && p.HasMore() && len(params) > 8 && params[2].HasMore() && params[3].HasMore() && params[4].HasMore() && params[5].HasMore() && params[6].HasMore() && params[7].HasMore(): + // We have color space id, a 6th parameter, a tolerance value, and a tolerance color space + n += 7 + return params[3].Param(0), params[4].Param(0), params[5].Param(0), params[6].Param(0) + case s.HasMore() && p.HasMore() && len(params) > 7 && params[2].HasMore() && params[3].HasMore() && params[4].HasMore() && params[5].HasMore() && params[6].HasMore(): + // We have color space id, a 6th parameter, and a tolerance value + n += 6 + return params[3].Param(0), params[4].Param(0), params[5].Param(0), params[6].Param(0) + case s.HasMore() && p.HasMore() && len(params) > 6 && params[2].HasMore() && params[3].HasMore() && params[4].HasMore() && params[5].HasMore(): + // We have color space id and a 6th parameter + // 48 : 4 : : 1 : 2 : 3 :4 + n += 5 + return params[3].Param(0), params[4].Param(0), params[5].Param(0), params[6].Param(0) + case s.HasMore() && p.HasMore() && len(params) > 5 && params[2].HasMore() && params[3].HasMore() && params[4].HasMore() && !params[5].HasMore(): + // We have color space + // 48 : 3 : : 1 : 2 : 3 + n += 4 + return params[3].Param(0), params[4].Param(0), params[5].Param(0), -1 + case s.HasMore() && p.HasMore() && p.Param(0) == 2 && params[2].HasMore() && params[3].HasMore() && !params[4].HasMore(): + // We have color values separated by colons (:) + // 48 : 2 : 1 : 2 : 3 + fallthrough + case !s.HasMore() && !p.HasMore() && p.Param(0) == 2 && !params[2].HasMore() && !params[3].HasMore() && !params[4].HasMore(): + // Support legacy color values separated by semicolons (;) + // 48 ; 2 ; 1 ; 2 ; 3 + n += 3 + return params[2].Param(0), params[3].Param(0), params[4].Param(0), -1 + } + // Ambiguous SGR color + return -1, -1, -1, -1 + } + + switch colorType { + case 0: // implementation defined + return 2 + case 1: // transparent + *co = color.Transparent + return 2 + case 2: // RGB direct color + if len(params) < 5 { + return 0 + } + + r, g, b, _ := paramsfn() + if r == -1 || g == -1 || b == -1 { + return 0 + } + + *co = color.RGBA{ + R: uint8(r), //nolint:gosec + G: uint8(g), //nolint:gosec + B: uint8(b), //nolint:gosec + A: 0xff, + } + return + + case 3: // CMY direct color + if len(params) < 5 { + return 0 + } + + c, m, y, _ := paramsfn() + if c == -1 || m == -1 || y == -1 { + return 0 + } + + *co = color.CMYK{ + C: uint8(c), //nolint:gosec + M: uint8(m), //nolint:gosec + Y: uint8(y), //nolint:gosec + K: 0, + } + return + + case 4: // CMYK direct color + if len(params) < 6 { + return 0 + } + + c, m, y, k := paramsfn() + if c == -1 || m == -1 || y == -1 || k == -1 { + return 0 + } + + *co = color.CMYK{ + C: uint8(c), //nolint:gosec + M: uint8(m), //nolint:gosec + Y: uint8(y), //nolint:gosec + K: uint8(k), //nolint:gosec + } + return + + case 5: // indexed color + if len(params) < 3 { + return 0 + } + switch { + case s.HasMore() && p.HasMore() && !params[2].HasMore(): + // Colon separated indexed color + // 38 : 5 : 234 + case !s.HasMore() && !p.HasMore() && !params[2].HasMore(): + // Legacy semicolon indexed color + // 38 ; 5 ; 234 + default: + return 0 + } + *co = ExtendedColor(params[2].Param(0)) //nolint:gosec + return 3 + + case 6: // RGBA direct color + if len(params) < 6 { + return 0 + } + + r, g, b, a := paramsfn() + if r == -1 || g == -1 || b == -1 || a == -1 { + return 0 + } + + *co = color.RGBA{ + R: uint8(r), //nolint:gosec + G: uint8(g), //nolint:gosec + B: uint8(b), //nolint:gosec + A: uint8(a), //nolint:gosec + } + return + + default: + return 0 } - return v } diff --git a/source/vendor/github.com/charmbracelet/x/ansi/termcap.go b/source/vendor/github.com/charmbracelet/x/ansi/termcap.go index 1dfc52a6e01f631e34ed1f5ec533db49d829ce75..3c5c7da92fdf95822fbafdd970d29bd9babaa755 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/termcap.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/termcap.go @@ -14,7 +14,7 @@ import ( // // See: https://man7.org/linux/man-pages/man5/terminfo.5.html // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands -func RequestTermcap(caps ...string) string { +func XTGETTCAP(caps ...string) string { if len(caps) == 0 { return "" } @@ -29,3 +29,13 @@ func RequestTermcap(caps ...string) string { return s + "\x1b\\" } + +// RequestTermcap is an alias for [XTGETTCAP]. +func RequestTermcap(caps ...string) string { + return XTGETTCAP(caps...) +} + +// RequestTerminfo is an alias for [XTGETTCAP]. +func RequestTerminfo(caps ...string) string { + return XTGETTCAP(caps...) +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/truncate.go b/source/vendor/github.com/charmbracelet/x/ansi/truncate.go index db0782c81358e56a3b783f9144567088225027ae..1fa3efefebe68727a208dde3e9ba150d7506fa21 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/truncate.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/truncate.go @@ -4,14 +4,65 @@ import ( "bytes" "github.com/charmbracelet/x/ansi/parser" + "github.com/mattn/go-runewidth" "github.com/rivo/uniseg" ) -// Truncate truncates a string to a given length, adding a tail to the -// end if the string is longer than the given length. -// This function is aware of ANSI escape codes and will not break them, and -// accounts for wide-characters (such as East Asians and emojis). +// Cut the string, without adding any prefix or tail strings. This function is +// aware of ANSI escape codes and will not break them, and accounts for +// wide-characters (such as East-Asian characters and emojis). Note that the +// [left] parameter is inclusive, while [right] isn't. +// This treats the text as a sequence of graphemes. +func Cut(s string, left, right int) string { + return cut(GraphemeWidth, s, left, right) +} + +// CutWc the string, without adding any prefix or tail strings. This function is +// aware of ANSI escape codes and will not break them, and accounts for +// wide-characters (such as East-Asian characters and emojis). Note that the +// [left] parameter is inclusive, while [right] isn't. +// This treats the text as a sequence of wide characters and runes. +func CutWc(s string, left, right int) string { + return cut(WcWidth, s, left, right) +} + +func cut(m Method, s string, left, right int) string { + if right <= left { + return "" + } + + truncate := Truncate + truncateLeft := TruncateLeft + if m == WcWidth { + truncate = TruncateWc + truncateLeft = TruncateWc + } + + if left == 0 { + return truncate(s, right, "") + } + return truncateLeft(Truncate(s, right, ""), left, "") +} + +// Truncate truncates a string to a given length, adding a tail to the end if +// the string is longer than the given length. This function is aware of ANSI +// escape codes and will not break them, and accounts for wide-characters (such +// as East-Asian characters and emojis). +// This treats the text as a sequence of graphemes. func Truncate(s string, length int, tail string) string { + return truncate(GraphemeWidth, s, length, tail) +} + +// TruncateWc truncates a string to a given length, adding a tail to the end if +// the string is longer than the given length. This function is aware of ANSI +// escape codes and will not break them, and accounts for wide-characters (such +// as East-Asian characters and emojis). +// This treats the text as a sequence of wide characters and runes. +func TruncateWc(s string, length int, tail string) string { + return truncate(WcWidth, s, length, tail) +} + +func truncate(m Method, s string, length int, tail string) string { if sw := StringWidth(s); sw <= length { return s } @@ -33,6 +84,7 @@ func Truncate(s string, length int, tail string) string { // Here we iterate over the bytes of the string and collect printable // characters and runes. We also keep track of the width of the string // in cells. + // // Once we reach the given length, we start ignoring characters and only // collect ANSI escape codes until we reach the end of string. for i < len(b) { @@ -41,6 +93,9 @@ func Truncate(s string, length int, tail string) string { // This action happens when we transition to the Utf8State. var width int cluster, _, width, _ = uniseg.FirstGraphemeCluster(b[i:], -1) + if m == WcWidth { + width = runewidth.StringWidth(string(cluster)) + } // increment the index by the length of the cluster i += len(cluster) @@ -105,3 +160,123 @@ func Truncate(s string, length int, tail string) string { return buf.String() } + +// TruncateLeft truncates a string from the left side by removing n characters, +// adding a prefix to the beginning if the string is longer than n. +// This function is aware of ANSI escape codes and will not break them, and +// accounts for wide-characters (such as East-Asian characters and emojis). +// This treats the text as a sequence of graphemes. +func TruncateLeft(s string, n int, prefix string) string { + return truncateLeft(GraphemeWidth, s, n, prefix) +} + +// TruncateLeftWc truncates a string from the left side by removing n characters, +// adding a prefix to the beginning if the string is longer than n. +// This function is aware of ANSI escape codes and will not break them, and +// accounts for wide-characters (such as East-Asian characters and emojis). +// This treats the text as a sequence of wide characters and runes. +func TruncateLeftWc(s string, n int, prefix string) string { + return truncateLeft(WcWidth, s, n, prefix) +} + +func truncateLeft(m Method, s string, n int, prefix string) string { + if n <= 0 { + return s + } + + var cluster []byte + var buf bytes.Buffer + curWidth := 0 + ignoring := true + pstate := parser.GroundState + b := []byte(s) + i := 0 + + for i < len(b) { + if !ignoring { + buf.Write(b[i:]) + break + } + + state, action := parser.Table.Transition(pstate, b[i]) + if state == parser.Utf8State { + var width int + cluster, _, width, _ = uniseg.FirstGraphemeCluster(b[i:], -1) + if m == WcWidth { + width = runewidth.StringWidth(string(cluster)) + } + + i += len(cluster) + curWidth += width + + if curWidth > n && ignoring { + ignoring = false + buf.WriteString(prefix) + } + + if ignoring { + continue + } + + if curWidth > n { + buf.Write(cluster) + } + + pstate = parser.GroundState + continue + } + + switch action { + case parser.PrintAction: + curWidth++ + + if curWidth > n && ignoring { + ignoring = false + buf.WriteString(prefix) + } + + if ignoring { + i++ + continue + } + + fallthrough + default: + buf.WriteByte(b[i]) + i++ + } + + pstate = state + if curWidth > n && ignoring { + ignoring = false + buf.WriteString(prefix) + } + } + + return buf.String() +} + +// ByteToGraphemeRange takes start and stop byte positions and converts them to +// grapheme-aware char positions. +// You can use this with [Truncate], [TruncateLeft], and [Cut]. +func ByteToGraphemeRange(str string, byteStart, byteStop int) (charStart, charStop int) { + bytePos, charPos := 0, 0 + gr := uniseg.NewGraphemes(str) + for byteStart > bytePos { + if !gr.Next() { + break + } + bytePos += len(gr.Str()) + charPos += max(1, gr.Width()) + } + charStart = charPos + for byteStop > bytePos { + if !gr.Next() { + break + } + bytePos += len(gr.Str()) + charPos += max(1, gr.Width()) + } + charStop = charPos + return +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/util.go b/source/vendor/github.com/charmbracelet/x/ansi/util.go index 767093f921ec4a891b4d75ad14b110317ebd11ca..301ef15ff831b2d8e9e7319f0d64d4b2b291204d 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/util.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/util.go @@ -3,6 +3,10 @@ package ansi import ( "fmt" "image/color" + "strconv" + "strings" + + "github.com/lucasb-eyer/go-colorful" ) // colorToHexString returns a hex string representation of a color. @@ -27,3 +31,76 @@ func colorToHexString(c color.Color) string { func rgbToHex(r, g, b uint32) uint32 { return r<<16 + g<<8 + b } + +type shiftable interface { + ~uint | ~uint16 | ~uint32 | ~uint64 +} + +func shift[T shiftable](x T) T { + if x > 0xff { + x >>= 8 + } + return x +} + +// XParseColor is a helper function that parses a string into a color.Color. It +// provides a similar interface to the XParseColor function in Xlib. It +// supports the following formats: +// +// - #RGB +// - #RRGGBB +// - rgb:RRRR/GGGG/BBBB +// - rgba:RRRR/GGGG/BBBB/AAAA +// +// If the string is not a valid color, nil is returned. +// +// See: https://linux.die.net/man/3/xparsecolor +func XParseColor(s string) color.Color { + switch { + case strings.HasPrefix(s, "#"): + c, err := colorful.Hex(s) + if err != nil { + return nil + } + + return c + case strings.HasPrefix(s, "rgb:"): + parts := strings.Split(s[4:], "/") + if len(parts) != 3 { + return nil + } + + r, _ := strconv.ParseUint(parts[0], 16, 32) + g, _ := strconv.ParseUint(parts[1], 16, 32) + b, _ := strconv.ParseUint(parts[2], 16, 32) + + return color.RGBA{uint8(shift(r)), uint8(shift(g)), uint8(shift(b)), 255} //nolint:gosec + case strings.HasPrefix(s, "rgba:"): + parts := strings.Split(s[5:], "/") + if len(parts) != 4 { + return nil + } + + r, _ := strconv.ParseUint(parts[0], 16, 32) + g, _ := strconv.ParseUint(parts[1], 16, 32) + b, _ := strconv.ParseUint(parts[2], 16, 32) + a, _ := strconv.ParseUint(parts[3], 16, 32) + + return color.RGBA{uint8(shift(r)), uint8(shift(g)), uint8(shift(b)), uint8(shift(a))} //nolint:gosec + } + return nil +} + +type ordered interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | + ~float32 | ~float64 | + ~string +} + +func max[T ordered](a, b T) T { //nolint:predeclared + if a > b { + return a + } + return b +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/width.go b/source/vendor/github.com/charmbracelet/x/ansi/width.go index 80890e42c89c69652af813fff7603ac6f6010d2f..d0487d350b40b627f1d6b1e15920f5dcbee0ed6c 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/width.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/width.go @@ -4,6 +4,7 @@ import ( "bytes" "github.com/charmbracelet/x/ansi/parser" + "github.com/mattn/go-runewidth" "github.com/rivo/uniseg" ) @@ -62,7 +63,21 @@ func Strip(s string) string { // cells that the string will occupy when printed in a terminal. ANSI escape // codes are ignored and wide characters (such as East Asians and emojis) are // accounted for. +// This treats the text as a sequence of grapheme clusters. func StringWidth(s string) int { + return stringWidth(GraphemeWidth, s) +} + +// StringWidthWc returns the width of a string in cells. This is the number of +// cells that the string will occupy when printed in a terminal. ANSI escape +// codes are ignored and wide characters (such as East Asians and emojis) are +// accounted for. +// This treats the text as a sequence of wide characters and runes. +func StringWidthWc(s string) int { + return stringWidth(WcWidth, s) +} + +func stringWidth(m Method, s string) int { if s == "" { return 0 } @@ -78,6 +93,9 @@ func StringWidth(s string) int { if state == parser.Utf8State { var w int cluster, _, w, _ = uniseg.FirstGraphemeClusterInString(s[i:], -1) + if m == WcWidth { + w = runewidth.StringWidth(cluster) + } width += w i += len(cluster) - 1 pstate = parser.GroundState diff --git a/source/vendor/github.com/charmbracelet/x/ansi/winop.go b/source/vendor/github.com/charmbracelet/x/ansi/winop.go new file mode 100644 index 0000000000000000000000000000000000000000..0238780d0a099e0d6831a5d5df660cd4c9206cb6 --- /dev/null +++ b/source/vendor/github.com/charmbracelet/x/ansi/winop.go @@ -0,0 +1,53 @@ +package ansi + +import ( + "strconv" + "strings" +) + +const ( + // ResizeWindowWinOp is a window operation that resizes the terminal + // window. + ResizeWindowWinOp = 4 + + // RequestWindowSizeWinOp is a window operation that requests a report of + // the size of the terminal window in pixels. The response is in the form: + // CSI 4 ; height ; width t + RequestWindowSizeWinOp = 14 + + // RequestCellSizeWinOp is a window operation that requests a report of + // the size of the terminal cell size in pixels. The response is in the form: + // CSI 6 ; height ; width t + RequestCellSizeWinOp = 16 +) + +// WindowOp (XTWINOPS) is a sequence that manipulates the terminal window. +// +// CSI Ps ; Ps ; Ps t +// +// Ps is a semicolon-separated list of parameters. +// See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps;Ps;Ps-t.1EB0 +func WindowOp(p int, ps ...int) string { + if p <= 0 { + return "" + } + + if len(ps) == 0 { + return "\x1b[" + strconv.Itoa(p) + "t" + } + + params := make([]string, 0, len(ps)+1) + params = append(params, strconv.Itoa(p)) + for _, p := range ps { + if p >= 0 { + params = append(params, strconv.Itoa(p)) + } + } + + return "\x1b[" + strings.Join(params, ";") + "t" +} + +// XTWINOPS is an alias for [WindowOp]. +func XTWINOPS(p int, ps ...int) string { + return WindowOp(p, ps...) +} diff --git a/source/vendor/github.com/charmbracelet/x/ansi/wrap.go b/source/vendor/github.com/charmbracelet/x/ansi/wrap.go index 77d239a5a665d910791422bd91c3571519698f73..6b99580085bdbd560558c9bd8adf9bb4c3aed7c6 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/wrap.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/wrap.go @@ -6,6 +6,7 @@ import ( "unicode/utf8" "github.com/charmbracelet/x/ansi/parser" + "github.com/mattn/go-runewidth" "github.com/rivo/uniseg" ) @@ -17,7 +18,22 @@ const nbsp = 0xA0 // wide-characters in the string. // When preserveSpace is true, spaces at the beginning of a line will be // preserved. +// This treats the text as a sequence of graphemes. func Hardwrap(s string, limit int, preserveSpace bool) string { + return hardwrap(GraphemeWidth, s, limit, preserveSpace) +} + +// HardwrapWc wraps a string or a block of text to a given line length, breaking +// word boundaries. This will preserve ANSI escape codes and will account for +// wide-characters in the string. +// When preserveSpace is true, spaces at the beginning of a line will be +// preserved. +// This treats the text as a sequence of wide characters and runes. +func HardwrapWc(s string, limit int, preserveSpace bool) string { + return hardwrap(WcWidth, s, limit, preserveSpace) +} + +func hardwrap(m Method, s string, limit int, preserveSpace bool) string { if limit < 1 { return s } @@ -42,6 +58,9 @@ func Hardwrap(s string, limit int, preserveSpace bool) string { if state == parser.Utf8State { var width int cluster, _, width, _ = uniseg.FirstGraphemeCluster(b[i:], -1) + if m == WcWidth { + width = runewidth.StringWidth(string(cluster)) + } i += len(cluster) if curWidth+width > limit { @@ -108,7 +127,27 @@ func Hardwrap(s string, limit int, preserveSpace bool) string { // breakpoint. // // Note: breakpoints must be a string of 1-cell wide rune characters. +// +// This treats the text as a sequence of graphemes. func Wordwrap(s string, limit int, breakpoints string) string { + return wordwrap(GraphemeWidth, s, limit, breakpoints) +} + +// WordwrapWc wraps a string or a block of text to a given line length, not +// breaking word boundaries. This will preserve ANSI escape codes and will +// account for wide-characters in the string. +// The breakpoints string is a list of characters that are considered +// breakpoints for word wrapping. A hyphen (-) is always considered a +// breakpoint. +// +// Note: breakpoints must be a string of 1-cell wide rune characters. +// +// This treats the text as a sequence of wide characters and runes. +func WordwrapWc(s string, limit int, breakpoints string) string { + return wordwrap(WcWidth, s, limit, breakpoints) +} + +func wordwrap(m Method, s string, limit int, breakpoints string) string { if limit < 1 { return s } @@ -154,6 +193,9 @@ func Wordwrap(s string, limit int, breakpoints string) string { if state == parser.Utf8State { var width int cluster, _, width, _ = uniseg.FirstGraphemeCluster(b[i:], -1) + if m == WcWidth { + width = runewidth.StringWidth(string(cluster)) + } i += len(cluster) r, _ := utf8.DecodeRune(cluster) @@ -236,7 +278,26 @@ func Wordwrap(s string, limit int, breakpoints string) string { // (-) is always considered a breakpoint. // // Note: breakpoints must be a string of 1-cell wide rune characters. +// +// This treats the text as a sequence of graphemes. func Wrap(s string, limit int, breakpoints string) string { + return wrap(GraphemeWidth, s, limit, breakpoints) +} + +// WrapWc wraps a string or a block of text to a given line length, breaking word +// boundaries if necessary. This will preserve ANSI escape codes and will +// account for wide-characters in the string. The breakpoints string is a list +// of characters that are considered breakpoints for word wrapping. A hyphen +// (-) is always considered a breakpoint. +// +// Note: breakpoints must be a string of 1-cell wide rune characters. +// +// This treats the text as a sequence of wide characters and runes. +func WrapWc(s string, limit int, breakpoints string) string { + return wrap(WcWidth, s, limit, breakpoints) +} + +func wrap(m Method, s string, limit int, breakpoints string) string { if limit < 1 { return s } @@ -282,6 +343,9 @@ func Wrap(s string, limit int, breakpoints string) string { if state == parser.Utf8State { var width int cluster, _, width, _ = uniseg.FirstGraphemeCluster(b[i:], -1) + if m == WcWidth { + width = runewidth.StringWidth(string(cluster)) + } i += len(cluster) r, _ := utf8.DecodeRune(cluster) @@ -378,14 +442,17 @@ func Wrap(s string, limit int, breakpoints string) string { i++ } - if word.Len() != 0 { - // Preserve ANSI wrapped spaces at the end of string + if wordLen == 0 { if curWidth+space.Len() > limit { - buf.WriteByte('\n') + curWidth = 0 + } else { + // preserve whitespaces + buf.Write(space.Bytes()) } - addSpace() + space.Reset() } - buf.Write(word.Bytes()) + + addWord() return buf.String() } diff --git a/source/vendor/github.com/charmbracelet/x/ansi/xterm.go b/source/vendor/github.com/charmbracelet/x/ansi/xterm.go index f87712a64b1634227bc813cd1fd44e1066654077..83fd4bdc4e2b3e4bed978ec32094582c2926920e 100644 --- a/source/vendor/github.com/charmbracelet/x/ansi/xterm.go +++ b/source/vendor/github.com/charmbracelet/x/ansi/xterm.go @@ -2,6 +2,84 @@ package ansi import "strconv" +// KeyModifierOptions (XTMODKEYS) sets/resets xterm key modifier options. +// +// Default is 0. +// +// CSI > Pp m +// CSI > Pp ; Pv m +// +// If Pv is omitted, the resource is reset to its initial value. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ +func KeyModifierOptions(p int, vs ...int) string { + var pp, pv string + if p > 0 { + pp = strconv.Itoa(p) + } + + if len(vs) == 0 { + return "\x1b[>" + strconv.Itoa(p) + "m" + } + + v := vs[0] + if v > 0 { + pv = strconv.Itoa(v) + return "\x1b[>" + pp + ";" + pv + "m" + } + + return "\x1b[>" + pp + "m" +} + +// XTMODKEYS is an alias for [KeyModifierOptions]. +func XTMODKEYS(p int, vs ...int) string { + return KeyModifierOptions(p, vs...) +} + +// SetKeyModifierOptions sets xterm key modifier options. +// This is an alias for [KeyModifierOptions]. +func SetKeyModifierOptions(pp int, pv int) string { + return KeyModifierOptions(pp, pv) +} + +// ResetKeyModifierOptions resets xterm key modifier options. +// This is an alias for [KeyModifierOptions]. +func ResetKeyModifierOptions(pp int) string { + return KeyModifierOptions(pp) +} + +// QueryKeyModifierOptions (XTQMODKEYS) requests xterm key modifier options. +// +// Default is 0. +// +// CSI ? Pp m +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ +func QueryKeyModifierOptions(pp int) string { + var p string + if pp > 0 { + p = strconv.Itoa(pp) + } + return "\x1b[?" + p + "m" +} + +// XTQMODKEYS is an alias for [QueryKeyModifierOptions]. +func XTQMODKEYS(pp int) string { + return QueryKeyModifierOptions(pp) +} + +// Modify Other Keys (modifyOtherKeys) is an xterm feature that allows the +// terminal to modify the behavior of certain keys to send different escape +// sequences when pressed. +// +// See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys +const ( + SetModifyOtherKeys1 = "\x1b[>4;1m" + SetModifyOtherKeys2 = "\x1b[>4;2m" + ResetModifyOtherKeys = "\x1b[>4m" + QueryModifyOtherKeys = "\x1b[?4m" +) + // ModifyOtherKeys returns a sequence that sets XTerm modifyOtherKeys mode. // The mode argument specifies the mode to set. // @@ -13,6 +91,8 @@ import "strconv" // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys +// +// Deprecated: use [SetModifyOtherKeys1] or [SetModifyOtherKeys2] instead. func ModifyOtherKeys(mode int) string { return "\x1b[>4;" + strconv.Itoa(mode) + "m" } @@ -23,6 +103,8 @@ func ModifyOtherKeys(mode int) string { // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys +// +// Deprecated: use [ResetModifyOtherKeys] instead. const DisableModifyOtherKeys = "\x1b[>4;0m" // EnableModifyOtherKeys1 enables the modifyOtherKeys mode 1. @@ -31,6 +113,8 @@ const DisableModifyOtherKeys = "\x1b[>4;0m" // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys +// +// Deprecated: use [SetModifyOtherKeys1] instead. const EnableModifyOtherKeys1 = "\x1b[>4;1m" // EnableModifyOtherKeys2 enables the modifyOtherKeys mode 2. @@ -39,6 +123,8 @@ const EnableModifyOtherKeys1 = "\x1b[>4;1m" // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys +// +// Deprecated: use [SetModifyOtherKeys2] instead. const EnableModifyOtherKeys2 = "\x1b[>4;2m" // RequestModifyOtherKeys requests the modifyOtherKeys mode. @@ -47,4 +133,6 @@ const EnableModifyOtherKeys2 = "\x1b[>4;2m" // // See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ // See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys +// +// Deprecated: use [QueryModifyOtherKeys] instead. const RequestModifyOtherKeys = "\x1b[?4m" diff --git a/source/vendor/github.com/evanw/esbuild/internal/bundler/bundler.go b/source/vendor/github.com/evanw/esbuild/internal/bundler/bundler.go index 67d9e41f54ac6d7ec974e19c1a8258df07bc16f2..3b398ec18c2d6960c648586b2543981efe855538 100644 --- a/source/vendor/github.com/evanw/esbuild/internal/bundler/bundler.go +++ b/source/vendor/github.com/evanw/esbuild/internal/bundler/bundler.go @@ -120,11 +120,29 @@ type tlaCheck struct { } func parseFile(args parseArgs) { + pathForIdentifierName := args.keyPath.Text + + // Identifier name generation may use the name of the parent folder if the + // file name starts with "index". However, this is problematic when the + // parent folder includes the parent directory of what the developer + // considers to be the root of the source tree. If that happens, strip the + // parent folder to avoid including it in the generated name. + if relative, ok := args.fs.Rel(args.options.AbsOutputBase, pathForIdentifierName); ok { + for { + next := strings.TrimPrefix(strings.TrimPrefix(relative, "../"), "..\\") + if relative == next { + break + } + relative = next + } + pathForIdentifierName = relative + } + source := logger.Source{ Index: args.sourceIndex, KeyPath: args.keyPath, PrettyPath: args.prettyPath, - IdentifierName: js_ast.GenerateNonUniqueNameFromPath(args.keyPath.Text), + IdentifierName: js_ast.GenerateNonUniqueNameFromPath(pathForIdentifierName), } var loader config.Loader @@ -1857,15 +1875,20 @@ func (s *scanner) addEntryPoints(entryPoints []EntryPoint) []graph.EntryPoint { return nil } - // Parse all entry points that were resolved successfully + // Determine output paths for all entry points that were resolved successfully + type entryPointToParse struct { + index int + parse func() uint32 + } + var entryPointsToParse []entryPointToParse for i, info := range entryPointInfos { if info.results == nil { continue } for _, resolveResult := range info.results { + resolveResult := resolveResult prettyPath := resolver.PrettyPath(s.fs, resolveResult.PathPair.Primary) - sourceIndex := s.maybeParseFile(resolveResult, prettyPath, nil, logger.Range{}, nil, inputKindEntryPoint, nil) outputPath := entryPoints[i].OutputPath outputPathWasAutoGenerated := false @@ -1900,9 +1923,17 @@ func (s *scanner) addEntryPoints(entryPoints []EntryPoint) []graph.EntryPoint { outputPathWasAutoGenerated = true } + // Defer parsing for this entry point until later + entryPointsToParse = append(entryPointsToParse, entryPointToParse{ + index: len(entryMetas), + parse: func() uint32 { + return s.maybeParseFile(resolveResult, prettyPath, nil, logger.Range{}, nil, inputKindEntryPoint, nil) + }, + }) + entryMetas = append(entryMetas, graph.EntryPoint{ OutputPath: outputPath, - SourceIndex: sourceIndex, + SourceIndex: ast.InvalidRef.SourceIndex, OutputPathWasAutoGenerated: outputPathWasAutoGenerated, }) } @@ -1924,6 +1955,11 @@ func (s *scanner) addEntryPoints(entryPoints []EntryPoint) []graph.EntryPoint { } } + // Only parse entry points after "AbsOutputBase" has been determined + for _, toParse := range entryPointsToParse { + entryMetas[toParse.index].SourceIndex = toParse.parse() + } + // Turn all output paths back into relative paths, but this time relative to // the "outbase" value we computed above for i := range entryMetas { @@ -2541,11 +2577,13 @@ func (s *scanner) processScannedFiles(entryPointMeta []graph.EntryPoint) []scann // the entry point itself. customFilePath := "" useOutputFile := false + isEntryPoint := false if result.file.inputFile.Loader == config.LoaderCopy { if metaIndex, ok := entryPointSourceIndexToMetaIndex[uint32(sourceIndex)]; ok { template = s.options.EntryPathTemplate customFilePath = entryPointMeta[metaIndex].OutputPath useOutputFile = s.options.AbsOutputFile != "" + isEntryPoint = true } } @@ -2596,8 +2634,14 @@ func (s *scanner) processScannedFiles(entryPointMeta []graph.EntryPoint) []scann helpers.QuoteForJSON(result.file.inputFile.Source.PrettyPath, s.options.ASCIIOnly), len(bytes), ) + entryPointJSON := "" + if isEntryPoint { + entryPointJSON = fmt.Sprintf("\"entryPoint\": %s,\n ", + helpers.QuoteForJSON(result.file.inputFile.Source.PrettyPath, s.options.ASCIIOnly)) + } jsonMetadataChunk = fmt.Sprintf( - "{\n \"imports\": [],\n \"exports\": [],\n \"inputs\": %s,\n \"bytes\": %d\n }", + "{\n \"imports\": [],\n \"exports\": [],\n %s\"inputs\": %s,\n \"bytes\": %d\n }", + entryPointJSON, inputs, len(bytes), ) diff --git a/source/vendor/github.com/evanw/esbuild/internal/compat/css_table.go b/source/vendor/github.com/evanw/esbuild/internal/compat/css_table.go index 1cd717e0a544fc761f0123cea7fadce2c1f4c0e0..0ee1001ac0e414ba272acf79d0023334a4f6711c 100644 --- a/source/vendor/github.com/evanw/esbuild/internal/compat/css_table.go +++ b/source/vendor/github.com/evanw/esbuild/internal/compat/css_table.go @@ -198,13 +198,12 @@ var cssPrefixTable = map[css_ast.D][]prefixData{ {engine: Chrome, prefix: WebkitPrefix, withoutPrefix: v{120, 0, 0}}, {engine: Edge, prefix: MsPrefix, withoutPrefix: v{15, 0, 0}}, {engine: Edge, prefix: WebkitPrefix, withoutPrefix: v{120, 0, 0}}, - {engine: IOS, prefix: WebkitPrefix, withoutPrefix: v{14, 0, 0}}, {engine: Opera, prefix: WebkitPrefix, withoutPrefix: v{106, 0, 0}}, - {engine: Safari, prefix: WebkitPrefix, withoutPrefix: v{14, 0, 0}}, + {engine: Safari, prefix: WebkitPrefix, withoutPrefix: v{5, 0, 0}}, }, css_ast.DBoxDecorationBreak: { - {engine: Chrome, prefix: WebkitPrefix}, - {engine: Edge, prefix: WebkitPrefix}, + {engine: Chrome, prefix: WebkitPrefix, withoutPrefix: v{130, 0, 0}}, + {engine: Edge, prefix: WebkitPrefix, withoutPrefix: v{130, 0, 0}}, {engine: IOS, prefix: WebkitPrefix}, {engine: Opera, prefix: WebkitPrefix}, {engine: Safari, prefix: WebkitPrefix}, diff --git a/source/vendor/github.com/evanw/esbuild/internal/compat/js_table.go b/source/vendor/github.com/evanw/esbuild/internal/compat/js_table.go index 89180c3f665b24764205bc5c590c04dcc8d8c88e..18f2bbe1c6d4f1de3d6a58f8f7aed6437f75cca4 100644 --- a/source/vendor/github.com/evanw/esbuild/internal/compat/js_table.go +++ b/source/vendor/github.com/evanw/esbuild/internal/compat/js_table.go @@ -815,15 +815,14 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{ RegexpUnicodePropertyEscapes: { // Note: The latest version of "Chrome" failed this test: RegExp Unicode Property Escapes: Unicode 16.0 // Note: The latest version of "Edge" failed this test: RegExp Unicode Property Escapes: Unicode 16.0 - // Note: The latest version of "Firefox" failed 2 tests including: RegExp Unicode Property Escapes: Unicode 15.1 // Note: The latest version of "Hermes" failed 8 tests including: RegExp Unicode Property Escapes: Unicode 11 // Note: The latest version of "IE" failed 8 tests including: RegExp Unicode Property Escapes: Unicode 11 // Note: The latest version of "IOS" failed this test: RegExp Unicode Property Escapes: Unicode 16.0 - // Note: The latest version of "Node" failed this test: RegExp Unicode Property Escapes: Unicode 16.0 // Note: The latest version of "Rhino" failed 8 tests including: RegExp Unicode Property Escapes: Unicode 11 // Note: The latest version of "Safari" failed this test: RegExp Unicode Property Escapes: Unicode 16.0 - ES: {{start: v{2018, 0, 0}}}, - Opera: {{start: v{111, 0, 0}}}, + ES: {{start: v{2018, 0, 0}}}, + Firefox: {{start: v{134, 0, 0}}}, + Node: {{start: v{22, 12, 0}, end: v{23, 0, 0}}, {start: v{23, 3, 0}}}, }, RestArgument: { // Note: The latest version of "Hermes" failed this test: rest parameters: function 'length' property diff --git a/source/vendor/github.com/evanw/esbuild/internal/config/globals.go b/source/vendor/github.com/evanw/esbuild/internal/config/globals.go index 4a77c0267c088baacffc798a31b35a94f4d89cd7..1bbc9786f8cba482a9004a0b82b83b27de97ab1b 100644 --- a/source/vendor/github.com/evanw/esbuild/internal/config/globals.go +++ b/source/vendor/github.com/evanw/esbuild/internal/config/globals.go @@ -2,7 +2,6 @@ package config import ( "math" - "strings" "sync" "github.com/evanw/esbuild/internal/ast" @@ -868,6 +867,7 @@ type DefineExpr struct { } type DefineData struct { + KeyParts []string DefineExpr *DefineExpr Flags DefineFlags } @@ -905,14 +905,9 @@ func mergeDefineData(old DefineData, new DefineData) DefineData { return new } -type DotDefine struct { - Data DefineData - Parts []string -} - type ProcessedDefines struct { IdentifierDefines map[string]DefineData - DotDefines map[string][]DotDefine + DotDefines map[string][]DefineData } // This transformation is expensive, so we only want to do it once. Make sure @@ -920,7 +915,7 @@ type ProcessedDefines struct { // doesn't have an efficient way to copy a map and the overhead of copying // all of the properties into a new map once for every new parser noticeably // slows down our benchmarks. -func ProcessDefines(userDefines map[string]DefineData) ProcessedDefines { +func ProcessDefines(userDefines []DefineData) ProcessedDefines { // Optimization: reuse known globals if there are no user-specified defines hasUserDefines := len(userDefines) != 0 if !hasUserDefines { @@ -934,7 +929,7 @@ func ProcessDefines(userDefines map[string]DefineData) ProcessedDefines { result := ProcessedDefines{ IdentifierDefines: make(map[string]DefineData), - DotDefines: make(map[string][]DotDefine), + DotDefines: make(map[string][]DefineData), } // Mark these property accesses as free of side effects. That means they can @@ -956,7 +951,7 @@ func ProcessDefines(userDefines map[string]DefineData) ProcessedDefines { flags |= IsSymbolInstance } - result.DotDefines[tail] = append(result.DotDefines[tail], DotDefine{Parts: parts, Data: DefineData{Flags: flags}}) + result.DotDefines[tail] = append(result.DotDefines[tail], DefineData{KeyParts: parts, Flags: flags}) } } @@ -973,31 +968,29 @@ func ProcessDefines(userDefines map[string]DefineData) ProcessedDefines { // Then copy the user-specified defines in afterwards, which will overwrite // any known globals above. - for key, data := range userDefines { - parts := strings.Split(key, ".") - + for _, data := range userDefines { // Identifier defines are special-cased - if len(parts) == 1 { - result.IdentifierDefines[key] = mergeDefineData(result.IdentifierDefines[key], data) + if len(data.KeyParts) == 1 { + name := data.KeyParts[0] + result.IdentifierDefines[name] = mergeDefineData(result.IdentifierDefines[name], data) continue } - tail := parts[len(parts)-1] + tail := data.KeyParts[len(data.KeyParts)-1] dotDefines := result.DotDefines[tail] found := false // Try to merge with existing dot defines first for i, define := range dotDefines { - if helpers.StringArraysEqual(parts, define.Parts) { - define := &dotDefines[i] - define.Data = mergeDefineData(define.Data, data) + if helpers.StringArraysEqual(data.KeyParts, define.KeyParts) { + dotDefines[i] = mergeDefineData(dotDefines[i], data) found = true break } } if !found { - dotDefines = append(dotDefines, DotDefine{Parts: parts, Data: data}) + dotDefines = append(dotDefines, data) } result.DotDefines[tail] = dotDefines } diff --git a/source/vendor/github.com/evanw/esbuild/internal/js_parser/global_name_parser.go b/source/vendor/github.com/evanw/esbuild/internal/js_parser/global_name_parser.go index 0064990b75a603a3e91fa999e5c4c8c9b88d06ce..78649ead8aa60ba4eb30106c53a5d050063443aa 100644 --- a/source/vendor/github.com/evanw/esbuild/internal/js_parser/global_name_parser.go +++ b/source/vendor/github.com/evanw/esbuild/internal/js_parser/global_name_parser.go @@ -19,9 +19,22 @@ func ParseGlobalName(log logger.Log, source logger.Source) (result []string, ok lexer := js_lexer.NewLexerGlobalName(log, source) - // Start off with an identifier + // Start off with an identifier or a keyword that results in an object result = append(result, lexer.Identifier.String) - lexer.Expect(js_lexer.TIdentifier) + switch lexer.Token { + case js_lexer.TThis: + lexer.Next() + + case js_lexer.TImport: + // Handle "import.meta" + lexer.Next() + lexer.Expect(js_lexer.TDot) + result = append(result, lexer.Identifier.String) + lexer.ExpectContextualKeyword("meta") + + default: + lexer.Expect(js_lexer.TIdentifier) + } // Follow with dot or index expressions for lexer.Token != js_lexer.TEndOfFile { diff --git a/source/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go b/source/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go index 45daca94c3ff1f9d4a26bf0e2d170aaa2b6da534..01c3fde9fa60787f8c9dc9945fbc39dd3cc59bd7 100644 --- a/source/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go +++ b/source/vendor/github.com/evanw/esbuild/internal/js_parser/js_parser.go @@ -2136,47 +2136,50 @@ func (p *parser) parseProperty(startLoc logger.Loc, kind js_ast.PropertyKind, op couldBeModifierKeyword := p.lexer.IsIdentifierOrKeyword() if !couldBeModifierKeyword { switch p.lexer.Token { - case js_lexer.TOpenBracket, js_lexer.TNumericLiteral, js_lexer.TStringLiteral, - js_lexer.TAsterisk, js_lexer.TPrivateIdentifier: + case js_lexer.TOpenBracket, js_lexer.TNumericLiteral, js_lexer.TStringLiteral, js_lexer.TPrivateIdentifier: couldBeModifierKeyword = true + case js_lexer.TAsterisk: + if opts.isAsync || (raw != "get" && raw != "set") { + couldBeModifierKeyword = true + } } } // If so, check for a modifier keyword if couldBeModifierKeyword { - switch name.String { + switch raw { case "get": - if !opts.isAsync && raw == name.String { + if !opts.isAsync { p.markSyntaxFeature(compat.ObjectAccessors, nameRange) return p.parseProperty(startLoc, js_ast.PropertyGetter, opts, nil) } case "set": - if !opts.isAsync && raw == name.String { + if !opts.isAsync { p.markSyntaxFeature(compat.ObjectAccessors, nameRange) return p.parseProperty(startLoc, js_ast.PropertySetter, opts, nil) } case "accessor": - if !p.lexer.HasNewlineBefore && !opts.isAsync && opts.isClass && raw == name.String { + if !p.lexer.HasNewlineBefore && !opts.isAsync && opts.isClass { return p.parseProperty(startLoc, js_ast.PropertyAutoAccessor, opts, nil) } case "async": - if !p.lexer.HasNewlineBefore && !opts.isAsync && raw == name.String { + if !p.lexer.HasNewlineBefore && !opts.isAsync { opts.isAsync = true opts.asyncRange = nameRange return p.parseProperty(startLoc, js_ast.PropertyMethod, opts, nil) } case "static": - if !opts.isStatic && !opts.isAsync && opts.isClass && raw == name.String { + if !opts.isStatic && !opts.isAsync && opts.isClass { opts.isStatic = true return p.parseProperty(startLoc, kind, opts, nil) } case "declare": - if !p.lexer.HasNewlineBefore && opts.isClass && p.options.ts.Parse && opts.tsDeclareRange.Len == 0 && raw == name.String { + if !p.lexer.HasNewlineBefore && opts.isClass && p.options.ts.Parse && opts.tsDeclareRange.Len == 0 { opts.tsDeclareRange = nameRange scopeIndex := len(p.scopesInOrder) @@ -2213,7 +2216,7 @@ func (p *parser) parseProperty(startLoc logger.Loc, kind js_ast.PropertyKind, op } case "abstract": - if !p.lexer.HasNewlineBefore && opts.isClass && p.options.ts.Parse && !opts.isTSAbstract && raw == name.String { + if !p.lexer.HasNewlineBefore && opts.isClass && p.options.ts.Parse && !opts.isTSAbstract { opts.isTSAbstract = true scopeIndex := len(p.scopesInOrder) @@ -2249,7 +2252,7 @@ func (p *parser) parseProperty(startLoc logger.Loc, kind js_ast.PropertyKind, op case "private", "protected", "public", "readonly", "override": // Skip over TypeScript keywords - if opts.isClass && p.options.ts.Parse && raw == name.String { + if opts.isClass && p.options.ts.Parse { return p.parseProperty(startLoc, kind, opts, nil) } } @@ -10771,6 +10774,13 @@ func (p *parser) visitAndAppendStmt(stmts []js_ast.Stmt, stmt js_ast.Stmt) []js_ p.popScope() if s.Catch != nil { + old := p.isControlFlowDead + + // If the try body is empty, then the catch body is dead + if len(s.Block.Stmts) == 0 { + p.isControlFlowDead = true + } + p.pushScopeForVisitPass(js_ast.ScopeCatchBinding, s.Catch.Loc) if s.Catch.BindingOrNil.Data != nil { p.visitBinding(s.Catch.BindingOrNil, bindingOpts{}) @@ -10782,6 +10792,8 @@ func (p *parser) visitAndAppendStmt(stmts []js_ast.Stmt, stmt js_ast.Stmt) []js_ p.lowerObjectRestInCatchBinding(s.Catch) p.popScope() + + p.isControlFlowDead = old } if s.Finally != nil { @@ -10790,6 +10802,44 @@ func (p *parser) visitAndAppendStmt(stmts []js_ast.Stmt, stmt js_ast.Stmt) []js_ p.popScope() } + // Drop the whole thing if the try body is empty + if p.options.minifySyntax && len(s.Block.Stmts) == 0 { + keepCatch := false + + // Certain "catch" blocks need to be preserved: + // + // try {} catch { let foo } // Can be removed + // try {} catch { var foo } // Must be kept + // + if s.Catch != nil { + for _, stmt2 := range s.Catch.Block.Stmts { + if shouldKeepStmtInDeadControlFlow(stmt2) { + keepCatch = true + break + } + } + } + + // Make sure to preserve the "finally" block if present + if !keepCatch { + if s.Finally == nil { + return stmts + } + finallyNeedsBlock := false + for _, stmt2 := range s.Finally.Block.Stmts { + if statementCaresAboutScope(stmt2) { + finallyNeedsBlock = true + break + } + } + if !finallyNeedsBlock { + return append(stmts, s.Finally.Block.Stmts...) + } + block := s.Finally.Block + stmt = js_ast.Stmt{Loc: s.Finally.Loc, Data: &block} + } + } + case *js_ast.SSwitch: s.Test = p.visitExpr(s.Test) p.pushScopeForVisitPass(js_ast.ScopeBlock, s.BodyLoc) @@ -11972,8 +12022,8 @@ func (p *parser) instantiateDefineExpr(loc logger.Loc, expr config.DefineExpr, o // Substitute user-specified defines if defines, ok := p.options.defines.DotDefines[parts[len(parts)-1]]; ok { for _, define := range defines { - if define.Data.DefineExpr != nil && helpers.StringArraysEqual(define.Parts, parts) { - return p.instantiateDefineExpr(loc, *define.Data.DefineExpr, opts) + if define.DefineExpr != nil && helpers.StringArraysEqual(define.KeyParts, parts) { + return p.instantiateDefineExpr(loc, *define.DefineExpr, opts) } } } @@ -12906,10 +12956,10 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO // Check both user-specified defines and known globals if defines, ok := p.options.defines.DotDefines["meta"]; ok { for _, define := range defines { - if p.isDotOrIndexDefineMatch(expr, define.Parts) { + if p.isDotOrIndexDefineMatch(expr, define.KeyParts) { // Substitute user-specified defines - if define.Data.DefineExpr != nil { - return p.instantiateDefineExpr(expr.Loc, *define.Data.DefineExpr, identifierOpts{ + if define.DefineExpr != nil { + return p.instantiateDefineExpr(expr.Loc, *define.DefineExpr, identifierOpts{ assignTarget: in.assignTarget, isCallTarget: isCallTarget, isDeleteTarget: isDeleteTarget, @@ -13537,10 +13587,10 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO // Check both user-specified defines and known globals if defines, ok := p.options.defines.DotDefines[e.Name]; ok { for _, define := range defines { - if p.isDotOrIndexDefineMatch(expr, define.Parts) { + if p.isDotOrIndexDefineMatch(expr, define.KeyParts) { // Substitute user-specified defines - if define.Data.DefineExpr != nil { - new := p.instantiateDefineExpr(expr.Loc, *define.Data.DefineExpr, identifierOpts{ + if define.DefineExpr != nil { + new := p.instantiateDefineExpr(expr.Loc, *define.DefineExpr, identifierOpts{ assignTarget: in.assignTarget, isCallTarget: isCallTarget, isDeleteTarget: isDeleteTarget, @@ -13556,13 +13606,13 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO } // Copy the side effect flags over in case this expression is unused - if define.Data.Flags.Has(config.CanBeRemovedIfUnused) { + if define.Flags.Has(config.CanBeRemovedIfUnused) { e.CanBeRemovedIfUnused = true } - if define.Data.Flags.Has(config.CallCanBeUnwrappedIfUnused) && !p.options.ignoreDCEAnnotations { + if define.Flags.Has(config.CallCanBeUnwrappedIfUnused) && !p.options.ignoreDCEAnnotations { e.CallCanBeUnwrappedIfUnused = true } - if define.Data.Flags.Has(config.IsSymbolInstance) { + if define.Flags.Has(config.IsSymbolInstance) { e.IsSymbolInstance = true } break @@ -13659,10 +13709,10 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO if str, ok := e.Index.Data.(*js_ast.EString); ok { if defines, ok := p.options.defines.DotDefines[helpers.UTF16ToString(str.Value)]; ok { for _, define := range defines { - if p.isDotOrIndexDefineMatch(expr, define.Parts) { + if p.isDotOrIndexDefineMatch(expr, define.KeyParts) { // Substitute user-specified defines - if define.Data.DefineExpr != nil { - new := p.instantiateDefineExpr(expr.Loc, *define.Data.DefineExpr, identifierOpts{ + if define.DefineExpr != nil { + new := p.instantiateDefineExpr(expr.Loc, *define.DefineExpr, identifierOpts{ assignTarget: in.assignTarget, isCallTarget: isCallTarget, isDeleteTarget: isDeleteTarget, @@ -13682,13 +13732,13 @@ func (p *parser) visitExprInOut(expr js_ast.Expr, in exprIn) (js_ast.Expr, exprO } // Copy the side effect flags over in case this expression is unused - if define.Data.Flags.Has(config.CanBeRemovedIfUnused) { + if define.Flags.Has(config.CanBeRemovedIfUnused) { e.CanBeRemovedIfUnused = true } - if define.Data.Flags.Has(config.CallCanBeUnwrappedIfUnused) && !p.options.ignoreDCEAnnotations { + if define.Flags.Has(config.CallCanBeUnwrappedIfUnused) && !p.options.ignoreDCEAnnotations { e.CallCanBeUnwrappedIfUnused = true } - if define.Data.Flags.Has(config.IsSymbolInstance) { + if define.Flags.Has(config.IsSymbolInstance) { e.IsSymbolInstance = true } break diff --git a/source/vendor/github.com/evanw/esbuild/internal/linker/linker.go b/source/vendor/github.com/evanw/esbuild/internal/linker/linker.go index 219fe8e614b2a5cb138f489b5ba1c89901aac1e2..f1d6c83d5a06f7dd1ec4cf04fd356839ef7fd7ad 100644 --- a/source/vendor/github.com/evanw/esbuild/internal/linker/linker.go +++ b/source/vendor/github.com/evanw/esbuild/internal/linker/linker.go @@ -5849,6 +5849,16 @@ func (c *linkerContext) generateChunkJS(chunkIndex int, chunkWaitGroup *sync.Wai // Ignore empty source map chunks if compileResult.SourceMapChunk.ShouldIgnore { prevOffset.AdvanceBytes(compileResult.JS) + + // Include a null entry in the source map + if len(compileResult.JS) > 0 && c.options.SourceMap != config.SourceMapNone { + if n := len(compileResultsForSourceMap); n > 0 && !compileResultsForSourceMap[n-1].isNullEntry { + compileResultsForSourceMap = append(compileResultsForSourceMap, compileResultForSourceMap{ + sourceIndex: compileResult.sourceIndex, + isNullEntry: true, + }) + } + } } else { prevOffset = sourcemap.LineColumnOffset{} @@ -5963,7 +5973,7 @@ func (c *linkerContext) generateChunkJS(chunkIndex int, chunkWaitGroup *sync.Wai func (c *linkerContext) generateGlobalNamePrefix() string { var text string globalName := c.options.GlobalName - prefix := globalName[0] + prefix, globalName := globalName[0], globalName[1:] space := " " join := ";\n" @@ -5972,9 +5982,18 @@ func (c *linkerContext) generateGlobalNamePrefix() string { join = ";" } + // Assume the "this" and "import.meta" objects always exist + isExistingObject := prefix == "this" + if prefix == "import" && len(globalName) > 0 && globalName[0] == "meta" { + prefix, globalName = "import.meta", globalName[1:] + isExistingObject = true + } + // Use "||=" to make the code more compact when it's supported - if len(globalName) > 1 && !c.options.UnsupportedJSFeatures.Has(compat.LogicalAssignment) { - if js_printer.CanEscapeIdentifier(prefix, c.options.UnsupportedJSFeatures, c.options.ASCIIOnly) { + if len(globalName) > 0 && !c.options.UnsupportedJSFeatures.Has(compat.LogicalAssignment) { + if isExistingObject { + // Keep the prefix as it is + } else if js_printer.CanEscapeIdentifier(prefix, c.options.UnsupportedJSFeatures, c.options.ASCIIOnly) { if c.options.ASCIIOnly { prefix = string(js_printer.QuoteIdentifier(nil, prefix, c.options.UnsupportedJSFeatures)) } @@ -5982,7 +6001,7 @@ func (c *linkerContext) generateGlobalNamePrefix() string { } else { prefix = fmt.Sprintf("this[%s]", helpers.QuoteForJSON(prefix, c.options.ASCIIOnly)) } - for _, name := range globalName[1:] { + for _, name := range globalName { var dotOrIndex string if js_printer.CanEscapeIdentifier(name, c.options.UnsupportedJSFeatures, c.options.ASCIIOnly) { if c.options.ASCIIOnly { @@ -5992,12 +6011,19 @@ func (c *linkerContext) generateGlobalNamePrefix() string { } else { dotOrIndex = fmt.Sprintf("[%s]", helpers.QuoteForJSON(name, c.options.ASCIIOnly)) } - prefix = fmt.Sprintf("(%s%s||=%s{})%s", prefix, space, space, dotOrIndex) + if isExistingObject { + prefix = fmt.Sprintf("%s%s", prefix, dotOrIndex) + isExistingObject = false + } else { + prefix = fmt.Sprintf("(%s%s||=%s{})%s", prefix, space, space, dotOrIndex) + } } return fmt.Sprintf("%s%s%s=%s", text, prefix, space, space) } - if js_printer.CanEscapeIdentifier(prefix, c.options.UnsupportedJSFeatures, c.options.ASCIIOnly) { + if isExistingObject { + text = fmt.Sprintf("%s%s=%s", prefix, space, space) + } else if js_printer.CanEscapeIdentifier(prefix, c.options.UnsupportedJSFeatures, c.options.ASCIIOnly) { if c.options.ASCIIOnly { prefix = string(js_printer.QuoteIdentifier(nil, prefix, c.options.UnsupportedJSFeatures)) } @@ -6007,7 +6033,7 @@ func (c *linkerContext) generateGlobalNamePrefix() string { text = fmt.Sprintf("%s%s=%s", prefix, space, space) } - for _, name := range globalName[1:] { + for _, name := range globalName { oldPrefix := prefix if js_printer.CanEscapeIdentifier(name, c.options.UnsupportedJSFeatures, c.options.ASCIIOnly) { if c.options.ASCIIOnly { @@ -6330,6 +6356,16 @@ func (c *linkerContext) generateChunkCSS(chunkIndex int, chunkWaitGroup *sync.Wa // Ignore empty source map chunks if compileResult.SourceMapChunk.ShouldIgnore { prevOffset.AdvanceBytes(compileResult.CSS) + + // Include a null entry in the source map + if len(compileResult.CSS) > 0 && c.options.SourceMap != config.SourceMapNone && compileResult.sourceIndex.IsValid() { + if n := len(compileResultsForSourceMap); n > 0 && !compileResultsForSourceMap[n-1].isNullEntry { + compileResultsForSourceMap = append(compileResultsForSourceMap, compileResultForSourceMap{ + sourceIndex: compileResult.sourceIndex.GetIndex(), + isNullEntry: true, + }) + } + } } else { prevOffset = sourcemap.LineColumnOffset{} @@ -6902,6 +6938,7 @@ type compileResultForSourceMap struct { sourceMapChunk sourcemap.Chunk generatedOffset sourcemap.LineColumnOffset sourceIndex uint32 + isNullEntry bool } func (c *linkerContext) generateSourceMapForChunk( @@ -6929,6 +6966,9 @@ func (c *linkerContext) generateSourceMapForChunk( continue } sourceIndexToSourcesIndex[result.sourceIndex] = nextSourcesIndex + if result.isNullEntry { + continue + } file := &c.graph.Files[result.sourceIndex] // Simple case: no nested source map @@ -7044,28 +7084,38 @@ func (c *linkerContext) generateSourceMapForChunk( startState.GeneratedColumn += prevColumnOffset } - // Append the precomputed source map chunk - sourcemap.AppendSourceMapChunk(&j, prevEndState, startState, chunk.Buffer) + if result.isNullEntry { + // Emit a "null" mapping + chunk.Buffer.Data = []byte("A") + sourcemap.AppendSourceMapChunk(&j, prevEndState, startState, chunk.Buffer) - // Generate the relative offset to start from next time - prevOriginalName := prevEndState.OriginalName - prevEndState = chunk.EndState - prevEndState.SourceIndex += sourcesIndex - if chunk.Buffer.FirstNameOffset.IsValid() { - prevEndState.OriginalName += totalQuotedNameLen + // Only the generated position was advanced + prevEndState.GeneratedLine = startState.GeneratedLine + prevEndState.GeneratedColumn = startState.GeneratedColumn } else { - // It's possible for a chunk to have mappings but for none of those - // mappings to have an associated name. The name is optional and is - // omitted when the mapping is for a non-name token or if the final - // and original names are the same. In that case we need to restore - // the previous original name end state since it wasn't modified after - // all. If we don't do this, then files after this will adjust their - // name offsets assuming that the previous generated mapping has this - // file's offset, which is wrong. - prevEndState.OriginalName = prevOriginalName - } - prevColumnOffset = chunk.FinalGeneratedColumn - totalQuotedNameLen += len(chunk.QuotedNames) + // Append the precomputed source map chunk + sourcemap.AppendSourceMapChunk(&j, prevEndState, startState, chunk.Buffer) + + // Generate the relative offset to start from next time + prevOriginalName := prevEndState.OriginalName + prevEndState = chunk.EndState + prevEndState.SourceIndex += sourcesIndex + if chunk.Buffer.FirstNameOffset.IsValid() { + prevEndState.OriginalName += totalQuotedNameLen + } else { + // It's possible for a chunk to have mappings but for none of those + // mappings to have an associated name. The name is optional and is + // omitted when the mapping is for a non-name token or if the final + // and original names are the same. In that case we need to restore + // the previous original name end state since it wasn't modified after + // all. If we don't do this, then files after this will adjust their + // name offsets assuming that the previous generated mapping has this + // file's offset, which is wrong. + prevEndState.OriginalName = prevOriginalName + } + prevColumnOffset = chunk.FinalGeneratedColumn + totalQuotedNameLen += len(chunk.QuotedNames) + } // If this was all one line, include the column offset from the start if prevEndState.GeneratedLine == 0 { diff --git a/source/vendor/github.com/evanw/esbuild/internal/resolver/tsconfig_json.go b/source/vendor/github.com/evanw/esbuild/internal/resolver/tsconfig_json.go index edfc7755cee6d435de06daecc7695461348cd420..1f9063e58a9db181821ef2e6cbde7a44b7fc6079 100644 --- a/source/vendor/github.com/evanw/esbuild/internal/resolver/tsconfig_json.go +++ b/source/vendor/github.com/evanw/esbuild/internal/resolver/tsconfig_json.go @@ -221,7 +221,7 @@ func ParseTSConfigJSON( switch lowerValue { case "es3", "es5", "es6", "es2015", "es2016", "es2017", "es2018", "es2019", "es2020", "es2021": result.Settings.Target = config.TSTargetBelowES2022 - case "es2022", "es2023", "esnext": + case "es2022", "es2023", "es2024", "esnext": result.Settings.Target = config.TSTargetAtOrAboveES2022 default: ok = false diff --git a/source/vendor/github.com/evanw/esbuild/internal/sourcemap/sourcemap.go b/source/vendor/github.com/evanw/esbuild/internal/sourcemap/sourcemap.go index 93effc2102e58a77bb6463846d8cf540f657b435..4d759dbbaec892321753adce9b4535c184620096 100644 --- a/source/vendor/github.com/evanw/esbuild/internal/sourcemap/sourcemap.go +++ b/source/vendor/github.com/evanw/esbuild/internal/sourcemap/sourcemap.go @@ -2,6 +2,7 @@ package sourcemap import ( "bytes" + "strings" "unicode/utf8" "github.com/evanw/esbuild/internal/ast" @@ -315,14 +316,14 @@ func (pieces SourceMapPieces) Finalize(shifts []SourceMapShift) []byte { potentialStartOfRun := current - // Skip over the original position information - _, current = DecodeVLQ(pieces.Mappings, current) // The original source - _, current = DecodeVLQ(pieces.Mappings, current) // The original line - _, current = DecodeVLQ(pieces.Mappings, current) // The original column - - // Skip over the original name + // Skip over the original position information if present if current < len(pieces.Mappings) { - if c := pieces.Mappings[current]; c != ',' && c != ';' { + _, current = DecodeVLQ(pieces.Mappings, current) // The original source + _, current = DecodeVLQ(pieces.Mappings, current) // The original line + _, current = DecodeVLQ(pieces.Mappings, current) // The original column + + // Skip over the original name if present + if current < len(pieces.Mappings) { _, current = DecodeVLQ(pieces.Mappings, current) } } @@ -426,20 +427,28 @@ func AppendSourceMapChunk(j *helpers.Joiner, prevEndState SourceMapState, startS // case below instead. Original names are optional and are often omitted, so // we handle it uniformly by saving an index to the first original name, // which may or may not be a part of the first mapping. + var sourceIndex int + var originalLine int + var originalColumn int + omitSource := false generatedColumn, i := DecodeVLQ(buffer.Data, semicolons) - sourceIndex, i := DecodeVLQ(buffer.Data, i) - originalLine, i := DecodeVLQ(buffer.Data, i) - originalColumn, i := DecodeVLQ(buffer.Data, i) + if i == len(buffer.Data) || strings.IndexByte(",;", buffer.Data[i]) != -1 { + omitSource = true + } else { + sourceIndex, i = DecodeVLQ(buffer.Data, i) + originalLine, i = DecodeVLQ(buffer.Data, i) + originalColumn, i = DecodeVLQ(buffer.Data, i) + } // Rewrite the first mapping to be relative to the end state of the previous // chunk. We now know what the end state is because we're in the second pass // where all chunks have already been generated. - startState.SourceIndex += sourceIndex startState.GeneratedColumn += generatedColumn + startState.SourceIndex += sourceIndex startState.OriginalLine += originalLine startState.OriginalColumn += originalColumn prevEndState.HasOriginalName = false // This is handled separately below - rewritten, _ := appendMappingToBuffer(nil, j.LastByte(), prevEndState, startState) + rewritten, _ := appendMappingToBuffer(nil, j.LastByte(), prevEndState, startState, omitSource) j.AddBytes(rewritten) // Next, if there's an original name, we need to rewrite that as well to be @@ -458,7 +467,9 @@ func AppendSourceMapChunk(j *helpers.Joiner, prevEndState SourceMapState, startS j.AddBytes(buffer.Data[i:]) } -func appendMappingToBuffer(buffer []byte, lastByte byte, prevState SourceMapState, currentState SourceMapState) ([]byte, ast.Index32) { +func appendMappingToBuffer( + buffer []byte, lastByte byte, prevState SourceMapState, currentState SourceMapState, omitSource bool, +) ([]byte, ast.Index32) { // Put commas in between mappings if lastByte != 0 && lastByte != ';' && lastByte != '"' { buffer = append(buffer, ',') @@ -466,9 +477,11 @@ func appendMappingToBuffer(buffer []byte, lastByte byte, prevState SourceMapStat // Record the mapping (note that the generated line is recorded using ';' elsewhere) buffer = encodeVLQ(buffer, currentState.GeneratedColumn-prevState.GeneratedColumn) - buffer = encodeVLQ(buffer, currentState.SourceIndex-prevState.SourceIndex) - buffer = encodeVLQ(buffer, currentState.OriginalLine-prevState.OriginalLine) - buffer = encodeVLQ(buffer, currentState.OriginalColumn-prevState.OriginalColumn) + if !omitSource { + buffer = encodeVLQ(buffer, currentState.SourceIndex-prevState.SourceIndex) + buffer = encodeVLQ(buffer, currentState.OriginalLine-prevState.OriginalLine) + buffer = encodeVLQ(buffer, currentState.OriginalColumn-prevState.OriginalColumn) + } // Record the optional original name var nameOffset ast.Index32 @@ -820,7 +833,7 @@ func (b *ChunkBuilder) appendMappingWithoutRemapping(currentState SourceMapState } var nameOffset ast.Index32 - b.sourceMap, nameOffset = appendMappingToBuffer(b.sourceMap, lastByte, b.prevState, currentState) + b.sourceMap, nameOffset = appendMappingToBuffer(b.sourceMap, lastByte, b.prevState, currentState, false) prevOriginalName := b.prevState.OriginalName b.prevState = currentState if !currentState.HasOriginalName { diff --git a/source/vendor/github.com/evanw/esbuild/pkg/api/api_impl.go b/source/vendor/github.com/evanw/esbuild/pkg/api/api_impl.go index 7c737779e0f8f3015d544aad996659da8ab9a5b1..d294d366b9dbefc3daf8572a1f040422a560c5b5 100644 --- a/source/vendor/github.com/evanw/esbuild/pkg/api/api_impl.go +++ b/source/vendor/github.com/evanw/esbuild/pkg/api/api_impl.go @@ -386,11 +386,11 @@ func validateSupported(log logger.Log, supported map[string]bool) ( return } -func validateGlobalName(log logger.Log, text string) []string { +func validateGlobalName(log logger.Log, text string, path string) []string { if text != "" { source := logger.Source{ - KeyPath: logger.Path{Text: "(global path)"}, - PrettyPath: "(global name)", + KeyPath: logger.Path{Text: path}, + PrettyPath: path, Contents: text, } @@ -524,6 +524,18 @@ func validateJSXExpr(log logger.Log, text string, name string) config.DefineExpr return config.DefineExpr{} } +// This returns an arbitrary but unique key for each unique array of strings +func mapKeyForDefine(parts []string) string { + var sb strings.Builder + var n [4]byte + for _, part := range parts { + binary.LittleEndian.PutUint32(n[:], uint32(len(part))) + sb.Write(n[:]) + sb.WriteString(part) + } + return sb.String() +} + func validateDefines( log logger.Log, defines map[string]string, @@ -533,32 +545,36 @@ func validateDefines( minify bool, drop Drop, ) (*config.ProcessedDefines, []config.InjectedDefine) { + // Sort injected defines for determinism, since the imports will be injected + // into every file in the order that we return them from this function + sortedKeys := make([]string, 0, len(defines)) + for key := range defines { + sortedKeys = append(sortedKeys, key) + } + sort.Strings(sortedKeys) + rawDefines := make(map[string]config.DefineData) - var valueToInject map[string]config.InjectedDefine - var definesToInject []string - - for key, value := range defines { - // The key must be a dot-separated identifier list - for _, part := range strings.Split(key, ".") { - if !js_ast.IsIdentifier(part) { - if part == key { - log.AddError(nil, logger.Range{}, fmt.Sprintf("The define key %q must be a valid identifier", key)) - } else { - log.AddError(nil, logger.Range{}, fmt.Sprintf("The define key %q contains invalid identifier %q", key, part)) - } - continue - } + nodeEnvParts := []string{"process", "env", "NODE_ENV"} + nodeEnvMapKey := mapKeyForDefine(nodeEnvParts) + var injectedDefines []config.InjectedDefine + + for _, key := range sortedKeys { + value := defines[key] + keyParts := validateGlobalName(log, key, "(define name)") + if keyParts == nil { + continue } + mapKey := mapKeyForDefine(keyParts) // Parse the value defineExpr, injectExpr := js_parser.ParseDefineExprOrJSON(value) // Define simple expressions if defineExpr.Constant != nil || len(defineExpr.Parts) > 0 { - rawDefines[key] = config.DefineData{DefineExpr: &defineExpr} + rawDefines[mapKey] = config.DefineData{KeyParts: keyParts, DefineExpr: &defineExpr} // Try to be helpful for common mistakes - if len(defineExpr.Parts) == 1 && key == "process.env.NODE_ENV" { + if len(defineExpr.Parts) == 1 && mapKey == nodeEnvMapKey { data := logger.MsgData{ Text: fmt.Sprintf("%q is defined as an identifier instead of a string (surround %q with quotes to get a string)", key, value), } @@ -606,15 +622,13 @@ func validateDefines( // Inject complex expressions if injectExpr != nil { - definesToInject = append(definesToInject, key) - if valueToInject == nil { - valueToInject = make(map[string]config.InjectedDefine) - } - valueToInject[key] = config.InjectedDefine{ + index := ast.MakeIndex32(uint32(len(injectedDefines))) + injectedDefines = append(injectedDefines, config.InjectedDefine{ Source: logger.Source{Contents: value}, Data: injectExpr, Name: key, - } + }) + rawDefines[mapKey] = config.DefineData{KeyParts: keyParts, DefineExpr: &config.DefineExpr{InjectedDefineIndex: index}} continue } @@ -622,18 +636,6 @@ func validateDefines( log.AddError(nil, logger.Range{}, fmt.Sprintf("Invalid define value (must be an entity name or valid JSON syntax): %s", value)) } - // Sort injected defines for determinism, since the imports will be injected - // into every file in the order that we return them from this function - var injectedDefines []config.InjectedDefine - if len(definesToInject) > 0 { - injectedDefines = make([]config.InjectedDefine, len(definesToInject)) - sort.Strings(definesToInject) - for i, key := range definesToInject { - injectedDefines[i] = valueToInject[key] - rawDefines[key] = config.DefineData{DefineExpr: &config.DefineExpr{InjectedDefineIndex: ast.MakeIndex32(uint32(i))}} - } - } - // If we're bundling for the browser, add a special-cased define for // "process.env.NODE_ENV" that is "development" when not minifying and // "production" when minifying. This is a convention from the React world @@ -641,16 +643,16 @@ func validateDefines( // is only done if it's not already defined so that you can override it if // necessary. if isBuildAPI && platform == config.PlatformBrowser { - if _, process := rawDefines["process"]; !process { - if _, processEnv := rawDefines["process.env"]; !processEnv { - if _, processEnvNodeEnv := rawDefines["process.env.NODE_ENV"]; !processEnvNodeEnv { + if _, process := rawDefines[mapKeyForDefine([]string{"process"})]; !process { + if _, processEnv := rawDefines[mapKeyForDefine([]string{"process.env"})]; !processEnv { + if _, processEnvNodeEnv := rawDefines[nodeEnvMapKey]; !processEnvNodeEnv { var value []uint16 if minify { value = helpers.StringToUTF16("production") } else { value = helpers.StringToUTF16("development") } - rawDefines["process.env.NODE_ENV"] = config.DefineData{DefineExpr: &config.DefineExpr{Constant: &js_ast.EString{Value: value}}} + rawDefines[nodeEnvMapKey] = config.DefineData{KeyParts: nodeEnvParts, DefineExpr: &config.DefineExpr{Constant: &js_ast.EString{Value: value}}} } } } @@ -658,29 +660,35 @@ func validateDefines( // If we're dropping all console API calls, replace each one with undefined if (drop & DropConsole) != 0 { - define := rawDefines["console"] + consoleParts := []string{"console"} + consoleMapKey := mapKeyForDefine(consoleParts) + define := rawDefines[consoleMapKey] + define.KeyParts = consoleParts define.Flags |= config.MethodCallsMustBeReplacedWithUndefined - rawDefines["console"] = define + rawDefines[consoleMapKey] = define } for _, key := range pureFns { - // The key must be a dot-separated identifier list - for _, part := range strings.Split(key, ".") { - if !js_ast.IsIdentifier(part) { - log.AddError(nil, logger.Range{}, fmt.Sprintf("Invalid pure function: %q", key)) - continue - } + keyParts := validateGlobalName(log, key, "(pure name)") + if keyParts == nil { + continue } + mapKey := mapKeyForDefine(keyParts) // Merge with any previously-specified defines - define := rawDefines[key] + define := rawDefines[mapKey] + define.KeyParts = keyParts define.Flags |= config.CallCanBeUnwrappedIfUnused - rawDefines[key] = define + rawDefines[mapKey] = define } // Processing defines is expensive. Process them once here so the same object // can be shared between all parsers we create using these arguments. - processed := config.ProcessDefines(rawDefines) + definesArray := make([]config.DefineData, 0, len(rawDefines)) + for _, define := range rawDefines { + definesArray = append(definesArray, define) + } + processed := config.ProcessDefines(definesArray) return &processed, injectedDefines } @@ -1263,7 +1271,7 @@ func validateBuildOptions( ASCIIOnly: validateASCIIOnly(buildOpts.Charset), IgnoreDCEAnnotations: buildOpts.IgnoreAnnotations, TreeShaking: validateTreeShaking(buildOpts.TreeShaking, buildOpts.Bundle, buildOpts.Format), - GlobalName: validateGlobalName(log, buildOpts.GlobalName), + GlobalName: validateGlobalName(log, buildOpts.GlobalName, "(global name)"), CodeSplitting: buildOpts.Splitting, OutputFormat: validateFormat(buildOpts.Format), AbsOutputFile: validatePath(log, realFS, buildOpts.Outfile, "outfile path"), @@ -1707,7 +1715,7 @@ func transformImpl(input string, transformOpts TransformOptions) TransformResult SourceRoot: transformOpts.SourceRoot, ExcludeSourcesContent: transformOpts.SourcesContent == SourcesContentExclude, OutputFormat: validateFormat(transformOpts.Format), - GlobalName: validateGlobalName(log, transformOpts.GlobalName), + GlobalName: validateGlobalName(log, transformOpts.GlobalName, "(global name)"), MinifySyntax: transformOpts.MinifySyntax, MinifyWhitespace: transformOpts.MinifyWhitespace, MinifyIdentifiers: transformOpts.MinifyIdentifiers, diff --git a/source/vendor/github.com/tdewolff/parse/v2/binary.go b/source/vendor/github.com/tdewolff/parse/v2/binary.go index 0b2dd8d19b65a13fae04e678dbbc670096effd0d..53439200b01ae85aa5c2edac898ee9fe25083039 100644 --- a/source/vendor/github.com/tdewolff/parse/v2/binary.go +++ b/source/vendor/github.com/tdewolff/parse/v2/binary.go @@ -386,8 +386,8 @@ type binaryReaderBytes struct { data []byte } -func newBinaryReaderBytes(data []byte) (*binaryReaderBytes, error) { - return &binaryReaderBytes{data}, nil +func newBinaryReaderBytes(data []byte) *binaryReaderBytes { + return &binaryReaderBytes{data} } // Close closes the reader. @@ -414,10 +414,10 @@ type binaryReaderReader struct { seeker bool } -func newBinaryReaderReader(r io.Reader, n int64) (*binaryReaderReader, error) { +func newBinaryReaderReader(r io.Reader, n int64) *binaryReaderReader { _, readerAt := r.(io.ReaderAt) _, seeker := r.(io.Seeker) - return &binaryReaderReader{r, n, readerAt, seeker}, nil + return &binaryReaderReader{r, n, readerAt, seeker} } // Close closes the reader. @@ -482,24 +482,20 @@ func NewBinaryReader2Reader(r io.Reader, n int64) (*BinaryReader2, error) { var f IBinaryReader if isReaderAt || isSeeker { - var err error - f, err = newBinaryReaderReader(r, n) - if err != nil { - return nil, err - } + f = newBinaryReaderReader(r, n) } else { b := make([]byte, n) if _, err := io.ReadFull(r, b); err != nil { return nil, err } - f, _ = newBinaryReaderBytes(b) + f = newBinaryReaderBytes(b) } return NewBinaryReader2(f), nil } -func NewBinaryReader2Bytes(data []byte) (*BinaryReader2, error) { - f, _ := newBinaryReaderBytes(data) - return NewBinaryReader2(f), nil +func NewBinaryReader2Bytes(data []byte) *BinaryReader2 { + f := newBinaryReaderBytes(data) + return NewBinaryReader2(f) } func NewBinaryReader2File(filename string) (*BinaryReader2, error) { @@ -641,12 +637,16 @@ func (r *BinaryReader2) ReadInt64() int64 { // BinaryWriter is a big endian binary file format writer. type BinaryWriter struct { - buf []byte + buf []byte + Endian binary.ByteOrder } // NewBinaryWriter returns a big endian binary file format writer. func NewBinaryWriter(buf []byte) *BinaryWriter { - return &BinaryWriter{buf} + return &BinaryWriter{ + buf: buf, + Endian: binary.BigEndian, + } } // Len returns the buffer's length in bytes. @@ -689,21 +689,21 @@ func (w *BinaryWriter) WriteUint8(v uint8) { func (w *BinaryWriter) WriteUint16(v uint16) { pos := len(w.buf) w.buf = append(w.buf, make([]byte, 2)...) - binary.BigEndian.PutUint16(w.buf[pos:], v) + w.Endian.PutUint16(w.buf[pos:], v) } // WriteUint32 writes the given uint32 to the buffer. func (w *BinaryWriter) WriteUint32(v uint32) { pos := len(w.buf) w.buf = append(w.buf, make([]byte, 4)...) - binary.BigEndian.PutUint32(w.buf[pos:], v) + w.Endian.PutUint32(w.buf[pos:], v) } // WriteUint64 writes the given uint64 to the buffer. func (w *BinaryWriter) WriteUint64(v uint64) { pos := len(w.buf) w.buf = append(w.buf, make([]byte, 8)...) - binary.BigEndian.PutUint64(w.buf[pos:], v) + w.Endian.PutUint64(w.buf[pos:], v) } // WriteInt8 writes the given int8 to the buffer. diff --git a/source/vendor/github.com/tdewolff/parse/v2/common.go b/source/vendor/github.com/tdewolff/parse/v2/common.go index 1883d1bd4d04fa444f725928f658d2a5134586f8..05f88173928b59fcb07964be45a9926763f4f0e2 100644 --- a/source/vendor/github.com/tdewolff/parse/v2/common.go +++ b/source/vendor/github.com/tdewolff/parse/v2/common.go @@ -534,7 +534,7 @@ func DecodeURL(b []byte) []byte { c = c<<4 + int(b[j]-'a') + 10 } } - if j == i+3 && c < 128 { + if j == i+3 { b[i] = byte(c) b = append(b[:i+1], b[i+3:]...) } diff --git a/source/vendor/golang.org/x/exp/constraints/constraints.go b/source/vendor/golang.org/x/exp/constraints/constraints.go deleted file mode 100644 index 2c033dff47e904fc5cd8643c2e6b5c3d1f42c5fe..0000000000000000000000000000000000000000 --- a/source/vendor/golang.org/x/exp/constraints/constraints.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2021 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. - -// Package constraints defines a set of useful constraints to be used -// with type parameters. -package constraints - -// Signed is a constraint that permits any signed integer type. -// If future releases of Go add new predeclared signed integer types, -// this constraint will be modified to include them. -type Signed interface { - ~int | ~int8 | ~int16 | ~int32 | ~int64 -} - -// Unsigned is a constraint that permits any unsigned integer type. -// If future releases of Go add new predeclared unsigned integer types, -// this constraint will be modified to include them. -type Unsigned interface { - ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr -} - -// Integer is a constraint that permits any integer type. -// If future releases of Go add new predeclared integer types, -// this constraint will be modified to include them. -type Integer interface { - Signed | Unsigned -} - -// Float is a constraint that permits any floating-point type. -// If future releases of Go add new predeclared floating-point types, -// this constraint will be modified to include them. -type Float interface { - ~float32 | ~float64 -} - -// Complex is a constraint that permits any complex numeric type. -// If future releases of Go add new predeclared complex numeric types, -// this constraint will be modified to include them. -type Complex interface { - ~complex64 | ~complex128 -} - -// Ordered is a constraint that permits any ordered type: any type -// that supports the operators < <= >= >. -// If future releases of Go add new ordered types, -// this constraint will be modified to include them. -type Ordered interface { - Integer | Float | ~string -} diff --git a/source/vendor/golang.org/x/exp/slices/cmp.go b/source/vendor/golang.org/x/exp/slices/cmp.go deleted file mode 100644 index fbf1934a06174d4da0ad9dee9db031a47324e16c..0000000000000000000000000000000000000000 --- a/source/vendor/golang.org/x/exp/slices/cmp.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2023 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. - -package slices - -import "golang.org/x/exp/constraints" - -// min is a version of the predeclared function from the Go 1.21 release. -func min[T constraints.Ordered](a, b T) T { - if a < b || isNaN(a) { - return a - } - return b -} - -// max is a version of the predeclared function from the Go 1.21 release. -func max[T constraints.Ordered](a, b T) T { - if a > b || isNaN(a) { - return a - } - return b -} - -// cmpLess is a copy of cmp.Less from the Go 1.21 release. -func cmpLess[T constraints.Ordered](x, y T) bool { - return (isNaN(x) && !isNaN(y)) || x < y -} - -// cmpCompare is a copy of cmp.Compare from the Go 1.21 release. -func cmpCompare[T constraints.Ordered](x, y T) int { - xNaN := isNaN(x) - yNaN := isNaN(y) - if xNaN && yNaN { - return 0 - } - if xNaN || x < y { - return -1 - } - if yNaN || x > y { - return +1 - } - return 0 -} diff --git a/source/vendor/golang.org/x/exp/slices/slices.go b/source/vendor/golang.org/x/exp/slices/slices.go index 46ceac343995f13320ec893f6adc7f75cf894ff4..757383ea1c0141fb9594ed7fb3c82b0672828239 100644 --- a/source/vendor/golang.org/x/exp/slices/slices.go +++ b/source/vendor/golang.org/x/exp/slices/slices.go @@ -6,26 +6,22 @@ package slices import ( - "unsafe" - - "golang.org/x/exp/constraints" + "cmp" + "slices" ) +// TODO(adonovan): when https://go.dev/issue/32816 is accepted, all of +// these functions should be annotated (provisionally with "//go:fix +// inline") so that tools can safely and automatically replace calls +// to exp/slices with calls to std slices by inlining them. + // Equal reports whether two slices are equal: the same length and all // elements equal. If the lengths are different, Equal returns false. // Otherwise, the elements are compared in increasing index order, and the // comparison stops at the first unequal pair. // Floating point NaNs are not considered equal. func Equal[S ~[]E, E comparable](s1, s2 S) bool { - if len(s1) != len(s2) { - return false - } - for i := range s1 { - if s1[i] != s2[i] { - return false - } - } - return true + return slices.Equal(s1, s2) } // EqualFunc reports whether two slices are equal using an equality @@ -34,16 +30,7 @@ func Equal[S ~[]E, E comparable](s1, s2 S) bool { // increasing index order, and the comparison stops at the first index // for which eq returns false. func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) bool) bool { - if len(s1) != len(s2) { - return false - } - for i, v1 := range s1 { - v2 := s2[i] - if !eq(v1, v2) { - return false - } - } - return true + return slices.EqualFunc(s1, s2, eq) } // Compare compares the elements of s1 and s2, using [cmp.Compare] on each pair @@ -53,20 +40,8 @@ func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) boo // If both slices are equal until one of them ends, the shorter slice is // considered less than the longer one. // The result is 0 if s1 == s2, -1 if s1 < s2, and +1 if s1 > s2. -func Compare[S ~[]E, E constraints.Ordered](s1, s2 S) int { - for i, v1 := range s1 { - if i >= len(s2) { - return +1 - } - v2 := s2[i] - if c := cmpCompare(v1, v2); c != 0 { - return c - } - } - if len(s1) < len(s2) { - return -1 - } - return 0 +func Compare[S ~[]E, E cmp.Ordered](s1, s2 S) int { + return slices.Compare(s1, s2) } // CompareFunc is like [Compare] but uses a custom comparison function on each @@ -75,52 +50,30 @@ func Compare[S ~[]E, E constraints.Ordered](s1, s2 S) int { // returns 0 the result is 0 if len(s1) == len(s2), -1 if len(s1) < len(s2), // and +1 if len(s1) > len(s2). func CompareFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, cmp func(E1, E2) int) int { - for i, v1 := range s1 { - if i >= len(s2) { - return +1 - } - v2 := s2[i] - if c := cmp(v1, v2); c != 0 { - return c - } - } - if len(s1) < len(s2) { - return -1 - } - return 0 + return slices.CompareFunc(s1, s2, cmp) } // Index returns the index of the first occurrence of v in s, // or -1 if not present. func Index[S ~[]E, E comparable](s S, v E) int { - for i := range s { - if v == s[i] { - return i - } - } - return -1 + return slices.Index(s, v) } // IndexFunc returns the first index i satisfying f(s[i]), // or -1 if none do. func IndexFunc[S ~[]E, E any](s S, f func(E) bool) int { - for i := range s { - if f(s[i]) { - return i - } - } - return -1 + return slices.IndexFunc(s, f) } // Contains reports whether v is present in s. func Contains[S ~[]E, E comparable](s S, v E) bool { - return Index(s, v) >= 0 + return slices.Contains(s, v) } // ContainsFunc reports whether at least one // element e of s satisfies f(e). func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool { - return IndexFunc(s, f) >= 0 + return slices.ContainsFunc(s, f) } // Insert inserts the values v... into s at index i, @@ -131,92 +84,7 @@ func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool { // Insert panics if i is out of range. // This function is O(len(s) + len(v)). func Insert[S ~[]E, E any](s S, i int, v ...E) S { - m := len(v) - if m == 0 { - return s - } - n := len(s) - if i == n { - return append(s, v...) - } - if n+m > cap(s) { - // Use append rather than make so that we bump the size of - // the slice up to the next storage class. - // This is what Grow does but we don't call Grow because - // that might copy the values twice. - s2 := append(s[:i], make(S, n+m-i)...) - copy(s2[i:], v) - copy(s2[i+m:], s[i:]) - return s2 - } - s = s[:n+m] - - // before: - // s: aaaaaaaabbbbccccccccdddd - // ^ ^ ^ ^ - // i i+m n n+m - // after: - // s: aaaaaaaavvvvbbbbcccccccc - // ^ ^ ^ ^ - // i i+m n n+m - // - // a are the values that don't move in s. - // v are the values copied in from v. - // b and c are the values from s that are shifted up in index. - // d are the values that get overwritten, never to be seen again. - - if !overlaps(v, s[i+m:]) { - // Easy case - v does not overlap either the c or d regions. - // (It might be in some of a or b, or elsewhere entirely.) - // The data we copy up doesn't write to v at all, so just do it. - - copy(s[i+m:], s[i:]) - - // Now we have - // s: aaaaaaaabbbbbbbbcccccccc - // ^ ^ ^ ^ - // i i+m n n+m - // Note the b values are duplicated. - - copy(s[i:], v) - - // Now we have - // s: aaaaaaaavvvvbbbbcccccccc - // ^ ^ ^ ^ - // i i+m n n+m - // That's the result we want. - return s - } - - // The hard case - v overlaps c or d. We can't just shift up - // the data because we'd move or clobber the values we're trying - // to insert. - // So instead, write v on top of d, then rotate. - copy(s[n:], v) - - // Now we have - // s: aaaaaaaabbbbccccccccvvvv - // ^ ^ ^ ^ - // i i+m n n+m - - rotateRight(s[i:], m) - - // Now we have - // s: aaaaaaaavvvvbbbbcccccccc - // ^ ^ ^ ^ - // i i+m n n+m - // That's the result we want. - return s -} - -// clearSlice sets all elements up to the length of s to the zero value of E. -// We may use the builtin clear func instead, and remove clearSlice, when upgrading -// to Go 1.21+. -func clearSlice[S ~[]E, E any](s S) { - var zero E - for i := range s { - s[i] = zero - } + return slices.Insert(s, i, v...) } // Delete removes the elements s[i:j] from s, returning the modified slice. @@ -225,135 +93,27 @@ func clearSlice[S ~[]E, E any](s S) { // make a single call deleting them all together than to delete one at a time. // Delete zeroes the elements s[len(s)-(j-i):len(s)]. func Delete[S ~[]E, E any](s S, i, j int) S { - _ = s[i:j:len(s)] // bounds check - - if i == j { - return s - } - - oldlen := len(s) - s = append(s[:i], s[j:]...) - clearSlice(s[len(s):oldlen]) // zero/nil out the obsolete elements, for GC - return s + return slices.Delete(s, i, j) } // DeleteFunc removes any elements from s for which del returns true, // returning the modified slice. // DeleteFunc zeroes the elements between the new length and the original length. func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S { - i := IndexFunc(s, del) - if i == -1 { - return s - } - // Don't start copying elements until we find one to delete. - for j := i + 1; j < len(s); j++ { - if v := s[j]; !del(v) { - s[i] = v - i++ - } - } - clearSlice(s[i:]) // zero/nil out the obsolete elements, for GC - return s[:i] + return slices.DeleteFunc(s, del) } // Replace replaces the elements s[i:j] by the given v, and returns the // modified slice. Replace panics if s[i:j] is not a valid slice of s. // When len(v) < (j-i), Replace zeroes the elements between the new length and the original length. func Replace[S ~[]E, E any](s S, i, j int, v ...E) S { - _ = s[i:j] // verify that i:j is a valid subslice - - if i == j { - return Insert(s, i, v...) - } - if j == len(s) { - return append(s[:i], v...) - } - - tot := len(s[:i]) + len(v) + len(s[j:]) - if tot > cap(s) { - // Too big to fit, allocate and copy over. - s2 := append(s[:i], make(S, tot-i)...) // See Insert - copy(s2[i:], v) - copy(s2[i+len(v):], s[j:]) - return s2 - } - - r := s[:tot] - - if i+len(v) <= j { - // Easy, as v fits in the deleted portion. - copy(r[i:], v) - if i+len(v) != j { - copy(r[i+len(v):], s[j:]) - } - clearSlice(s[tot:]) // zero/nil out the obsolete elements, for GC - return r - } - - // We are expanding (v is bigger than j-i). - // The situation is something like this: - // (example has i=4,j=8,len(s)=16,len(v)=6) - // s: aaaaxxxxbbbbbbbbyy - // ^ ^ ^ ^ - // i j len(s) tot - // a: prefix of s - // x: deleted range - // b: more of s - // y: area to expand into - - if !overlaps(r[i+len(v):], v) { - // Easy, as v is not clobbered by the first copy. - copy(r[i+len(v):], s[j:]) - copy(r[i:], v) - return r - } - - // This is a situation where we don't have a single place to which - // we can copy v. Parts of it need to go to two different places. - // We want to copy the prefix of v into y and the suffix into x, then - // rotate |y| spots to the right. - // - // v[2:] v[:2] - // | | - // s: aaaavvvvbbbbbbbbvv - // ^ ^ ^ ^ - // i j len(s) tot - // - // If either of those two destinations don't alias v, then we're good. - y := len(v) - (j - i) // length of y portion - - if !overlaps(r[i:j], v) { - copy(r[i:j], v[y:]) - copy(r[len(s):], v[:y]) - rotateRight(r[i:], y) - return r - } - if !overlaps(r[len(s):], v) { - copy(r[len(s):], v[:y]) - copy(r[i:j], v[y:]) - rotateRight(r[i:], y) - return r - } - - // Now we know that v overlaps both x and y. - // That means that the entirety of b is *inside* v. - // So we don't need to preserve b at all; instead we - // can copy v first, then copy the b part of v out of - // v to the right destination. - k := startIdx(v, s[j:]) - copy(r[i:], v) - copy(r[i+len(v):], r[i+k:]) - return r + return slices.Replace(s, i, j, v...) } // Clone returns a copy of the slice. // The elements are copied using assignment, so this is a shallow clone. func Clone[S ~[]E, E any](s S) S { - // Preserve nil in case it matters. - if s == nil { - return nil - } - return append(S([]E{}), s...) + return slices.Clone(s) } // Compact replaces consecutive runs of equal elements with a single copy. @@ -362,40 +122,14 @@ func Clone[S ~[]E, E any](s S) S { // which may have a smaller length. // Compact zeroes the elements between the new length and the original length. func Compact[S ~[]E, E comparable](s S) S { - if len(s) < 2 { - return s - } - i := 1 - for k := 1; k < len(s); k++ { - if s[k] != s[k-1] { - if i != k { - s[i] = s[k] - } - i++ - } - } - clearSlice(s[i:]) // zero/nil out the obsolete elements, for GC - return s[:i] + return slices.Compact(s) } // CompactFunc is like [Compact] but uses an equality function to compare elements. // For runs of elements that compare equal, CompactFunc keeps the first one. // CompactFunc zeroes the elements between the new length and the original length. func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S { - if len(s) < 2 { - return s - } - i := 1 - for k := 1; k < len(s); k++ { - if !eq(s[k], s[k-1]) { - if i != k { - s[i] = s[k] - } - i++ - } - } - clearSlice(s[i:]) // zero/nil out the obsolete elements, for GC - return s[:i] + return slices.CompactFunc(s, eq) } // Grow increases the slice's capacity, if necessary, to guarantee space for @@ -403,113 +137,15 @@ func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S { // to the slice without another allocation. If n is negative or too large to // allocate the memory, Grow panics. func Grow[S ~[]E, E any](s S, n int) S { - if n < 0 { - panic("cannot be negative") - } - if n -= cap(s) - len(s); n > 0 { - // TODO(https://go.dev/issue/53888): Make using []E instead of S - // to workaround a compiler bug where the runtime.growslice optimization - // does not take effect. Revert when the compiler is fixed. - s = append([]E(s)[:cap(s)], make([]E, n)...)[:len(s)] - } - return s + return slices.Grow(s, n) } // Clip removes unused capacity from the slice, returning s[:len(s):len(s)]. func Clip[S ~[]E, E any](s S) S { - return s[:len(s):len(s)] -} - -// Rotation algorithm explanation: -// -// rotate left by 2 -// start with -// 0123456789 -// split up like this -// 01 234567 89 -// swap first 2 and last 2 -// 89 234567 01 -// join first parts -// 89234567 01 -// recursively rotate first left part by 2 -// 23456789 01 -// join at the end -// 2345678901 -// -// rotate left by 8 -// start with -// 0123456789 -// split up like this -// 01 234567 89 -// swap first 2 and last 2 -// 89 234567 01 -// join last parts -// 89 23456701 -// recursively rotate second part left by 6 -// 89 01234567 -// join at the end -// 8901234567 - -// TODO: There are other rotate algorithms. -// This algorithm has the desirable property that it moves each element exactly twice. -// The triple-reverse algorithm is simpler and more cache friendly, but takes more writes. -// The follow-cycles algorithm can be 1-write but it is not very cache friendly. - -// rotateLeft rotates b left by n spaces. -// s_final[i] = s_orig[i+r], wrapping around. -func rotateLeft[E any](s []E, r int) { - for r != 0 && r != len(s) { - if r*2 <= len(s) { - swap(s[:r], s[len(s)-r:]) - s = s[:len(s)-r] - } else { - swap(s[:len(s)-r], s[r:]) - s, r = s[len(s)-r:], r*2-len(s) - } - } -} -func rotateRight[E any](s []E, r int) { - rotateLeft(s, len(s)-r) -} - -// swap swaps the contents of x and y. x and y must be equal length and disjoint. -func swap[E any](x, y []E) { - for i := 0; i < len(x); i++ { - x[i], y[i] = y[i], x[i] - } -} - -// overlaps reports whether the memory ranges a[0:len(a)] and b[0:len(b)] overlap. -func overlaps[E any](a, b []E) bool { - if len(a) == 0 || len(b) == 0 { - return false - } - elemSize := unsafe.Sizeof(a[0]) - if elemSize == 0 { - return false - } - // TODO: use a runtime/unsafe facility once one becomes available. See issue 12445. - // Also see crypto/internal/alias/alias.go:AnyOverlap - return uintptr(unsafe.Pointer(&a[0])) <= uintptr(unsafe.Pointer(&b[len(b)-1]))+(elemSize-1) && - uintptr(unsafe.Pointer(&b[0])) <= uintptr(unsafe.Pointer(&a[len(a)-1]))+(elemSize-1) -} - -// startIdx returns the index in haystack where the needle starts. -// prerequisite: the needle must be aliased entirely inside the haystack. -func startIdx[E any](haystack, needle []E) int { - p := &needle[0] - for i := range haystack { - if p == &haystack[i] { - return i - } - } - // TODO: what if the overlap is by a non-integral number of Es? - panic("needle not found") + return slices.Clip(s) } // Reverse reverses the elements of the slice in place. func Reverse[S ~[]E, E any](s S) { - for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { - s[i], s[j] = s[j], s[i] - } + slices.Reverse(s) } diff --git a/source/vendor/golang.org/x/exp/slices/sort.go b/source/vendor/golang.org/x/exp/slices/sort.go index f58bbc7ba4de5f05c35ac1e47f77f0d97941895b..e270a74652fa1e6d4be754bb4d184ed5f809ce71 100644 --- a/source/vendor/golang.org/x/exp/slices/sort.go +++ b/source/vendor/golang.org/x/exp/slices/sort.go @@ -2,21 +2,20 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:generate go run $GOROOT/src/sort/gen_sort_variants.go -exp - package slices import ( - "math/bits" - - "golang.org/x/exp/constraints" + "cmp" + "slices" ) +// TODO(adonovan): add a "//go:fix inline" annotation to each function +// in this file; see https://go.dev/issue/32816. + // Sort sorts a slice of any ordered type in ascending order. // When sorting floating-point numbers, NaNs are ordered before other values. -func Sort[S ~[]E, E constraints.Ordered](x S) { - n := len(x) - pdqsortOrdered(x, 0, n, bits.Len(uint(n))) +func Sort[S ~[]E, E cmp.Ordered](x S) { + slices.Sort(x) } // SortFunc sorts the slice x in ascending order as determined by the cmp @@ -29,118 +28,60 @@ func Sort[S ~[]E, E constraints.Ordered](x S) { // See https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings. // To indicate 'uncomparable', return 0 from the function. func SortFunc[S ~[]E, E any](x S, cmp func(a, b E) int) { - n := len(x) - pdqsortCmpFunc(x, 0, n, bits.Len(uint(n)), cmp) + slices.SortFunc(x, cmp) } // SortStableFunc sorts the slice x while keeping the original order of equal // elements, using cmp to compare elements in the same way as [SortFunc]. func SortStableFunc[S ~[]E, E any](x S, cmp func(a, b E) int) { - stableCmpFunc(x, len(x), cmp) + slices.SortStableFunc(x, cmp) } // IsSorted reports whether x is sorted in ascending order. -func IsSorted[S ~[]E, E constraints.Ordered](x S) bool { - for i := len(x) - 1; i > 0; i-- { - if cmpLess(x[i], x[i-1]) { - return false - } - } - return true +func IsSorted[S ~[]E, E cmp.Ordered](x S) bool { + return slices.IsSorted(x) } // IsSortedFunc reports whether x is sorted in ascending order, with cmp as the // comparison function as defined by [SortFunc]. func IsSortedFunc[S ~[]E, E any](x S, cmp func(a, b E) int) bool { - for i := len(x) - 1; i > 0; i-- { - if cmp(x[i], x[i-1]) < 0 { - return false - } - } - return true + return slices.IsSortedFunc(x, cmp) } // Min returns the minimal value in x. It panics if x is empty. // For floating-point numbers, Min propagates NaNs (any NaN value in x // forces the output to be NaN). -func Min[S ~[]E, E constraints.Ordered](x S) E { - if len(x) < 1 { - panic("slices.Min: empty list") - } - m := x[0] - for i := 1; i < len(x); i++ { - m = min(m, x[i]) - } - return m +func Min[S ~[]E, E cmp.Ordered](x S) E { + return slices.Min(x) } // MinFunc returns the minimal value in x, using cmp to compare elements. // It panics if x is empty. If there is more than one minimal element // according to the cmp function, MinFunc returns the first one. func MinFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E { - if len(x) < 1 { - panic("slices.MinFunc: empty list") - } - m := x[0] - for i := 1; i < len(x); i++ { - if cmp(x[i], m) < 0 { - m = x[i] - } - } - return m + return slices.MinFunc(x, cmp) } // Max returns the maximal value in x. It panics if x is empty. // For floating-point E, Max propagates NaNs (any NaN value in x // forces the output to be NaN). -func Max[S ~[]E, E constraints.Ordered](x S) E { - if len(x) < 1 { - panic("slices.Max: empty list") - } - m := x[0] - for i := 1; i < len(x); i++ { - m = max(m, x[i]) - } - return m +func Max[S ~[]E, E cmp.Ordered](x S) E { + return slices.Max(x) } // MaxFunc returns the maximal value in x, using cmp to compare elements. // It panics if x is empty. If there is more than one maximal element // according to the cmp function, MaxFunc returns the first one. func MaxFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E { - if len(x) < 1 { - panic("slices.MaxFunc: empty list") - } - m := x[0] - for i := 1; i < len(x); i++ { - if cmp(x[i], m) > 0 { - m = x[i] - } - } - return m + return slices.MaxFunc(x, cmp) } // BinarySearch searches for target in a sorted slice and returns the position // where target is found, or the position where target would appear in the // sort order; it also returns a bool saying whether the target is really found // in the slice. The slice must be sorted in increasing order. -func BinarySearch[S ~[]E, E constraints.Ordered](x S, target E) (int, bool) { - // Inlining is faster than calling BinarySearchFunc with a lambda. - n := len(x) - // Define x[-1] < target and x[n] >= target. - // Invariant: x[i-1] < target, x[j] >= target. - i, j := 0, n - for i < j { - h := int(uint(i+j) >> 1) // avoid overflow when computing h - // i ≤ h < j - if cmpLess(x[h], target) { - i = h + 1 // preserves x[i-1] < target - } else { - j = h // preserves x[j] >= target - } - } - // i == j, x[i-1] < target, and x[j] (= x[i]) >= target => answer is i. - return i, i < n && (x[i] == target || (isNaN(x[i]) && isNaN(target))) +func BinarySearch[S ~[]E, E cmp.Ordered](x S, target E) (int, bool) { + return slices.BinarySearch(x, target) } // BinarySearchFunc works like [BinarySearch], but uses a custom comparison @@ -151,47 +92,5 @@ func BinarySearch[S ~[]E, E constraints.Ordered](x S, target E) (int, bool) { // cmp must implement the same ordering as the slice, such that if // cmp(a, t) < 0 and cmp(b, t) >= 0, then a must precede b in the slice. func BinarySearchFunc[S ~[]E, E, T any](x S, target T, cmp func(E, T) int) (int, bool) { - n := len(x) - // Define cmp(x[-1], target) < 0 and cmp(x[n], target) >= 0 . - // Invariant: cmp(x[i - 1], target) < 0, cmp(x[j], target) >= 0. - i, j := 0, n - for i < j { - h := int(uint(i+j) >> 1) // avoid overflow when computing h - // i ≤ h < j - if cmp(x[h], target) < 0 { - i = h + 1 // preserves cmp(x[i - 1], target) < 0 - } else { - j = h // preserves cmp(x[j], target) >= 0 - } - } - // i == j, cmp(x[i-1], target) < 0, and cmp(x[j], target) (= cmp(x[i], target)) >= 0 => answer is i. - return i, i < n && cmp(x[i], target) == 0 -} - -type sortedHint int // hint for pdqsort when choosing the pivot - -const ( - unknownHint sortedHint = iota - increasingHint - decreasingHint -) - -// xorshift paper: https://www.jstatsoft.org/article/view/v008i14/xorshift.pdf -type xorshift uint64 - -func (r *xorshift) Next() uint64 { - *r ^= *r << 13 - *r ^= *r >> 17 - *r ^= *r << 5 - return uint64(*r) -} - -func nextPowerOfTwo(length int) uint { - return 1 << bits.Len(uint(length)) -} - -// isNaN reports whether x is a NaN without requiring the math package. -// This will always return false if T is not floating-point. -func isNaN[T constraints.Ordered](x T) bool { - return x != x + return slices.BinarySearchFunc(x, target, cmp) } diff --git a/source/vendor/golang.org/x/exp/slices/zsortanyfunc.go b/source/vendor/golang.org/x/exp/slices/zsortanyfunc.go deleted file mode 100644 index 06f2c7a2481b0ac3f506546c3c2591f8f05a59ef..0000000000000000000000000000000000000000 --- a/source/vendor/golang.org/x/exp/slices/zsortanyfunc.go +++ /dev/null @@ -1,479 +0,0 @@ -// Code generated by gen_sort_variants.go; DO NOT EDIT. - -// Copyright 2022 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. - -package slices - -// insertionSortCmpFunc sorts data[a:b] using insertion sort. -func insertionSortCmpFunc[E any](data []E, a, b int, cmp func(a, b E) int) { - for i := a + 1; i < b; i++ { - for j := i; j > a && (cmp(data[j], data[j-1]) < 0); j-- { - data[j], data[j-1] = data[j-1], data[j] - } - } -} - -// siftDownCmpFunc implements the heap property on data[lo:hi]. -// first is an offset into the array where the root of the heap lies. -func siftDownCmpFunc[E any](data []E, lo, hi, first int, cmp func(a, b E) int) { - root := lo - for { - child := 2*root + 1 - if child >= hi { - break - } - if child+1 < hi && (cmp(data[first+child], data[first+child+1]) < 0) { - child++ - } - if !(cmp(data[first+root], data[first+child]) < 0) { - return - } - data[first+root], data[first+child] = data[first+child], data[first+root] - root = child - } -} - -func heapSortCmpFunc[E any](data []E, a, b int, cmp func(a, b E) int) { - first := a - lo := 0 - hi := b - a - - // Build heap with greatest element at top. - for i := (hi - 1) / 2; i >= 0; i-- { - siftDownCmpFunc(data, i, hi, first, cmp) - } - - // Pop elements, largest first, into end of data. - for i := hi - 1; i >= 0; i-- { - data[first], data[first+i] = data[first+i], data[first] - siftDownCmpFunc(data, lo, i, first, cmp) - } -} - -// pdqsortCmpFunc sorts data[a:b]. -// The algorithm based on pattern-defeating quicksort(pdqsort), but without the optimizations from BlockQuicksort. -// pdqsort paper: https://arxiv.org/pdf/2106.05123.pdf -// C++ implementation: https://github.com/orlp/pdqsort -// Rust implementation: https://docs.rs/pdqsort/latest/pdqsort/ -// limit is the number of allowed bad (very unbalanced) pivots before falling back to heapsort. -func pdqsortCmpFunc[E any](data []E, a, b, limit int, cmp func(a, b E) int) { - const maxInsertion = 12 - - var ( - wasBalanced = true // whether the last partitioning was reasonably balanced - wasPartitioned = true // whether the slice was already partitioned - ) - - for { - length := b - a - - if length <= maxInsertion { - insertionSortCmpFunc(data, a, b, cmp) - return - } - - // Fall back to heapsort if too many bad choices were made. - if limit == 0 { - heapSortCmpFunc(data, a, b, cmp) - return - } - - // If the last partitioning was imbalanced, we need to breaking patterns. - if !wasBalanced { - breakPatternsCmpFunc(data, a, b, cmp) - limit-- - } - - pivot, hint := choosePivotCmpFunc(data, a, b, cmp) - if hint == decreasingHint { - reverseRangeCmpFunc(data, a, b, cmp) - // The chosen pivot was pivot-a elements after the start of the array. - // After reversing it is pivot-a elements before the end of the array. - // The idea came from Rust's implementation. - pivot = (b - 1) - (pivot - a) - hint = increasingHint - } - - // The slice is likely already sorted. - if wasBalanced && wasPartitioned && hint == increasingHint { - if partialInsertionSortCmpFunc(data, a, b, cmp) { - return - } - } - - // Probably the slice contains many duplicate elements, partition the slice into - // elements equal to and elements greater than the pivot. - if a > 0 && !(cmp(data[a-1], data[pivot]) < 0) { - mid := partitionEqualCmpFunc(data, a, b, pivot, cmp) - a = mid - continue - } - - mid, alreadyPartitioned := partitionCmpFunc(data, a, b, pivot, cmp) - wasPartitioned = alreadyPartitioned - - leftLen, rightLen := mid-a, b-mid - balanceThreshold := length / 8 - if leftLen < rightLen { - wasBalanced = leftLen >= balanceThreshold - pdqsortCmpFunc(data, a, mid, limit, cmp) - a = mid + 1 - } else { - wasBalanced = rightLen >= balanceThreshold - pdqsortCmpFunc(data, mid+1, b, limit, cmp) - b = mid - } - } -} - -// partitionCmpFunc does one quicksort partition. -// Let p = data[pivot] -// Moves elements in data[a:b] around, so that data[i]<p and data[j]>=p for i<newpivot and j>newpivot. -// On return, data[newpivot] = p -func partitionCmpFunc[E any](data []E, a, b, pivot int, cmp func(a, b E) int) (newpivot int, alreadyPartitioned bool) { - data[a], data[pivot] = data[pivot], data[a] - i, j := a+1, b-1 // i and j are inclusive of the elements remaining to be partitioned - - for i <= j && (cmp(data[i], data[a]) < 0) { - i++ - } - for i <= j && !(cmp(data[j], data[a]) < 0) { - j-- - } - if i > j { - data[j], data[a] = data[a], data[j] - return j, true - } - data[i], data[j] = data[j], data[i] - i++ - j-- - - for { - for i <= j && (cmp(data[i], data[a]) < 0) { - i++ - } - for i <= j && !(cmp(data[j], data[a]) < 0) { - j-- - } - if i > j { - break - } - data[i], data[j] = data[j], data[i] - i++ - j-- - } - data[j], data[a] = data[a], data[j] - return j, false -} - -// partitionEqualCmpFunc partitions data[a:b] into elements equal to data[pivot] followed by elements greater than data[pivot]. -// It assumed that data[a:b] does not contain elements smaller than the data[pivot]. -func partitionEqualCmpFunc[E any](data []E, a, b, pivot int, cmp func(a, b E) int) (newpivot int) { - data[a], data[pivot] = data[pivot], data[a] - i, j := a+1, b-1 // i and j are inclusive of the elements remaining to be partitioned - - for { - for i <= j && !(cmp(data[a], data[i]) < 0) { - i++ - } - for i <= j && (cmp(data[a], data[j]) < 0) { - j-- - } - if i > j { - break - } - data[i], data[j] = data[j], data[i] - i++ - j-- - } - return i -} - -// partialInsertionSortCmpFunc partially sorts a slice, returns true if the slice is sorted at the end. -func partialInsertionSortCmpFunc[E any](data []E, a, b int, cmp func(a, b E) int) bool { - const ( - maxSteps = 5 // maximum number of adjacent out-of-order pairs that will get shifted - shortestShifting = 50 // don't shift any elements on short arrays - ) - i := a + 1 - for j := 0; j < maxSteps; j++ { - for i < b && !(cmp(data[i], data[i-1]) < 0) { - i++ - } - - if i == b { - return true - } - - if b-a < shortestShifting { - return false - } - - data[i], data[i-1] = data[i-1], data[i] - - // Shift the smaller one to the left. - if i-a >= 2 { - for j := i - 1; j >= 1; j-- { - if !(cmp(data[j], data[j-1]) < 0) { - break - } - data[j], data[j-1] = data[j-1], data[j] - } - } - // Shift the greater one to the right. - if b-i >= 2 { - for j := i + 1; j < b; j++ { - if !(cmp(data[j], data[j-1]) < 0) { - break - } - data[j], data[j-1] = data[j-1], data[j] - } - } - } - return false -} - -// breakPatternsCmpFunc scatters some elements around in an attempt to break some patterns -// that might cause imbalanced partitions in quicksort. -func breakPatternsCmpFunc[E any](data []E, a, b int, cmp func(a, b E) int) { - length := b - a - if length >= 8 { - random := xorshift(length) - modulus := nextPowerOfTwo(length) - - for idx := a + (length/4)*2 - 1; idx <= a+(length/4)*2+1; idx++ { - other := int(uint(random.Next()) & (modulus - 1)) - if other >= length { - other -= length - } - data[idx], data[a+other] = data[a+other], data[idx] - } - } -} - -// choosePivotCmpFunc chooses a pivot in data[a:b]. -// -// [0,8): chooses a static pivot. -// [8,shortestNinther): uses the simple median-of-three method. -// [shortestNinther,∞): uses the Tukey ninther method. -func choosePivotCmpFunc[E any](data []E, a, b int, cmp func(a, b E) int) (pivot int, hint sortedHint) { - const ( - shortestNinther = 50 - maxSwaps = 4 * 3 - ) - - l := b - a - - var ( - swaps int - i = a + l/4*1 - j = a + l/4*2 - k = a + l/4*3 - ) - - if l >= 8 { - if l >= shortestNinther { - // Tukey ninther method, the idea came from Rust's implementation. - i = medianAdjacentCmpFunc(data, i, &swaps, cmp) - j = medianAdjacentCmpFunc(data, j, &swaps, cmp) - k = medianAdjacentCmpFunc(data, k, &swaps, cmp) - } - // Find the median among i, j, k and stores it into j. - j = medianCmpFunc(data, i, j, k, &swaps, cmp) - } - - switch swaps { - case 0: - return j, increasingHint - case maxSwaps: - return j, decreasingHint - default: - return j, unknownHint - } -} - -// order2CmpFunc returns x,y where data[x] <= data[y], where x,y=a,b or x,y=b,a. -func order2CmpFunc[E any](data []E, a, b int, swaps *int, cmp func(a, b E) int) (int, int) { - if cmp(data[b], data[a]) < 0 { - *swaps++ - return b, a - } - return a, b -} - -// medianCmpFunc returns x where data[x] is the median of data[a],data[b],data[c], where x is a, b, or c. -func medianCmpFunc[E any](data []E, a, b, c int, swaps *int, cmp func(a, b E) int) int { - a, b = order2CmpFunc(data, a, b, swaps, cmp) - b, c = order2CmpFunc(data, b, c, swaps, cmp) - a, b = order2CmpFunc(data, a, b, swaps, cmp) - return b -} - -// medianAdjacentCmpFunc finds the median of data[a - 1], data[a], data[a + 1] and stores the index into a. -func medianAdjacentCmpFunc[E any](data []E, a int, swaps *int, cmp func(a, b E) int) int { - return medianCmpFunc(data, a-1, a, a+1, swaps, cmp) -} - -func reverseRangeCmpFunc[E any](data []E, a, b int, cmp func(a, b E) int) { - i := a - j := b - 1 - for i < j { - data[i], data[j] = data[j], data[i] - i++ - j-- - } -} - -func swapRangeCmpFunc[E any](data []E, a, b, n int, cmp func(a, b E) int) { - for i := 0; i < n; i++ { - data[a+i], data[b+i] = data[b+i], data[a+i] - } -} - -func stableCmpFunc[E any](data []E, n int, cmp func(a, b E) int) { - blockSize := 20 // must be > 0 - a, b := 0, blockSize - for b <= n { - insertionSortCmpFunc(data, a, b, cmp) - a = b - b += blockSize - } - insertionSortCmpFunc(data, a, n, cmp) - - for blockSize < n { - a, b = 0, 2*blockSize - for b <= n { - symMergeCmpFunc(data, a, a+blockSize, b, cmp) - a = b - b += 2 * blockSize - } - if m := a + blockSize; m < n { - symMergeCmpFunc(data, a, m, n, cmp) - } - blockSize *= 2 - } -} - -// symMergeCmpFunc merges the two sorted subsequences data[a:m] and data[m:b] using -// the SymMerge algorithm from Pok-Son Kim and Arne Kutzner, "Stable Minimum -// Storage Merging by Symmetric Comparisons", in Susanne Albers and Tomasz -// Radzik, editors, Algorithms - ESA 2004, volume 3221 of Lecture Notes in -// Computer Science, pages 714-723. Springer, 2004. -// -// Let M = m-a and N = b-n. Wolog M < N. -// The recursion depth is bound by ceil(log(N+M)). -// The algorithm needs O(M*log(N/M + 1)) calls to data.Less. -// The algorithm needs O((M+N)*log(M)) calls to data.Swap. -// -// The paper gives O((M+N)*log(M)) as the number of assignments assuming a -// rotation algorithm which uses O(M+N+gcd(M+N)) assignments. The argumentation -// in the paper carries through for Swap operations, especially as the block -// swapping rotate uses only O(M+N) Swaps. -// -// symMerge assumes non-degenerate arguments: a < m && m < b. -// Having the caller check this condition eliminates many leaf recursion calls, -// which improves performance. -func symMergeCmpFunc[E any](data []E, a, m, b int, cmp func(a, b E) int) { - // Avoid unnecessary recursions of symMerge - // by direct insertion of data[a] into data[m:b] - // if data[a:m] only contains one element. - if m-a == 1 { - // Use binary search to find the lowest index i - // such that data[i] >= data[a] for m <= i < b. - // Exit the search loop with i == b in case no such index exists. - i := m - j := b - for i < j { - h := int(uint(i+j) >> 1) - if cmp(data[h], data[a]) < 0 { - i = h + 1 - } else { - j = h - } - } - // Swap values until data[a] reaches the position before i. - for k := a; k < i-1; k++ { - data[k], data[k+1] = data[k+1], data[k] - } - return - } - - // Avoid unnecessary recursions of symMerge - // by direct insertion of data[m] into data[a:m] - // if data[m:b] only contains one element. - if b-m == 1 { - // Use binary search to find the lowest index i - // such that data[i] > data[m] for a <= i < m. - // Exit the search loop with i == m in case no such index exists. - i := a - j := m - for i < j { - h := int(uint(i+j) >> 1) - if !(cmp(data[m], data[h]) < 0) { - i = h + 1 - } else { - j = h - } - } - // Swap values until data[m] reaches the position i. - for k := m; k > i; k-- { - data[k], data[k-1] = data[k-1], data[k] - } - return - } - - mid := int(uint(a+b) >> 1) - n := mid + m - var start, r int - if m > mid { - start = n - b - r = mid - } else { - start = a - r = m - } - p := n - 1 - - for start < r { - c := int(uint(start+r) >> 1) - if !(cmp(data[p-c], data[c]) < 0) { - start = c + 1 - } else { - r = c - } - } - - end := n - start - if start < m && m < end { - rotateCmpFunc(data, start, m, end, cmp) - } - if a < start && start < mid { - symMergeCmpFunc(data, a, start, mid, cmp) - } - if mid < end && end < b { - symMergeCmpFunc(data, mid, end, b, cmp) - } -} - -// rotateCmpFunc rotates two consecutive blocks u = data[a:m] and v = data[m:b] in data: -// Data of the form 'x u v y' is changed to 'x v u y'. -// rotate performs at most b-a many calls to data.Swap, -// and it assumes non-degenerate arguments: a < m && m < b. -func rotateCmpFunc[E any](data []E, a, m, b int, cmp func(a, b E) int) { - i := m - a - j := b - m - - for i != j { - if i > j { - swapRangeCmpFunc(data, m-i, m, j, cmp) - i -= j - } else { - swapRangeCmpFunc(data, m-i, m+j-i, i, cmp) - j -= i - } - } - // i == j - swapRangeCmpFunc(data, m-i, m, i, cmp) -} diff --git a/source/vendor/golang.org/x/exp/slices/zsortordered.go b/source/vendor/golang.org/x/exp/slices/zsortordered.go deleted file mode 100644 index 99b47c3986a4e2a5c0dbbcc7b60a3b47c6b1dada..0000000000000000000000000000000000000000 --- a/source/vendor/golang.org/x/exp/slices/zsortordered.go +++ /dev/null @@ -1,481 +0,0 @@ -// Code generated by gen_sort_variants.go; DO NOT EDIT. - -// Copyright 2022 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. - -package slices - -import "golang.org/x/exp/constraints" - -// insertionSortOrdered sorts data[a:b] using insertion sort. -func insertionSortOrdered[E constraints.Ordered](data []E, a, b int) { - for i := a + 1; i < b; i++ { - for j := i; j > a && cmpLess(data[j], data[j-1]); j-- { - data[j], data[j-1] = data[j-1], data[j] - } - } -} - -// siftDownOrdered implements the heap property on data[lo:hi]. -// first is an offset into the array where the root of the heap lies. -func siftDownOrdered[E constraints.Ordered](data []E, lo, hi, first int) { - root := lo - for { - child := 2*root + 1 - if child >= hi { - break - } - if child+1 < hi && cmpLess(data[first+child], data[first+child+1]) { - child++ - } - if !cmpLess(data[first+root], data[first+child]) { - return - } - data[first+root], data[first+child] = data[first+child], data[first+root] - root = child - } -} - -func heapSortOrdered[E constraints.Ordered](data []E, a, b int) { - first := a - lo := 0 - hi := b - a - - // Build heap with greatest element at top. - for i := (hi - 1) / 2; i >= 0; i-- { - siftDownOrdered(data, i, hi, first) - } - - // Pop elements, largest first, into end of data. - for i := hi - 1; i >= 0; i-- { - data[first], data[first+i] = data[first+i], data[first] - siftDownOrdered(data, lo, i, first) - } -} - -// pdqsortOrdered sorts data[a:b]. -// The algorithm based on pattern-defeating quicksort(pdqsort), but without the optimizations from BlockQuicksort. -// pdqsort paper: https://arxiv.org/pdf/2106.05123.pdf -// C++ implementation: https://github.com/orlp/pdqsort -// Rust implementation: https://docs.rs/pdqsort/latest/pdqsort/ -// limit is the number of allowed bad (very unbalanced) pivots before falling back to heapsort. -func pdqsortOrdered[E constraints.Ordered](data []E, a, b, limit int) { - const maxInsertion = 12 - - var ( - wasBalanced = true // whether the last partitioning was reasonably balanced - wasPartitioned = true // whether the slice was already partitioned - ) - - for { - length := b - a - - if length <= maxInsertion { - insertionSortOrdered(data, a, b) - return - } - - // Fall back to heapsort if too many bad choices were made. - if limit == 0 { - heapSortOrdered(data, a, b) - return - } - - // If the last partitioning was imbalanced, we need to breaking patterns. - if !wasBalanced { - breakPatternsOrdered(data, a, b) - limit-- - } - - pivot, hint := choosePivotOrdered(data, a, b) - if hint == decreasingHint { - reverseRangeOrdered(data, a, b) - // The chosen pivot was pivot-a elements after the start of the array. - // After reversing it is pivot-a elements before the end of the array. - // The idea came from Rust's implementation. - pivot = (b - 1) - (pivot - a) - hint = increasingHint - } - - // The slice is likely already sorted. - if wasBalanced && wasPartitioned && hint == increasingHint { - if partialInsertionSortOrdered(data, a, b) { - return - } - } - - // Probably the slice contains many duplicate elements, partition the slice into - // elements equal to and elements greater than the pivot. - if a > 0 && !cmpLess(data[a-1], data[pivot]) { - mid := partitionEqualOrdered(data, a, b, pivot) - a = mid - continue - } - - mid, alreadyPartitioned := partitionOrdered(data, a, b, pivot) - wasPartitioned = alreadyPartitioned - - leftLen, rightLen := mid-a, b-mid - balanceThreshold := length / 8 - if leftLen < rightLen { - wasBalanced = leftLen >= balanceThreshold - pdqsortOrdered(data, a, mid, limit) - a = mid + 1 - } else { - wasBalanced = rightLen >= balanceThreshold - pdqsortOrdered(data, mid+1, b, limit) - b = mid - } - } -} - -// partitionOrdered does one quicksort partition. -// Let p = data[pivot] -// Moves elements in data[a:b] around, so that data[i]<p and data[j]>=p for i<newpivot and j>newpivot. -// On return, data[newpivot] = p -func partitionOrdered[E constraints.Ordered](data []E, a, b, pivot int) (newpivot int, alreadyPartitioned bool) { - data[a], data[pivot] = data[pivot], data[a] - i, j := a+1, b-1 // i and j are inclusive of the elements remaining to be partitioned - - for i <= j && cmpLess(data[i], data[a]) { - i++ - } - for i <= j && !cmpLess(data[j], data[a]) { - j-- - } - if i > j { - data[j], data[a] = data[a], data[j] - return j, true - } - data[i], data[j] = data[j], data[i] - i++ - j-- - - for { - for i <= j && cmpLess(data[i], data[a]) { - i++ - } - for i <= j && !cmpLess(data[j], data[a]) { - j-- - } - if i > j { - break - } - data[i], data[j] = data[j], data[i] - i++ - j-- - } - data[j], data[a] = data[a], data[j] - return j, false -} - -// partitionEqualOrdered partitions data[a:b] into elements equal to data[pivot] followed by elements greater than data[pivot]. -// It assumed that data[a:b] does not contain elements smaller than the data[pivot]. -func partitionEqualOrdered[E constraints.Ordered](data []E, a, b, pivot int) (newpivot int) { - data[a], data[pivot] = data[pivot], data[a] - i, j := a+1, b-1 // i and j are inclusive of the elements remaining to be partitioned - - for { - for i <= j && !cmpLess(data[a], data[i]) { - i++ - } - for i <= j && cmpLess(data[a], data[j]) { - j-- - } - if i > j { - break - } - data[i], data[j] = data[j], data[i] - i++ - j-- - } - return i -} - -// partialInsertionSortOrdered partially sorts a slice, returns true if the slice is sorted at the end. -func partialInsertionSortOrdered[E constraints.Ordered](data []E, a, b int) bool { - const ( - maxSteps = 5 // maximum number of adjacent out-of-order pairs that will get shifted - shortestShifting = 50 // don't shift any elements on short arrays - ) - i := a + 1 - for j := 0; j < maxSteps; j++ { - for i < b && !cmpLess(data[i], data[i-1]) { - i++ - } - - if i == b { - return true - } - - if b-a < shortestShifting { - return false - } - - data[i], data[i-1] = data[i-1], data[i] - - // Shift the smaller one to the left. - if i-a >= 2 { - for j := i - 1; j >= 1; j-- { - if !cmpLess(data[j], data[j-1]) { - break - } - data[j], data[j-1] = data[j-1], data[j] - } - } - // Shift the greater one to the right. - if b-i >= 2 { - for j := i + 1; j < b; j++ { - if !cmpLess(data[j], data[j-1]) { - break - } - data[j], data[j-1] = data[j-1], data[j] - } - } - } - return false -} - -// breakPatternsOrdered scatters some elements around in an attempt to break some patterns -// that might cause imbalanced partitions in quicksort. -func breakPatternsOrdered[E constraints.Ordered](data []E, a, b int) { - length := b - a - if length >= 8 { - random := xorshift(length) - modulus := nextPowerOfTwo(length) - - for idx := a + (length/4)*2 - 1; idx <= a+(length/4)*2+1; idx++ { - other := int(uint(random.Next()) & (modulus - 1)) - if other >= length { - other -= length - } - data[idx], data[a+other] = data[a+other], data[idx] - } - } -} - -// choosePivotOrdered chooses a pivot in data[a:b]. -// -// [0,8): chooses a static pivot. -// [8,shortestNinther): uses the simple median-of-three method. -// [shortestNinther,∞): uses the Tukey ninther method. -func choosePivotOrdered[E constraints.Ordered](data []E, a, b int) (pivot int, hint sortedHint) { - const ( - shortestNinther = 50 - maxSwaps = 4 * 3 - ) - - l := b - a - - var ( - swaps int - i = a + l/4*1 - j = a + l/4*2 - k = a + l/4*3 - ) - - if l >= 8 { - if l >= shortestNinther { - // Tukey ninther method, the idea came from Rust's implementation. - i = medianAdjacentOrdered(data, i, &swaps) - j = medianAdjacentOrdered(data, j, &swaps) - k = medianAdjacentOrdered(data, k, &swaps) - } - // Find the median among i, j, k and stores it into j. - j = medianOrdered(data, i, j, k, &swaps) - } - - switch swaps { - case 0: - return j, increasingHint - case maxSwaps: - return j, decreasingHint - default: - return j, unknownHint - } -} - -// order2Ordered returns x,y where data[x] <= data[y], where x,y=a,b or x,y=b,a. -func order2Ordered[E constraints.Ordered](data []E, a, b int, swaps *int) (int, int) { - if cmpLess(data[b], data[a]) { - *swaps++ - return b, a - } - return a, b -} - -// medianOrdered returns x where data[x] is the median of data[a],data[b],data[c], where x is a, b, or c. -func medianOrdered[E constraints.Ordered](data []E, a, b, c int, swaps *int) int { - a, b = order2Ordered(data, a, b, swaps) - b, c = order2Ordered(data, b, c, swaps) - a, b = order2Ordered(data, a, b, swaps) - return b -} - -// medianAdjacentOrdered finds the median of data[a - 1], data[a], data[a + 1] and stores the index into a. -func medianAdjacentOrdered[E constraints.Ordered](data []E, a int, swaps *int) int { - return medianOrdered(data, a-1, a, a+1, swaps) -} - -func reverseRangeOrdered[E constraints.Ordered](data []E, a, b int) { - i := a - j := b - 1 - for i < j { - data[i], data[j] = data[j], data[i] - i++ - j-- - } -} - -func swapRangeOrdered[E constraints.Ordered](data []E, a, b, n int) { - for i := 0; i < n; i++ { - data[a+i], data[b+i] = data[b+i], data[a+i] - } -} - -func stableOrdered[E constraints.Ordered](data []E, n int) { - blockSize := 20 // must be > 0 - a, b := 0, blockSize - for b <= n { - insertionSortOrdered(data, a, b) - a = b - b += blockSize - } - insertionSortOrdered(data, a, n) - - for blockSize < n { - a, b = 0, 2*blockSize - for b <= n { - symMergeOrdered(data, a, a+blockSize, b) - a = b - b += 2 * blockSize - } - if m := a + blockSize; m < n { - symMergeOrdered(data, a, m, n) - } - blockSize *= 2 - } -} - -// symMergeOrdered merges the two sorted subsequences data[a:m] and data[m:b] using -// the SymMerge algorithm from Pok-Son Kim and Arne Kutzner, "Stable Minimum -// Storage Merging by Symmetric Comparisons", in Susanne Albers and Tomasz -// Radzik, editors, Algorithms - ESA 2004, volume 3221 of Lecture Notes in -// Computer Science, pages 714-723. Springer, 2004. -// -// Let M = m-a and N = b-n. Wolog M < N. -// The recursion depth is bound by ceil(log(N+M)). -// The algorithm needs O(M*log(N/M + 1)) calls to data.Less. -// The algorithm needs O((M+N)*log(M)) calls to data.Swap. -// -// The paper gives O((M+N)*log(M)) as the number of assignments assuming a -// rotation algorithm which uses O(M+N+gcd(M+N)) assignments. The argumentation -// in the paper carries through for Swap operations, especially as the block -// swapping rotate uses only O(M+N) Swaps. -// -// symMerge assumes non-degenerate arguments: a < m && m < b. -// Having the caller check this condition eliminates many leaf recursion calls, -// which improves performance. -func symMergeOrdered[E constraints.Ordered](data []E, a, m, b int) { - // Avoid unnecessary recursions of symMerge - // by direct insertion of data[a] into data[m:b] - // if data[a:m] only contains one element. - if m-a == 1 { - // Use binary search to find the lowest index i - // such that data[i] >= data[a] for m <= i < b. - // Exit the search loop with i == b in case no such index exists. - i := m - j := b - for i < j { - h := int(uint(i+j) >> 1) - if cmpLess(data[h], data[a]) { - i = h + 1 - } else { - j = h - } - } - // Swap values until data[a] reaches the position before i. - for k := a; k < i-1; k++ { - data[k], data[k+1] = data[k+1], data[k] - } - return - } - - // Avoid unnecessary recursions of symMerge - // by direct insertion of data[m] into data[a:m] - // if data[m:b] only contains one element. - if b-m == 1 { - // Use binary search to find the lowest index i - // such that data[i] > data[m] for a <= i < m. - // Exit the search loop with i == m in case no such index exists. - i := a - j := m - for i < j { - h := int(uint(i+j) >> 1) - if !cmpLess(data[m], data[h]) { - i = h + 1 - } else { - j = h - } - } - // Swap values until data[m] reaches the position i. - for k := m; k > i; k-- { - data[k], data[k-1] = data[k-1], data[k] - } - return - } - - mid := int(uint(a+b) >> 1) - n := mid + m - var start, r int - if m > mid { - start = n - b - r = mid - } else { - start = a - r = m - } - p := n - 1 - - for start < r { - c := int(uint(start+r) >> 1) - if !cmpLess(data[p-c], data[c]) { - start = c + 1 - } else { - r = c - } - } - - end := n - start - if start < m && m < end { - rotateOrdered(data, start, m, end) - } - if a < start && start < mid { - symMergeOrdered(data, a, start, mid) - } - if mid < end && end < b { - symMergeOrdered(data, mid, end, b) - } -} - -// rotateOrdered rotates two consecutive blocks u = data[a:m] and v = data[m:b] in data: -// Data of the form 'x u v y' is changed to 'x v u y'. -// rotate performs at most b-a many calls to data.Swap, -// and it assumes non-degenerate arguments: a < m && m < b. -func rotateOrdered[E constraints.Ordered](data []E, a, m, b int) { - i := m - a - j := b - m - - for i != j { - if i > j { - swapRangeOrdered(data, m-i, m, j) - i -= j - } else { - swapRangeOrdered(data, m-i, m+j-i, i) - j -= i - } - } - // i == j - swapRangeOrdered(data, m-i, m, i) -} diff --git a/source/vendor/golang.org/x/net/html/doctype.go b/source/vendor/golang.org/x/net/html/doctype.go index c484e5a94fbf0a38b9c1789356f9f152ccaec4d2..bca3ae9a0c221ab109e5051c76b377e29f0b70bb 100644 --- a/source/vendor/golang.org/x/net/html/doctype.go +++ b/source/vendor/golang.org/x/net/html/doctype.go @@ -87,7 +87,7 @@ func parseDoctype(s string) (n *Node, quirks bool) { } } if lastAttr := n.Attr[len(n.Attr)-1]; lastAttr.Key == "system" && - strings.ToLower(lastAttr.Val) == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd" { + strings.EqualFold(lastAttr.Val, "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") { quirks = true } } diff --git a/source/vendor/golang.org/x/net/html/foreign.go b/source/vendor/golang.org/x/net/html/foreign.go index 9da9e9dc4246323836f27dca93d039732e88bd7d..e8515d8e887fb26a540fc64c7edca76ad6a14723 100644 --- a/source/vendor/golang.org/x/net/html/foreign.go +++ b/source/vendor/golang.org/x/net/html/foreign.go @@ -40,8 +40,7 @@ func htmlIntegrationPoint(n *Node) bool { if n.Data == "annotation-xml" { for _, a := range n.Attr { if a.Key == "encoding" { - val := strings.ToLower(a.Val) - if val == "text/html" || val == "application/xhtml+xml" { + if strings.EqualFold(a.Val, "text/html") || strings.EqualFold(a.Val, "application/xhtml+xml") { return true } } diff --git a/source/vendor/golang.org/x/net/html/parse.go b/source/vendor/golang.org/x/net/html/parse.go index 46a89eda6c19954b7fccde101a6c87bd225ded83..643c674e37802d509cb5806cff26a0b0be4ab603 100644 --- a/source/vendor/golang.org/x/net/html/parse.go +++ b/source/vendor/golang.org/x/net/html/parse.go @@ -840,6 +840,10 @@ func afterHeadIM(p *parser) bool { p.parseImpliedToken(StartTagToken, a.Body, a.Body.String()) p.framesetOK = true + if p.tok.Type == ErrorToken { + // Stop parsing. + return true + } return false } @@ -1031,7 +1035,7 @@ func inBodyIM(p *parser) bool { if p.tok.DataAtom == a.Input { for _, t := range p.tok.Attr { if t.Key == "type" { - if strings.ToLower(t.Val) == "hidden" { + if strings.EqualFold(t.Val, "hidden") { // Skip setting framesetOK = false return true } @@ -1459,7 +1463,7 @@ func inTableIM(p *parser) bool { return inHeadIM(p) case a.Input: for _, t := range p.tok.Attr { - if t.Key == "type" && strings.ToLower(t.Val) == "hidden" { + if t.Key == "type" && strings.EqualFold(t.Val, "hidden") { p.addElement() p.oe.pop() return true diff --git a/source/vendor/golang.org/x/sys/unix/auxv.go b/source/vendor/golang.org/x/sys/unix/auxv.go new file mode 100644 index 0000000000000000000000000000000000000000..37a82528f580f1a3fa7ed57d65cbb8ee7097a98e --- /dev/null +++ b/source/vendor/golang.org/x/sys/unix/auxv.go @@ -0,0 +1,36 @@ +// Copyright 2025 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 go1.21 && (aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos) + +package unix + +import ( + "syscall" + "unsafe" +) + +//go:linkname runtime_getAuxv runtime.getAuxv +func runtime_getAuxv() []uintptr + +// Auxv returns the ELF auxiliary vector as a sequence of key/value pairs. +// The returned slice is always a fresh copy, owned by the caller. +// It returns an error on non-ELF platforms, or if the auxiliary vector cannot be accessed, +// which happens in some locked-down environments and build modes. +func Auxv() ([][2]uintptr, error) { + vec := runtime_getAuxv() + vecLen := len(vec) + + if vecLen == 0 { + return nil, syscall.ENOENT + } + + if vecLen%2 != 0 { + return nil, syscall.EINVAL + } + + result := make([]uintptr, vecLen) + copy(result, vec) + return unsafe.Slice((*[2]uintptr)(unsafe.Pointer(&result[0])), vecLen/2), nil +} diff --git a/source/vendor/golang.org/x/sys/unix/auxv_unsupported.go b/source/vendor/golang.org/x/sys/unix/auxv_unsupported.go new file mode 100644 index 0000000000000000000000000000000000000000..1200487f2e86c60b112d6042f329ce48f677bb64 --- /dev/null +++ b/source/vendor/golang.org/x/sys/unix/auxv_unsupported.go @@ -0,0 +1,13 @@ +// Copyright 2025 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 !go1.21 && (aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos) + +package unix + +import "syscall" + +func Auxv() ([][2]uintptr, error) { + return nil, syscall.ENOTSUP +} diff --git a/source/vendor/golang.org/x/sys/unix/syscall_dragonfly.go b/source/vendor/golang.org/x/sys/unix/syscall_dragonfly.go index 97cb916f2c90ef178ea7d14f319ff73360ef2210..be8c0020701ee4ccbc415fb16e00108033093c5b 100644 --- a/source/vendor/golang.org/x/sys/unix/syscall_dragonfly.go +++ b/source/vendor/golang.org/x/sys/unix/syscall_dragonfly.go @@ -246,6 +246,18 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e return sendfile(outfd, infd, offset, count) } +func Dup3(oldfd, newfd, flags int) error { + if oldfd == newfd || flags&^O_CLOEXEC != 0 { + return EINVAL + } + how := F_DUP2FD + if flags&O_CLOEXEC != 0 { + how = F_DUP2FD_CLOEXEC + } + _, err := fcntl(oldfd, how, newfd) + return err +} + /* * Exposed directly */ diff --git a/source/vendor/golang.org/x/sys/unix/syscall_solaris.go b/source/vendor/golang.org/x/sys/unix/syscall_solaris.go index 21974af064ddc38e765f3543cda0a9ca29aa44aa..abc3955477c7d38a774bc46bdd8ed0fd736a7bb8 100644 --- a/source/vendor/golang.org/x/sys/unix/syscall_solaris.go +++ b/source/vendor/golang.org/x/sys/unix/syscall_solaris.go @@ -1102,3 +1102,90 @@ func (s *Strioctl) SetInt(i int) { func IoctlSetStrioctlRetInt(fd int, req int, s *Strioctl) (int, error) { return ioctlPtrRet(fd, req, unsafe.Pointer(s)) } + +// Ucred Helpers +// See ucred(3c) and getpeerucred(3c) + +//sys getpeerucred(fd uintptr, ucred *uintptr) (err error) +//sys ucredFree(ucred uintptr) = ucred_free +//sys ucredGet(pid int) (ucred uintptr, err error) = ucred_get +//sys ucredGeteuid(ucred uintptr) (uid int) = ucred_geteuid +//sys ucredGetegid(ucred uintptr) (gid int) = ucred_getegid +//sys ucredGetruid(ucred uintptr) (uid int) = ucred_getruid +//sys ucredGetrgid(ucred uintptr) (gid int) = ucred_getrgid +//sys ucredGetsuid(ucred uintptr) (uid int) = ucred_getsuid +//sys ucredGetsgid(ucred uintptr) (gid int) = ucred_getsgid +//sys ucredGetpid(ucred uintptr) (pid int) = ucred_getpid + +// Ucred is an opaque struct that holds user credentials. +type Ucred struct { + ucred uintptr +} + +// We need to ensure that ucredFree is called on the underlying ucred +// when the Ucred is garbage collected. +func ucredFinalizer(u *Ucred) { + ucredFree(u.ucred) +} + +func GetPeerUcred(fd uintptr) (*Ucred, error) { + var ucred uintptr + err := getpeerucred(fd, &ucred) + if err != nil { + return nil, err + } + result := &Ucred{ + ucred: ucred, + } + // set the finalizer on the result so that the ucred will be freed + runtime.SetFinalizer(result, ucredFinalizer) + return result, nil +} + +func UcredGet(pid int) (*Ucred, error) { + ucred, err := ucredGet(pid) + if err != nil { + return nil, err + } + result := &Ucred{ + ucred: ucred, + } + // set the finalizer on the result so that the ucred will be freed + runtime.SetFinalizer(result, ucredFinalizer) + return result, nil +} + +func (u *Ucred) Geteuid() int { + defer runtime.KeepAlive(u) + return ucredGeteuid(u.ucred) +} + +func (u *Ucred) Getruid() int { + defer runtime.KeepAlive(u) + return ucredGetruid(u.ucred) +} + +func (u *Ucred) Getsuid() int { + defer runtime.KeepAlive(u) + return ucredGetsuid(u.ucred) +} + +func (u *Ucred) Getegid() int { + defer runtime.KeepAlive(u) + return ucredGetegid(u.ucred) +} + +func (u *Ucred) Getrgid() int { + defer runtime.KeepAlive(u) + return ucredGetrgid(u.ucred) +} + +func (u *Ucred) Getsgid() int { + defer runtime.KeepAlive(u) + return ucredGetsgid(u.ucred) +} + +func (u *Ucred) Getpid() int { + defer runtime.KeepAlive(u) + return ucredGetpid(u.ucred) +} diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux.go index ccba391c9fb0923f4113e45e00491f3b015f254e..4f432bfe8feeee77862ace1bbfbed983d72f6e76 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux.go @@ -321,6 +321,9 @@ const ( AUDIT_INTEGRITY_STATUS = 0x70a AUDIT_IPC = 0x517 AUDIT_IPC_SET_PERM = 0x51f + AUDIT_IPE_ACCESS = 0x58c + AUDIT_IPE_CONFIG_CHANGE = 0x58d + AUDIT_IPE_POLICY_LOAD = 0x58e AUDIT_KERNEL = 0x7d0 AUDIT_KERNEL_OTHER = 0x524 AUDIT_KERN_MODULE = 0x532 @@ -489,6 +492,7 @@ const ( BPF_F_ID = 0x20 BPF_F_NETFILTER_IP_DEFRAG = 0x1 BPF_F_QUERY_EFFECTIVE = 0x1 + BPF_F_REDIRECT_FLAGS = 0x19 BPF_F_REPLACE = 0x4 BPF_F_SLEEPABLE = 0x10 BPF_F_STRICT_ALIGNMENT = 0x1 @@ -1166,6 +1170,7 @@ const ( EXTA = 0xe EXTB = 0xf F2FS_SUPER_MAGIC = 0xf2f52010 + FALLOC_FL_ALLOCATE_RANGE = 0x0 FALLOC_FL_COLLAPSE_RANGE = 0x8 FALLOC_FL_INSERT_RANGE = 0x20 FALLOC_FL_KEEP_SIZE = 0x1 @@ -1240,6 +1245,7 @@ const ( FAN_REPORT_DFID_NAME = 0xc00 FAN_REPORT_DFID_NAME_TARGET = 0x1e00 FAN_REPORT_DIR_FID = 0x400 + FAN_REPORT_FD_ERROR = 0x2000 FAN_REPORT_FID = 0x200 FAN_REPORT_NAME = 0x800 FAN_REPORT_PIDFD = 0x80 @@ -1325,8 +1331,10 @@ const ( FUSE_SUPER_MAGIC = 0x65735546 FUTEXFS_SUPER_MAGIC = 0xbad1dea F_ADD_SEALS = 0x409 + F_CREATED_QUERY = 0x404 F_DUPFD = 0x0 F_DUPFD_CLOEXEC = 0x406 + F_DUPFD_QUERY = 0x403 F_EXLCK = 0x4 F_GETFD = 0x1 F_GETFL = 0x3 @@ -1546,6 +1554,7 @@ const ( IPPROTO_ROUTING = 0x2b IPPROTO_RSVP = 0x2e IPPROTO_SCTP = 0x84 + IPPROTO_SMC = 0x100 IPPROTO_TCP = 0x6 IPPROTO_TP = 0x1d IPPROTO_UDP = 0x11 @@ -1618,6 +1627,8 @@ const ( IPV6_UNICAST_IF = 0x4c IPV6_USER_FLOW = 0xe IPV6_V6ONLY = 0x1a + IPV6_VERSION = 0x60 + IPV6_VERSION_MASK = 0xf0 IPV6_XFRM_POLICY = 0x23 IP_ADD_MEMBERSHIP = 0x23 IP_ADD_SOURCE_MEMBERSHIP = 0x27 @@ -1799,6 +1810,8 @@ const ( LANDLOCK_ACCESS_NET_BIND_TCP = 0x1 LANDLOCK_ACCESS_NET_CONNECT_TCP = 0x2 LANDLOCK_CREATE_RULESET_VERSION = 0x1 + LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET = 0x1 + LANDLOCK_SCOPE_SIGNAL = 0x2 LINUX_REBOOT_CMD_CAD_OFF = 0x0 LINUX_REBOOT_CMD_CAD_ON = 0x89abcdef LINUX_REBOOT_CMD_HALT = 0xcdef0123 @@ -1860,6 +1873,7 @@ const ( MADV_UNMERGEABLE = 0xd MADV_WILLNEED = 0x3 MADV_WIPEONFORK = 0x12 + MAP_DROPPABLE = 0x8 MAP_FILE = 0x0 MAP_FIXED = 0x10 MAP_FIXED_NOREPLACE = 0x100000 @@ -1924,6 +1938,7 @@ const ( MNT_FORCE = 0x1 MNT_ID_REQ_SIZE_VER0 = 0x18 MNT_ID_REQ_SIZE_VER1 = 0x20 + MNT_NS_INFO_SIZE_VER0 = 0x10 MODULE_INIT_COMPRESSED_FILE = 0x4 MODULE_INIT_IGNORE_MODVERSIONS = 0x1 MODULE_INIT_IGNORE_VERMAGIC = 0x2 @@ -1959,6 +1974,7 @@ const ( MSG_PEEK = 0x2 MSG_PROXY = 0x10 MSG_RST = 0x1000 + MSG_SOCK_DEVMEM = 0x2000000 MSG_SYN = 0x400 MSG_TRUNC = 0x20 MSG_TRYHARD = 0x4 @@ -2075,6 +2091,7 @@ const ( NFC_ATR_REQ_MAXSIZE = 0x40 NFC_ATR_RES_GB_MAXSIZE = 0x2f NFC_ATR_RES_MAXSIZE = 0x40 + NFC_ATS_MAXSIZE = 0x14 NFC_COMM_ACTIVE = 0x0 NFC_COMM_PASSIVE = 0x1 NFC_DEVICE_NAME_MAXSIZE = 0x8 @@ -2155,6 +2172,7 @@ const ( NFNL_SUBSYS_QUEUE = 0x3 NFNL_SUBSYS_ULOG = 0x4 NFS_SUPER_MAGIC = 0x6969 + NFT_BITWISE_BOOL = 0x0 NFT_CHAIN_FLAGS = 0x7 NFT_CHAIN_MAXNAMELEN = 0x100 NFT_CT_MAX = 0x17 @@ -2483,6 +2501,7 @@ const ( PR_GET_PDEATHSIG = 0x2 PR_GET_SECCOMP = 0x15 PR_GET_SECUREBITS = 0x1b + PR_GET_SHADOW_STACK_STATUS = 0x4a PR_GET_SPECULATION_CTRL = 0x34 PR_GET_TAGGED_ADDR_CTRL = 0x38 PR_GET_THP_DISABLE = 0x2a @@ -2491,6 +2510,7 @@ const ( PR_GET_TIMING = 0xd PR_GET_TSC = 0x19 PR_GET_UNALIGN = 0x5 + PR_LOCK_SHADOW_STACK_STATUS = 0x4c PR_MCE_KILL = 0x21 PR_MCE_KILL_CLEAR = 0x0 PR_MCE_KILL_DEFAULT = 0x2 @@ -2517,6 +2537,8 @@ const ( PR_PAC_GET_ENABLED_KEYS = 0x3d PR_PAC_RESET_KEYS = 0x36 PR_PAC_SET_ENABLED_KEYS = 0x3c + PR_PMLEN_MASK = 0x7f000000 + PR_PMLEN_SHIFT = 0x18 PR_PPC_DEXCR_CTRL_CLEAR = 0x4 PR_PPC_DEXCR_CTRL_CLEAR_ONEXEC = 0x10 PR_PPC_DEXCR_CTRL_EDITABLE = 0x1 @@ -2584,6 +2606,7 @@ const ( PR_SET_PTRACER = 0x59616d61 PR_SET_SECCOMP = 0x16 PR_SET_SECUREBITS = 0x1c + PR_SET_SHADOW_STACK_STATUS = 0x4b PR_SET_SPECULATION_CTRL = 0x35 PR_SET_SYSCALL_USER_DISPATCH = 0x3b PR_SET_TAGGED_ADDR_CTRL = 0x37 @@ -2594,6 +2617,9 @@ const ( PR_SET_UNALIGN = 0x6 PR_SET_VMA = 0x53564d41 PR_SET_VMA_ANON_NAME = 0x0 + PR_SHADOW_STACK_ENABLE = 0x1 + PR_SHADOW_STACK_PUSH = 0x4 + PR_SHADOW_STACK_WRITE = 0x2 PR_SME_GET_VL = 0x40 PR_SME_SET_VL = 0x3f PR_SME_SET_VL_ONEXEC = 0x40000 @@ -2903,7 +2929,6 @@ const ( RTM_NEWNEXTHOP = 0x68 RTM_NEWNEXTHOPBUCKET = 0x74 RTM_NEWNSID = 0x58 - RTM_NEWNVLAN = 0x70 RTM_NEWPREFIX = 0x34 RTM_NEWQDISC = 0x24 RTM_NEWROUTE = 0x18 @@ -2912,6 +2937,7 @@ const ( RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c RTM_NEWTUNNEL = 0x78 + RTM_NEWVLAN = 0x70 RTM_NR_FAMILIES = 0x1b RTM_NR_MSGTYPES = 0x6c RTM_SETDCB = 0x4f @@ -2970,6 +2996,7 @@ const ( RWF_WRITE_LIFE_NOT_SET = 0x0 SCHED_BATCH = 0x3 SCHED_DEADLINE = 0x6 + SCHED_EXT = 0x7 SCHED_FIFO = 0x1 SCHED_FLAG_ALL = 0x7f SCHED_FLAG_DL_OVERRUN = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_386.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_386.go index 0c00cb3f3af836e182b7aa7ac2280ee2428d1967..75207613c785dbe3fb5e9afd152330e4ff342de3 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_386.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_386.go @@ -109,12 +109,15 @@ const ( HIDIOCGRAWINFO = 0x80084803 HIDIOCGRDESC = 0x90044802 HIDIOCGRDESCSIZE = 0x80044801 + HIDIOCREVOKE = 0x4004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x8000 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -297,10 +300,13 @@ const ( RTC_WIE_ON = 0x700f RTC_WKALM_RD = 0x80287010 RTC_WKALM_SET = 0x4028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 @@ -335,6 +341,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x27 SO_DONTROUTE = 0x5 SO_ERROR = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go index dfb364554dd58370b18e39856c3247a8ea5e07b7..c68acda53522d124fc1ef7c7dc889394ca4103ab 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go @@ -109,12 +109,15 @@ const ( HIDIOCGRAWINFO = 0x80084803 HIDIOCGRDESC = 0x90044802 HIDIOCGRDESCSIZE = 0x80044801 + HIDIOCREVOKE = 0x4004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x8000 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -298,10 +301,13 @@ const ( RTC_WIE_ON = 0x700f RTC_WKALM_RD = 0x80287010 RTC_WKALM_SET = 0x4028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 @@ -336,6 +342,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x27 SO_DONTROUTE = 0x5 SO_ERROR = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go index d46dcf78abc9a876cf38213985e869ebc601842e..a8c607ab86b51b1e69629a7131b674a533c1a05f 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go @@ -108,12 +108,15 @@ const ( HIDIOCGRAWINFO = 0x80084803 HIDIOCGRDESC = 0x90044802 HIDIOCGRDESCSIZE = 0x80044801 + HIDIOCREVOKE = 0x4004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x8000 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -303,10 +306,13 @@ const ( RTC_WIE_ON = 0x700f RTC_WKALM_RD = 0x80287010 RTC_WKALM_SET = 0x4028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 @@ -341,6 +347,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x27 SO_DONTROUTE = 0x5 SO_ERROR = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go index 3af3248a7f2e14a21a33edcbc4b00af5d4888c6a..18563dd8d33a0f8e7a343377cd529ddf3eeb47fc 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go @@ -109,15 +109,19 @@ const ( F_SETOWN = 0x8 F_UNLCK = 0x2 F_WRLCK = 0x1 + GCS_MAGIC = 0x47435300 HIDIOCGRAWINFO = 0x80084803 HIDIOCGRDESC = 0x90044802 HIDIOCGRDESCSIZE = 0x80044801 + HIDIOCREVOKE = 0x4004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x8000 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -205,6 +209,7 @@ const ( PERF_EVENT_IOC_SET_BPF = 0x40042408 PERF_EVENT_IOC_SET_FILTER = 0x40082406 PERF_EVENT_IOC_SET_OUTPUT = 0x2405 + POE_MAGIC = 0x504f4530 PPPIOCATTACH = 0x4004743d PPPIOCATTCHAN = 0x40047438 PPPIOCBRIDGECHAN = 0x40047435 @@ -294,10 +299,13 @@ const ( RTC_WIE_ON = 0x700f RTC_WKALM_RD = 0x80287010 RTC_WKALM_SET = 0x4028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 @@ -332,6 +340,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x27 SO_DONTROUTE = 0x5 SO_ERROR = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_loong64.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_loong64.go index 292bcf0283d179d091e5a95b052859b0feda1938..22912cdaa94483d6a5a2759d4d05b72663fce96b 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_loong64.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_loong64.go @@ -109,12 +109,15 @@ const ( HIDIOCGRAWINFO = 0x80084803 HIDIOCGRDESC = 0x90044802 HIDIOCGRDESCSIZE = 0x80044801 + HIDIOCREVOKE = 0x4004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x8000 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -290,10 +293,13 @@ const ( RTC_WIE_ON = 0x700f RTC_WKALM_RD = 0x80287010 RTC_WKALM_SET = 0x4028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 @@ -328,6 +334,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x27 SO_DONTROUTE = 0x5 SO_ERROR = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go index 782b7110fa19b814ef9d24773925c82b227ed438..29344eb37ab55a5982a044ccd388638be2ce0f23 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go @@ -108,12 +108,15 @@ const ( HIDIOCGRAWINFO = 0x40084803 HIDIOCGRDESC = 0x50044802 HIDIOCGRDESCSIZE = 0x40044801 + HIDIOCREVOKE = 0x8004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x100 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x80 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -296,10 +299,13 @@ const ( RTC_WIE_ON = 0x2000700f RTC_WKALM_RD = 0x40287010 RTC_WKALM_SET = 0x8028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 @@ -334,6 +340,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x1029 SO_DONTROUTE = 0x10 SO_ERROR = 0x1007 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go index 84973fd9271fbc919af57df6699f6365ec0d2e86..20d51fb96a897f5c675d91b1107efa1b0956c3b0 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go @@ -108,12 +108,15 @@ const ( HIDIOCGRAWINFO = 0x40084803 HIDIOCGRDESC = 0x50044802 HIDIOCGRDESCSIZE = 0x40044801 + HIDIOCREVOKE = 0x8004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x100 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x80 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -296,10 +299,13 @@ const ( RTC_WIE_ON = 0x2000700f RTC_WKALM_RD = 0x40287010 RTC_WKALM_SET = 0x8028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 @@ -334,6 +340,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x1029 SO_DONTROUTE = 0x10 SO_ERROR = 0x1007 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go index 6d9cbc3b274bf1a0d81dd1df0610fc2f7575f71c..321b60902ae5cd5686f44b8dcf9d742a6df9d30c 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go @@ -108,12 +108,15 @@ const ( HIDIOCGRAWINFO = 0x40084803 HIDIOCGRDESC = 0x50044802 HIDIOCGRDESCSIZE = 0x40044801 + HIDIOCREVOKE = 0x8004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x100 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x80 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -296,10 +299,13 @@ const ( RTC_WIE_ON = 0x2000700f RTC_WKALM_RD = 0x40287010 RTC_WKALM_SET = 0x8028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 @@ -334,6 +340,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x1029 SO_DONTROUTE = 0x10 SO_ERROR = 0x1007 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go index 5f9fedbce028d1a66846dd4790a9bd51b4f59e68..9bacdf1e27910f1e8f2cb8c582b37f7c54467224 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go @@ -108,12 +108,15 @@ const ( HIDIOCGRAWINFO = 0x40084803 HIDIOCGRDESC = 0x50044802 HIDIOCGRDESCSIZE = 0x40044801 + HIDIOCREVOKE = 0x8004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x100 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x80 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -296,10 +299,13 @@ const ( RTC_WIE_ON = 0x2000700f RTC_WKALM_RD = 0x40287010 RTC_WKALM_SET = 0x8028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 @@ -334,6 +340,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x1029 SO_DONTROUTE = 0x10 SO_ERROR = 0x1007 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go index bb0026ee0c46748816f20c8b0707de07d5a76f2b..c2242726156a94e77d1b3a6b5c8f5e0f61b643f7 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go @@ -108,12 +108,15 @@ const ( HIDIOCGRAWINFO = 0x40084803 HIDIOCGRDESC = 0x50044802 HIDIOCGRDESCSIZE = 0x40044801 + HIDIOCREVOKE = 0x8004480d HUPCL = 0x4000 ICANON = 0x100 IEXTEN = 0x400 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x80 IUCLC = 0x1000 IXOFF = 0x400 @@ -351,10 +354,13 @@ const ( RTC_WIE_ON = 0x2000700f RTC_WKALM_RD = 0x40287010 RTC_WKALM_SET = 0x8028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 @@ -389,6 +395,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x27 SO_DONTROUTE = 0x5 SO_ERROR = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go index 46120db5c9a19d9f94962b96472083114490e0a5..6270c8ee13e3f5ac37b6954b36ca972696ad092c 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go @@ -108,12 +108,15 @@ const ( HIDIOCGRAWINFO = 0x40084803 HIDIOCGRDESC = 0x50044802 HIDIOCGRDESCSIZE = 0x40044801 + HIDIOCREVOKE = 0x8004480d HUPCL = 0x4000 ICANON = 0x100 IEXTEN = 0x400 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x80 IUCLC = 0x1000 IXOFF = 0x400 @@ -355,10 +358,13 @@ const ( RTC_WIE_ON = 0x2000700f RTC_WKALM_RD = 0x40287010 RTC_WKALM_SET = 0x8028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 @@ -393,6 +399,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x27 SO_DONTROUTE = 0x5 SO_ERROR = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go index 5c951634fbed397c5d5c7a1468666baab9cd4cf3..9966c1941f8301450c052e12184340b465ad204e 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go @@ -108,12 +108,15 @@ const ( HIDIOCGRAWINFO = 0x40084803 HIDIOCGRDESC = 0x50044802 HIDIOCGRDESCSIZE = 0x40044801 + HIDIOCREVOKE = 0x8004480d HUPCL = 0x4000 ICANON = 0x100 IEXTEN = 0x400 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x80 IUCLC = 0x1000 IXOFF = 0x400 @@ -355,10 +358,13 @@ const ( RTC_WIE_ON = 0x2000700f RTC_WKALM_RD = 0x40287010 RTC_WKALM_SET = 0x8028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 @@ -393,6 +399,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x27 SO_DONTROUTE = 0x5 SO_ERROR = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go index 11a84d5af2083a43cd0db144cbac002a8a622a47..848e5fcc42e6f2f5dcc59d5a5d79199e57a856cb 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go @@ -108,12 +108,15 @@ const ( HIDIOCGRAWINFO = 0x80084803 HIDIOCGRDESC = 0x90044802 HIDIOCGRDESCSIZE = 0x80044801 + HIDIOCREVOKE = 0x4004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x8000 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -287,10 +290,13 @@ const ( RTC_WIE_ON = 0x700f RTC_WKALM_RD = 0x80287010 RTC_WKALM_SET = 0x4028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 @@ -325,6 +331,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x27 SO_DONTROUTE = 0x5 SO_ERROR = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go index f78c4617cac1f75ae6c066bfc4d9746892bf5e08..669b2adb80b778d9daf8400dd00cbab41c0ea5d1 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go @@ -108,12 +108,15 @@ const ( HIDIOCGRAWINFO = 0x80084803 HIDIOCGRDESC = 0x90044802 HIDIOCGRDESCSIZE = 0x80044801 + HIDIOCREVOKE = 0x4004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x8000 IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -359,10 +362,13 @@ const ( RTC_WIE_ON = 0x700f RTC_WKALM_RD = 0x80287010 RTC_WKALM_SET = 0x4028700f + SCM_DEVMEM_DMABUF = 0x4f + SCM_DEVMEM_LINEAR = 0x4e SCM_TIMESTAMPING = 0x25 SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 @@ -397,6 +403,9 @@ const ( SO_CNX_ADVICE = 0x35 SO_COOKIE = 0x39 SO_DETACH_REUSEPORT_BPF = 0x44 + SO_DEVMEM_DMABUF = 0x4f + SO_DEVMEM_DONTNEED = 0x50 + SO_DEVMEM_LINEAR = 0x4e SO_DOMAIN = 0x27 SO_DONTROUTE = 0x5 SO_ERROR = 0x4 diff --git a/source/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go b/source/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go index aeb777c34427de98fb86bd2980887250545532b6..4834e57514e44a7f8ca60a6a29e241ac1dba1c77 100644 --- a/source/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +++ b/source/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go @@ -112,12 +112,15 @@ const ( HIDIOCGRAWINFO = 0x40084803 HIDIOCGRDESC = 0x50044802 HIDIOCGRDESCSIZE = 0x40044801 + HIDIOCREVOKE = 0x8004480d HUPCL = 0x400 ICANON = 0x2 IEXTEN = 0x8000 IN_CLOEXEC = 0x400000 IN_NONBLOCK = 0x4000 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 @@ -350,10 +353,13 @@ const ( RTC_WIE_ON = 0x2000700f RTC_WKALM_RD = 0x40287010 RTC_WKALM_SET = 0x8028700f + SCM_DEVMEM_DMABUF = 0x58 + SCM_DEVMEM_LINEAR = 0x57 SCM_TIMESTAMPING = 0x23 SCM_TIMESTAMPING_OPT_STATS = 0x38 SCM_TIMESTAMPING_PKTINFO = 0x3c SCM_TIMESTAMPNS = 0x21 + SCM_TS_OPT_ID = 0x5a SCM_TXTIME = 0x3f SCM_WIFI_STATUS = 0x25 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 @@ -436,6 +442,9 @@ const ( SO_CNX_ADVICE = 0x37 SO_COOKIE = 0x3b SO_DETACH_REUSEPORT_BPF = 0x47 + SO_DEVMEM_DMABUF = 0x58 + SO_DEVMEM_DONTNEED = 0x59 + SO_DEVMEM_LINEAR = 0x57 SO_DOMAIN = 0x1029 SO_DONTROUTE = 0x10 SO_ERROR = 0x1007 diff --git a/source/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go b/source/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go index 829b87feb8da62f255f3b0662ed64cde8c2d01f7..c6545413c45b44cfa7876eb1ce27a1848c79b192 100644 --- a/source/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go +++ b/source/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go @@ -141,6 +141,16 @@ import ( //go:cgo_import_dynamic libc_getpeername getpeername "libsocket.so" //go:cgo_import_dynamic libc_setsockopt setsockopt "libsocket.so" //go:cgo_import_dynamic libc_recvfrom recvfrom "libsocket.so" +//go:cgo_import_dynamic libc_getpeerucred getpeerucred "libc.so" +//go:cgo_import_dynamic libc_ucred_get ucred_get "libc.so" +//go:cgo_import_dynamic libc_ucred_geteuid ucred_geteuid "libc.so" +//go:cgo_import_dynamic libc_ucred_getegid ucred_getegid "libc.so" +//go:cgo_import_dynamic libc_ucred_getruid ucred_getruid "libc.so" +//go:cgo_import_dynamic libc_ucred_getrgid ucred_getrgid "libc.so" +//go:cgo_import_dynamic libc_ucred_getsuid ucred_getsuid "libc.so" +//go:cgo_import_dynamic libc_ucred_getsgid ucred_getsgid "libc.so" +//go:cgo_import_dynamic libc_ucred_getpid ucred_getpid "libc.so" +//go:cgo_import_dynamic libc_ucred_free ucred_free "libc.so" //go:cgo_import_dynamic libc_port_create port_create "libc.so" //go:cgo_import_dynamic libc_port_associate port_associate "libc.so" //go:cgo_import_dynamic libc_port_dissociate port_dissociate "libc.so" @@ -280,6 +290,16 @@ import ( //go:linkname procgetpeername libc_getpeername //go:linkname procsetsockopt libc_setsockopt //go:linkname procrecvfrom libc_recvfrom +//go:linkname procgetpeerucred libc_getpeerucred +//go:linkname procucred_get libc_ucred_get +//go:linkname procucred_geteuid libc_ucred_geteuid +//go:linkname procucred_getegid libc_ucred_getegid +//go:linkname procucred_getruid libc_ucred_getruid +//go:linkname procucred_getrgid libc_ucred_getrgid +//go:linkname procucred_getsuid libc_ucred_getsuid +//go:linkname procucred_getsgid libc_ucred_getsgid +//go:linkname procucred_getpid libc_ucred_getpid +//go:linkname procucred_free libc_ucred_free //go:linkname procport_create libc_port_create //go:linkname procport_associate libc_port_associate //go:linkname procport_dissociate libc_port_dissociate @@ -420,6 +440,16 @@ var ( procgetpeername, procsetsockopt, procrecvfrom, + procgetpeerucred, + procucred_get, + procucred_geteuid, + procucred_getegid, + procucred_getruid, + procucred_getrgid, + procucred_getsuid, + procucred_getsgid, + procucred_getpid, + procucred_free, procport_create, procport_associate, procport_dissociate, @@ -2029,6 +2059,90 @@ func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Sockl // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func getpeerucred(fd uintptr, ucred *uintptr) (err error) { + _, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procgetpeerucred)), 2, uintptr(fd), uintptr(unsafe.Pointer(ucred)), 0, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGet(pid int) (ucred uintptr, err error) { + r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procucred_get)), 1, uintptr(pid), 0, 0, 0, 0, 0) + ucred = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGeteuid(ucred uintptr) (uid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_geteuid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetegid(ucred uintptr) (gid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getegid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetruid(ucred uintptr) (uid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getruid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetrgid(ucred uintptr) (gid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getrgid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetsuid(ucred uintptr) (uid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getsuid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetsgid(ucred uintptr) (gid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getsgid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetpid(ucred uintptr) (pid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getpid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredFree(ucred uintptr) { + sysvicall6(uintptr(unsafe.Pointer(&procucred_free)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func port_create() (n int, err error) { r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procport_create)), 0, 0, 0, 0, 0, 0, 0) n = int(r0) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go index 524b0820cbc2ee32a4598fa64ebbe64cec2a9dda..c79aaff306ae3eebf5d338ac84c4d478f566c485 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_386.go @@ -458,4 +458,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go index f485dbf4565671fd01bc685d7de256cbbac0dee2..5eb450695e95a819f1756ff2241adda0588cf628 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go @@ -381,4 +381,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go index 70b35bf3b09f68cb6bd6c4065b4248ed02657766..05e5029744586103a94d9482fe3dac1bb9ca607f 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_arm.go @@ -422,4 +422,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go index 1893e2fe884044dc9724126bf8565ca9fca04748..38c53ec51bb3e6b6fff2b168f1351758d99b6b05 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go @@ -325,4 +325,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_loong64.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_loong64.go index 16a4017da0ab2fbb8868a34cf7e90df9b052577e..31d2e71a18e17f4cd6fdd3a16f8ecffa1c2cdc91 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_loong64.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_loong64.go @@ -321,4 +321,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go index 7e567f1efff21dabc0bbb99d82ac79568fa0c71e..f4184a336b0e02d1ff0a976a4d47d01667072ff7 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips.go @@ -442,4 +442,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 4460 SYS_LSM_LIST_MODULES = 4461 SYS_MSEAL = 4462 + SYS_SETXATTRAT = 4463 + SYS_GETXATTRAT = 4464 + SYS_LISTXATTRAT = 4465 + SYS_REMOVEXATTRAT = 4466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go index 38ae55e5ef8564b859a937192e6e7ff9ff75404d..05b9962278f2760f8134c2396859cb9c142fa0a2 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go @@ -372,4 +372,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 5460 SYS_LSM_LIST_MODULES = 5461 SYS_MSEAL = 5462 + SYS_SETXATTRAT = 5463 + SYS_GETXATTRAT = 5464 + SYS_LISTXATTRAT = 5465 + SYS_REMOVEXATTRAT = 5466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go index 55e92e60a82abed887cc2e86929cf413ccc1f0e7..43a256e9e6758502f2f5883e3c43c29bb05f2bff 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go @@ -372,4 +372,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 5460 SYS_LSM_LIST_MODULES = 5461 SYS_MSEAL = 5462 + SYS_SETXATTRAT = 5463 + SYS_GETXATTRAT = 5464 + SYS_LISTXATTRAT = 5465 + SYS_REMOVEXATTRAT = 5466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go index 60658d6a021f66f19d23ed38f6eae448f0fa1b21..eea5ddfc220774443034d5ad1b052c17347d626e 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go @@ -442,4 +442,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 4460 SYS_LSM_LIST_MODULES = 4461 SYS_MSEAL = 4462 + SYS_SETXATTRAT = 4463 + SYS_GETXATTRAT = 4464 + SYS_LISTXATTRAT = 4465 + SYS_REMOVEXATTRAT = 4466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go index e203e8a7ed4b2c76d1a08ccda193c17f82fc7e93..0d777bfbb1408e2c32b03fdc2b5652157b3872a8 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go @@ -449,4 +449,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go index 5944b97d54604ea41a1dea195b26f3bd1f387343..b44636502561e6953318bb9cc942be9616340bc9 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go @@ -421,4 +421,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go index c66d416dad1ccb56f1196d99545460f9d658f092..0c7d21c18816539b4d6856dbcf44f56b4217c421 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go @@ -421,4 +421,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go index a5459e766f59dbfbd2751e1ecc5f7f1c4561bfb4..8405391698787a00552d807260232ad8680fd332 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go @@ -326,4 +326,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go index 01d86825bb926417fbc8c9e69c5ecb5bb599d683..fcf1b790d6cfd31996ab2f95beb8f965657e70be 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go @@ -387,4 +387,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go index 7b703e77cda8450621f3892f1a03d7e698f12cee..52d15b5f9d4597c74ff988c7893a0f2710963e3f 100644 --- a/source/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go +++ b/source/vendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go @@ -400,4 +400,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/source/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go b/source/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go index d003c3d43780c22bca92bd9426dc7e88bf7b8fb1..17c53bd9b3315aaec65571964e73bb93e6c85175 100644 --- a/source/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go +++ b/source/vendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go @@ -462,11 +462,14 @@ type FdSet struct { const ( SizeofIfMsghdr = 0x70 + SizeofIfMsghdr2 = 0xa0 SizeofIfData = 0x60 + SizeofIfData64 = 0x80 SizeofIfaMsghdr = 0x14 SizeofIfmaMsghdr = 0x10 SizeofIfmaMsghdr2 = 0x14 SizeofRtMsghdr = 0x5c + SizeofRtMsghdr2 = 0x5c SizeofRtMetrics = 0x38 ) @@ -480,6 +483,20 @@ type IfMsghdr struct { Data IfData } +type IfMsghdr2 struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + Snd_len int32 + Snd_maxlen int32 + Snd_drops int32 + Timer int32 + Data IfData64 +} + type IfData struct { Type uint8 Typelen uint8 @@ -512,6 +529,34 @@ type IfData struct { Reserved2 uint32 } +type IfData64 struct { + Type uint8 + Typelen uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Recvquota uint8 + Xmitquota uint8 + Unused1 uint8 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Noproto uint64 + Recvtiming uint32 + Xmittiming uint32 + Lastchange Timeval32 +} + type IfaMsghdr struct { Msglen uint16 Version uint8 @@ -557,6 +602,21 @@ type RtMsghdr struct { Rmx RtMetrics } +type RtMsghdr2 struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Flags int32 + Addrs int32 + Refcnt int32 + Parentflags int32 + Reserved int32 + Use int32 + Inits uint32 + Rmx RtMetrics +} + type RtMetrics struct { Locks uint32 Mtu uint32 diff --git a/source/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go b/source/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go index 0d45a941aaeccff1f29ca0bcfe667984a58f46d0..2392226a743eb3e19c581773191ddbe86eecad53 100644 --- a/source/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go +++ b/source/vendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go @@ -462,11 +462,14 @@ type FdSet struct { const ( SizeofIfMsghdr = 0x70 + SizeofIfMsghdr2 = 0xa0 SizeofIfData = 0x60 + SizeofIfData64 = 0x80 SizeofIfaMsghdr = 0x14 SizeofIfmaMsghdr = 0x10 SizeofIfmaMsghdr2 = 0x14 SizeofRtMsghdr = 0x5c + SizeofRtMsghdr2 = 0x5c SizeofRtMetrics = 0x38 ) @@ -480,6 +483,20 @@ type IfMsghdr struct { Data IfData } +type IfMsghdr2 struct { + Msglen uint16 + Version uint8 + Type uint8 + Addrs int32 + Flags int32 + Index uint16 + Snd_len int32 + Snd_maxlen int32 + Snd_drops int32 + Timer int32 + Data IfData64 +} + type IfData struct { Type uint8 Typelen uint8 @@ -512,6 +529,34 @@ type IfData struct { Reserved2 uint32 } +type IfData64 struct { + Type uint8 + Typelen uint8 + Physical uint8 + Addrlen uint8 + Hdrlen uint8 + Recvquota uint8 + Xmitquota uint8 + Unused1 uint8 + Mtu uint32 + Metric uint32 + Baudrate uint64 + Ipackets uint64 + Ierrors uint64 + Opackets uint64 + Oerrors uint64 + Collisions uint64 + Ibytes uint64 + Obytes uint64 + Imcasts uint64 + Omcasts uint64 + Iqdrops uint64 + Noproto uint64 + Recvtiming uint32 + Xmittiming uint32 + Lastchange Timeval32 +} + type IfaMsghdr struct { Msglen uint16 Version uint8 @@ -557,6 +602,21 @@ type RtMsghdr struct { Rmx RtMetrics } +type RtMsghdr2 struct { + Msglen uint16 + Version uint8 + Type uint8 + Index uint16 + Flags int32 + Addrs int32 + Refcnt int32 + Parentflags int32 + Reserved int32 + Use int32 + Inits uint32 + Rmx RtMetrics +} + type RtMetrics struct { Locks uint32 Mtu uint32 diff --git a/source/vendor/golang.org/x/sys/unix/ztypes_linux.go b/source/vendor/golang.org/x/sys/unix/ztypes_linux.go index 8daaf3faf4c7853867f3e5d0b45dda52380e1173..a46abe64720547a72a90330c2aa29113b4ef0552 100644 --- a/source/vendor/golang.org/x/sys/unix/ztypes_linux.go +++ b/source/vendor/golang.org/x/sys/unix/ztypes_linux.go @@ -2594,8 +2594,8 @@ const ( SOF_TIMESTAMPING_BIND_PHC = 0x8000 SOF_TIMESTAMPING_OPT_ID_TCP = 0x10000 - SOF_TIMESTAMPING_LAST = 0x10000 - SOF_TIMESTAMPING_MASK = 0x1ffff + SOF_TIMESTAMPING_LAST = 0x20000 + SOF_TIMESTAMPING_MASK = 0x3ffff SCM_TSTAMP_SND = 0x0 SCM_TSTAMP_SCHED = 0x1 @@ -3541,7 +3541,7 @@ type Nhmsg struct { type NexthopGrp struct { Id uint32 Weight uint8 - Resvd1 uint8 + High uint8 Resvd2 uint16 } @@ -3802,7 +3802,7 @@ const ( ETHTOOL_MSG_PSE_GET = 0x24 ETHTOOL_MSG_PSE_SET = 0x25 ETHTOOL_MSG_RSS_GET = 0x26 - ETHTOOL_MSG_USER_MAX = 0x2c + ETHTOOL_MSG_USER_MAX = 0x2d ETHTOOL_MSG_KERNEL_NONE = 0x0 ETHTOOL_MSG_STRSET_GET_REPLY = 0x1 ETHTOOL_MSG_LINKINFO_GET_REPLY = 0x2 @@ -3842,7 +3842,7 @@ const ( ETHTOOL_MSG_MODULE_NTF = 0x24 ETHTOOL_MSG_PSE_GET_REPLY = 0x25 ETHTOOL_MSG_RSS_GET_REPLY = 0x26 - ETHTOOL_MSG_KERNEL_MAX = 0x2c + ETHTOOL_MSG_KERNEL_MAX = 0x2e ETHTOOL_FLAG_COMPACT_BITSETS = 0x1 ETHTOOL_FLAG_OMIT_REPLY = 0x2 ETHTOOL_FLAG_STATS = 0x4 @@ -3850,7 +3850,7 @@ const ( ETHTOOL_A_HEADER_DEV_INDEX = 0x1 ETHTOOL_A_HEADER_DEV_NAME = 0x2 ETHTOOL_A_HEADER_FLAGS = 0x3 - ETHTOOL_A_HEADER_MAX = 0x3 + ETHTOOL_A_HEADER_MAX = 0x4 ETHTOOL_A_BITSET_BIT_UNSPEC = 0x0 ETHTOOL_A_BITSET_BIT_INDEX = 0x1 ETHTOOL_A_BITSET_BIT_NAME = 0x2 @@ -4031,11 +4031,11 @@ const ( ETHTOOL_A_CABLE_RESULT_UNSPEC = 0x0 ETHTOOL_A_CABLE_RESULT_PAIR = 0x1 ETHTOOL_A_CABLE_RESULT_CODE = 0x2 - ETHTOOL_A_CABLE_RESULT_MAX = 0x2 + ETHTOOL_A_CABLE_RESULT_MAX = 0x3 ETHTOOL_A_CABLE_FAULT_LENGTH_UNSPEC = 0x0 ETHTOOL_A_CABLE_FAULT_LENGTH_PAIR = 0x1 ETHTOOL_A_CABLE_FAULT_LENGTH_CM = 0x2 - ETHTOOL_A_CABLE_FAULT_LENGTH_MAX = 0x2 + ETHTOOL_A_CABLE_FAULT_LENGTH_MAX = 0x3 ETHTOOL_A_CABLE_TEST_NTF_STATUS_UNSPEC = 0x0 ETHTOOL_A_CABLE_TEST_NTF_STATUS_STARTED = 0x1 ETHTOOL_A_CABLE_TEST_NTF_STATUS_COMPLETED = 0x2 @@ -4200,7 +4200,8 @@ type ( } PtpSysOffsetExtended struct { Samples uint32 - Rsv [3]uint32 + Clockid int32 + Rsv [2]uint32 Ts [25][3]PtpClockTime } PtpSysOffsetPrecise struct { @@ -4399,6 +4400,7 @@ const ( type LandlockRulesetAttr struct { Access_fs uint64 Access_net uint64 + Scoped uint64 } type LandlockPathBeneathAttr struct { @@ -4745,7 +4747,7 @@ const ( NL80211_ATTR_MAC_HINT = 0xc8 NL80211_ATTR_MAC_MASK = 0xd7 NL80211_ATTR_MAX_AP_ASSOC_STA = 0xca - NL80211_ATTR_MAX = 0x14c + NL80211_ATTR_MAX = 0x14d NL80211_ATTR_MAX_CRIT_PROT_DURATION = 0xb4 NL80211_ATTR_MAX_CSA_COUNTERS = 0xce NL80211_ATTR_MAX_MATCH_SETS = 0x85 @@ -5517,7 +5519,7 @@ const ( NL80211_MNTR_FLAG_CONTROL = 0x3 NL80211_MNTR_FLAG_COOK_FRAMES = 0x5 NL80211_MNTR_FLAG_FCSFAIL = 0x1 - NL80211_MNTR_FLAG_MAX = 0x6 + NL80211_MNTR_FLAG_MAX = 0x7 NL80211_MNTR_FLAG_OTHER_BSS = 0x4 NL80211_MNTR_FLAG_PLCPFAIL = 0x2 NL80211_MPATH_FLAG_ACTIVE = 0x1 @@ -6172,3 +6174,5 @@ type SockDiagReq struct { Family uint8 Protocol uint8 } + +const RTM_NEWNVLAN = 0x70 diff --git a/source/vendor/golang.org/x/sys/windows/dll_windows.go b/source/vendor/golang.org/x/sys/windows/dll_windows.go index 4e613cf6335ceaaaf3075e177938ef11688461a4..3ca814f54d44eb100e254cebd949d31f0fe22b59 100644 --- a/source/vendor/golang.org/x/sys/windows/dll_windows.go +++ b/source/vendor/golang.org/x/sys/windows/dll_windows.go @@ -43,8 +43,8 @@ type DLL struct { // LoadDLL loads DLL file into memory. // // Warning: using LoadDLL without an absolute path name is subject to -// DLL preloading attacks. To safely load a system DLL, use LazyDLL -// with System set to true, or use LoadLibraryEx directly. +// DLL preloading attacks. To safely load a system DLL, use [NewLazySystemDLL], +// or use [LoadLibraryEx] directly. func LoadDLL(name string) (dll *DLL, err error) { namep, err := UTF16PtrFromString(name) if err != nil { @@ -271,6 +271,9 @@ func (d *LazyDLL) NewProc(name string) *LazyProc { } // NewLazyDLL creates new LazyDLL associated with DLL file. +// +// Warning: using NewLazyDLL without an absolute path name is subject to +// DLL preloading attacks. To safely load a system DLL, use [NewLazySystemDLL]. func NewLazyDLL(name string) *LazyDLL { return &LazyDLL{Name: name} } @@ -410,7 +413,3 @@ func loadLibraryEx(name string, system bool) (*DLL, error) { } return &DLL{Name: name, Handle: h}, nil } - -type errString string - -func (s errString) Error() string { return string(s) } diff --git a/source/vendor/golang.org/x/sys/windows/syscall_windows.go b/source/vendor/golang.org/x/sys/windows/syscall_windows.go index 4510bfc3f5c66ac3590f72621562dfd95d4c00ad..4a32543868500f5403404d54de8f9f5f827e6e18 100644 --- a/source/vendor/golang.org/x/sys/windows/syscall_windows.go +++ b/source/vendor/golang.org/x/sys/windows/syscall_windows.go @@ -168,6 +168,8 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys CreateNamedPipe(name *uint16, flags uint32, pipeMode uint32, maxInstances uint32, outSize uint32, inSize uint32, defaultTimeout uint32, sa *SecurityAttributes) (handle Handle, err error) [failretval==InvalidHandle] = CreateNamedPipeW //sys ConnectNamedPipe(pipe Handle, overlapped *Overlapped) (err error) //sys DisconnectNamedPipe(pipe Handle) (err error) +//sys GetNamedPipeClientProcessId(pipe Handle, clientProcessID *uint32) (err error) +//sys GetNamedPipeServerProcessId(pipe Handle, serverProcessID *uint32) (err error) //sys GetNamedPipeInfo(pipe Handle, flags *uint32, outSize *uint32, inSize *uint32, maxInstances *uint32) (err error) //sys GetNamedPipeHandleState(pipe Handle, state *uint32, curInstances *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32, userName *uint16, maxUserNameSize uint32) (err error) = GetNamedPipeHandleStateW //sys SetNamedPipeHandleState(pipe Handle, state *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32) (err error) = SetNamedPipeHandleState diff --git a/source/vendor/golang.org/x/sys/windows/types_windows.go b/source/vendor/golang.org/x/sys/windows/types_windows.go index 51311e205ff00c51ccd0193d77cfa0b0b58971ac..9d138de5fed63ccdc4435228ec96a68c0037bd8c 100644 --- a/source/vendor/golang.org/x/sys/windows/types_windows.go +++ b/source/vendor/golang.org/x/sys/windows/types_windows.go @@ -176,6 +176,7 @@ const ( WAIT_FAILED = 0xFFFFFFFF // Access rights for process. + PROCESS_ALL_ACCESS = 0xFFFF PROCESS_CREATE_PROCESS = 0x0080 PROCESS_CREATE_THREAD = 0x0002 PROCESS_DUP_HANDLE = 0x0040 diff --git a/source/vendor/golang.org/x/sys/windows/zsyscall_windows.go b/source/vendor/golang.org/x/sys/windows/zsyscall_windows.go index 6f5252880ceed90acdca149a1ec0dbc10cff8cd7..01c0716c2c4e839cc1a0466642204f4e73b0236f 100644 --- a/source/vendor/golang.org/x/sys/windows/zsyscall_windows.go +++ b/source/vendor/golang.org/x/sys/windows/zsyscall_windows.go @@ -280,8 +280,10 @@ var ( procGetMaximumProcessorCount = modkernel32.NewProc("GetMaximumProcessorCount") procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW") procGetModuleHandleExW = modkernel32.NewProc("GetModuleHandleExW") + procGetNamedPipeClientProcessId = modkernel32.NewProc("GetNamedPipeClientProcessId") procGetNamedPipeHandleStateW = modkernel32.NewProc("GetNamedPipeHandleStateW") procGetNamedPipeInfo = modkernel32.NewProc("GetNamedPipeInfo") + procGetNamedPipeServerProcessId = modkernel32.NewProc("GetNamedPipeServerProcessId") procGetOverlappedResult = modkernel32.NewProc("GetOverlappedResult") procGetPriorityClass = modkernel32.NewProc("GetPriorityClass") procGetProcAddress = modkernel32.NewProc("GetProcAddress") @@ -1612,7 +1614,7 @@ func DwmSetWindowAttribute(hwnd HWND, attribute uint32, value unsafe.Pointer, si } func CancelMibChangeNotify2(notificationHandle Handle) (errcode error) { - r0, _, _ := syscall.SyscallN(procCancelMibChangeNotify2.Addr(), uintptr(notificationHandle)) + r0, _, _ := syscall.Syscall(procCancelMibChangeNotify2.Addr(), 1, uintptr(notificationHandle), 0, 0) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1652,7 +1654,7 @@ func GetIfEntry(pIfRow *MibIfRow) (errcode error) { } func GetIfEntry2Ex(level uint32, row *MibIfRow2) (errcode error) { - r0, _, _ := syscall.SyscallN(procGetIfEntry2Ex.Addr(), uintptr(level), uintptr(unsafe.Pointer(row))) + r0, _, _ := syscall.Syscall(procGetIfEntry2Ex.Addr(), 2, uintptr(level), uintptr(unsafe.Pointer(row)), 0) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1660,7 +1662,7 @@ func GetIfEntry2Ex(level uint32, row *MibIfRow2) (errcode error) { } func GetUnicastIpAddressEntry(row *MibUnicastIpAddressRow) (errcode error) { - r0, _, _ := syscall.SyscallN(procGetUnicastIpAddressEntry.Addr(), uintptr(unsafe.Pointer(row))) + r0, _, _ := syscall.Syscall(procGetUnicastIpAddressEntry.Addr(), 1, uintptr(unsafe.Pointer(row)), 0, 0) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1672,7 +1674,7 @@ func NotifyIpInterfaceChange(family uint16, callback uintptr, callerContext unsa if initialNotification { _p0 = 1 } - r0, _, _ := syscall.SyscallN(procNotifyIpInterfaceChange.Addr(), uintptr(family), uintptr(callback), uintptr(callerContext), uintptr(_p0), uintptr(unsafe.Pointer(notificationHandle))) + r0, _, _ := syscall.Syscall6(procNotifyIpInterfaceChange.Addr(), 5, uintptr(family), uintptr(callback), uintptr(callerContext), uintptr(_p0), uintptr(unsafe.Pointer(notificationHandle)), 0) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1684,7 +1686,7 @@ func NotifyUnicastIpAddressChange(family uint16, callback uintptr, callerContext if initialNotification { _p0 = 1 } - r0, _, _ := syscall.SyscallN(procNotifyUnicastIpAddressChange.Addr(), uintptr(family), uintptr(callback), uintptr(callerContext), uintptr(_p0), uintptr(unsafe.Pointer(notificationHandle))) + r0, _, _ := syscall.Syscall6(procNotifyUnicastIpAddressChange.Addr(), 5, uintptr(family), uintptr(callback), uintptr(callerContext), uintptr(_p0), uintptr(unsafe.Pointer(notificationHandle)), 0) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -2446,6 +2448,14 @@ func GetModuleHandleEx(flags uint32, moduleName *uint16, module *Handle) (err er return } +func GetNamedPipeClientProcessId(pipe Handle, clientProcessID *uint32) (err error) { + r1, _, e1 := syscall.Syscall(procGetNamedPipeClientProcessId.Addr(), 2, uintptr(pipe), uintptr(unsafe.Pointer(clientProcessID)), 0) + if r1 == 0 { + err = errnoErr(e1) + } + return +} + func GetNamedPipeHandleState(pipe Handle, state *uint32, curInstances *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32, userName *uint16, maxUserNameSize uint32) (err error) { r1, _, e1 := syscall.Syscall9(procGetNamedPipeHandleStateW.Addr(), 7, uintptr(pipe), uintptr(unsafe.Pointer(state)), uintptr(unsafe.Pointer(curInstances)), uintptr(unsafe.Pointer(maxCollectionCount)), uintptr(unsafe.Pointer(collectDataTimeout)), uintptr(unsafe.Pointer(userName)), uintptr(maxUserNameSize), 0, 0) if r1 == 0 { @@ -2462,6 +2472,14 @@ func GetNamedPipeInfo(pipe Handle, flags *uint32, outSize *uint32, inSize *uint3 return } +func GetNamedPipeServerProcessId(pipe Handle, serverProcessID *uint32) (err error) { + r1, _, e1 := syscall.Syscall(procGetNamedPipeServerProcessId.Addr(), 2, uintptr(pipe), uintptr(unsafe.Pointer(serverProcessID)), 0) + if r1 == 0 { + err = errnoErr(e1) + } + return +} + func GetOverlappedResult(handle Handle, overlapped *Overlapped, done *uint32, wait bool) (err error) { var _p0 uint32 if wait { diff --git a/source/vendor/modules.txt b/source/vendor/modules.txt index 05f026fb5a38634990c62ea2ae2ea0027eeff58e..52249dc6cff69211c2e86040d8f9ea546eb7f513 100644 --- a/source/vendor/modules.txt +++ b/source/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/andybalholm/cascadia v1.3.2 +# github.com/andybalholm/cascadia v1.3.3 ## explicit; go 1.16 github.com/andybalholm/cascadia # github.com/aymanbagabas/go-osc52/v2 v2.0.1 @@ -10,11 +10,12 @@ github.com/charmbracelet/lipgloss # github.com/charmbracelet/log v0.4.0 ## explicit; go 1.19 github.com/charmbracelet/log -# github.com/charmbracelet/x/ansi v0.4.5 +# github.com/charmbracelet/x/ansi v0.8.0 ## explicit; go 1.18 github.com/charmbracelet/x/ansi +github.com/charmbracelet/x/ansi/kitty github.com/charmbracelet/x/ansi/parser -# github.com/evanw/esbuild v0.24.0 +# github.com/evanw/esbuild v0.24.2 ## explicit; go 1.13 github.com/evanw/esbuild/internal/api_helpers github.com/evanw/esbuild/internal/ast @@ -61,7 +62,7 @@ github.com/muesli/termenv # github.com/rivo/uniseg v0.4.7 ## explicit; go 1.18 github.com/rivo/uniseg -# github.com/tdewolff/parse/v2 v2.7.19 +# github.com/tdewolff/parse/v2 v2.7.20 ## explicit; go 1.13 github.com/tdewolff/parse/v2 github.com/tdewolff/parse/v2/buffer @@ -81,22 +82,21 @@ gitlab.schukai.com/oss/libraries/go/utilities/data.git # gitlab.schukai.com/oss/libraries/go/utilities/pathfinder.git v0.9.5 ## explicit; go 1.21 gitlab.schukai.com/oss/libraries/go/utilities/pathfinder.git -# golang.org/x/crypto v0.29.0 +# golang.org/x/crypto v0.32.0 ## explicit; go 1.20 golang.org/x/crypto/bcrypt golang.org/x/crypto/blowfish -# golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f +# golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c ## explicit; go 1.22.0 -golang.org/x/exp/constraints golang.org/x/exp/slices golang.org/x/exp/slog golang.org/x/exp/slog/internal golang.org/x/exp/slog/internal/buffer -# golang.org/x/net v0.31.0 +# golang.org/x/net v0.34.0 ## explicit; go 1.18 golang.org/x/net/html golang.org/x/net/html/atom -# golang.org/x/sys v0.27.0 +# golang.org/x/sys v0.30.0 ## explicit; go 1.18 golang.org/x/sys/unix golang.org/x/sys/windows