[
  {
    "path": ".dockerignore",
    "content": "**\n\n!config\n!formatter\n!*.go\n!go.mod\n!sample-config.toml\n!docker-entrypoint.sh"
  },
  {
    "path": ".gitignore",
    "content": "wuzz\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: go\ngo:\n  - 1.12.x #Update go version\n  - tip\nos:\n  - linux\n  # remove osx, getting vm from travis is extremely slow\n  # - osx\n  \narch:\n  - amd64\n  - ppc64le\nenv:\n  - \"PATH=/home/travis/gopath/bin:$PATH\"\nscript:\n  - test -z \"$(go get -a)\"\n  - test -z \"$(gofmt -l ./)\"\n  - test -z \"$(go vet -v ./...)\"\n  - go test ./...\n  - go build\n# after_success:\n#   # Publish as pre-release if it isn't a pull request\n#   - 'if [ \"$TRAVIS_PULL_REQUEST\" = \"false\" ]; then go get github.com/mitchellh/gox && go get github.com/tcnksm/ghr; fi'\n#   - 'if [ \"$TRAVIS_PULL_REQUEST\" = \"false\" ]; then gox -output \"dist/{{.Dir}}_{{.OS}}_{{.Arch}}\" && ghr --username $GITHUB_USERNAME --token $GITHUB_TOKEN --replace --prerelease --debug pre-release dist/; fi'\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "## 0.5.0 2020.01.19\n\n - Added context specific search for HTML (goquery)\n - Request data displayed in request history\n - Fixed JSON indentation\n - Redirect toggle command Added\n - Multiple minor bug fixes\n\n## 0.4.0 2017.08.21\n\n - Save/load requests (`-f`/`--file` flags for loading)\n - Multipart form handling (`-F`/`--form` flags)\n - Edit window content in external editor\n - Colorized html output\n - Context specific search (github.com/tidwall/gjson for JSON)\n - More consistency with cURL API (`--data-urlencode` flag added)\n - Update to the latest `gocui` ui library\n\n\n## 0.3.0 2017.03.07\n\n- Request header autocompletion\n- Configurable statusline\n- JSON requests with `-j`/`--json` flags\n- Allow insecure HTTPS requests (`-k`/`--insecure` flags)\n- Socks proxy support (`-x`/`--proxy` flags)\n- Disable following redirects (`-R`/`--disable-redirects` flags)\n- Enhanced TLS support (`-T`/`--tls`, `-1`/`--tlsv1`, `--tlsv1.0`, `--tlsv1.1`, `--tlsv1.2` flags)\n- Commands for line and word deletion\n- Home/end navigation fix\n\n## 0.2.0 2017.02.18\n\n- Config file support with configurable keybindings\n- Help popup (F1 key)\n- Ignore invalid SSL certs with the --insecure flag\n- PATCH request support\n- Allow JSON request body (--data-binary flag)\n- Colorized JSON response\n- Parameter encoding bugfix\n- Multiple UI bugfixes\n\n## 0.1.0 2017.02.11\n\nInitial release\n"
  },
  {
    "path": "Dockerfile",
    "content": "FROM alpine:3.12 AS permissions-giver\n\n# Make sure docker-entrypoint.sh is executable, regardless of the build host.\nWORKDIR /out\nCOPY docker-entrypoint.sh .\nRUN chmod +x docker-entrypoint.sh\n\nFROM golang:1.14-alpine3.12 AS builder\n\n# Build wuzz\nWORKDIR /out\nCOPY . .\nRUN go build .\n\nFROM alpine:3.12 AS organizer\n\n# Prepare executables\nWORKDIR /out\nCOPY --from=builder /out/wuzz .\nCOPY --from=permissions-giver /out/docker-entrypoint.sh .\n\nFROM alpine:3.12 AS runner\nWORKDIR /wuzz\nCOPY --from=organizer /out /usr/local/bin\nENTRYPOINT [ \"docker-entrypoint.sh\" ]"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU AFFERO GENERAL PUBLIC LICENSE\n                       Version 3, 19 November 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU Affero General Public License is a free, copyleft license for\nsoftware and other kinds of works, specifically designed to ensure\ncooperation with the community in the case of network server software.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nour General Public Licenses are intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  Developers that use our General Public Licenses protect your rights\nwith two steps: (1) assert copyright on the software, and (2) offer\nyou this License which gives you legal permission to copy, distribute\nand/or modify the software.\n\n  A secondary benefit of defending all users' freedom is that\nimprovements made in alternate versions of the program, if they\nreceive widespread use, become available for other developers to\nincorporate.  Many developers of free software are heartened and\nencouraged by the resulting cooperation.  However, in the case of\nsoftware used on network servers, this result may fail to come about.\nThe GNU General Public License permits making a modified version and\nletting the public access it on a server without ever releasing its\nsource code to the public.\n\n  The GNU Affero General Public License is designed specifically to\nensure that, in such cases, the modified source code becomes available\nto the community.  It requires the operator of a network server to\nprovide the source code of the modified version running there to the\nusers of that server.  Therefore, public use of a modified version, on\na publicly accessible server, gives the public access to the source\ncode of the modified version.\n\n  An older license, called the Affero General Public License and\npublished by Affero, was designed to accomplish similar goals.  This is\na different license, not a version of the Affero GPL, but Affero has\nreleased a new version of the Affero GPL which permits relicensing under\nthis license.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU Affero General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Remote Network Interaction; Use with the GNU General Public License.\n\n  Notwithstanding any other provision of this License, if you modify the\nProgram, your modified version must prominently offer all users\ninteracting with it remotely through a computer network (if your version\nsupports such interaction) an opportunity to receive the Corresponding\nSource of your version by providing access to the Corresponding Source\nfrom a network server at no charge, through some standard or customary\nmeans of facilitating copying of software.  This Corresponding Source\nshall include the Corresponding Source for any work covered by version 3\nof the GNU General Public License that is incorporated pursuant to the\nfollowing paragraph.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the work with which it is combined will remain governed by version\n3 of the GNU General Public License.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU Affero General Public License from time to time.  Such new versions\nwill be similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU Affero General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU Affero General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU Affero General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU Affero General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU Affero General Public License for more details.\n\n    You should have received a copy of the GNU Affero General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If your software can interact with users remotely through a computer\nnetwork, you should also make sure that it provides a way for users to\nget its source.  For example, if your program is a web application, its\ninterface could display a \"Source\" link that leads users to an archive\nof the code.  There are many ways you could offer source, and different\nsolutions will be better for different programs; see section 13 for the\nspecific requirements.\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU AGPL, see\n<http://www.gnu.org/licenses/>.\n"
  },
  {
    "path": "README.md",
    "content": "# wuzz\n\nInteractive cli tool for HTTP inspection.\n\nWuzz command line arguments are similar to cURL's arguments,\nso it can be used to inspect/modify requests copied from the\nbrowser's network inspector with the \"copy as cURL\" feature.\n\n![wuzz screencast](docs/images/screencast.gif)\n\n\n## Installation and usage\n\n### GO\n\n```\n$ go get github.com/asciimoo/wuzz\n$ \"$GOPATH/bin/wuzz\" --help\n```\n\nNote: golang >= 1.10 required.\n\n[Binary releases](https://github.com/asciimoo/wuzz/releases) are also available.\n\n### Apt\n\n```\n$ apt install wuzz\n```\n\n### Apk\n\n```\n$ apk add wuzz\n```\n\n### Scoop\n\n```\n$ scoop bucket add main\n$ scoop install main/wuzz\n```\n\n### X-CMD\n\n```\n$ x env use wuzz\n```\n\n### Nix\n\n```\n$ nix-shell -p wuzz\n```\n\n\n### Configuration\n\nIt is possible to override default settings in a configuration file.\nThe default location is `\"$XDG_CONFIG_HOME/wuzz/config.toml\"`on linux\nand `~/.wuzz/config.toml` on other platforms.\n`-c`/`--config` switches can be used to load config file from custom location.\n\nSee [example configuration](sample-config.toml) for more details.\n\n\n### Commands\n\nKeybinding                              | Description\n----------------------------------------|---------------------------------------\n<kbd>F1</kbd>                           | Display help\n<kbd>Ctrl+R</kbd>                       | Send request\n<kbd>Ret</kbd>                          | Send request (only from URL view)\n<kbd>Ctrl+S</kbd>                       | Save response\n<kbd>Ctrl+E</kbd>                       | Save request\n<kbd>Ctrl+F</kbd>                       | Load request\n<kbd>Ctrl+C</kbd>                       | Quit\n<kbd>Ctrl+K</kbd>, <kbd>Shift+Tab</kbd> | Previous view\n<kbd>Ctlr+J</kbd>, <kbd>Tab</kbd>       | Next view\n<kbd>Ctlr+T</kbd>                       | Toggle context specific search\n<kbd>Ctrl+L</kbd>                       | Clear all tabs to default\n<kbd>Alt+H</kbd>                        | Toggle history\n<kbd>Down</kbd>                         | Move down one view line\n<kbd>Up</kbd>                           | Move up one view line\n<kbd>Page down</kbd>                    | Move down one view page\n<kbd>Page up</kbd>                      | Move up one view page\n<kbd>F2</kbd>                           | Jump to URL\n<kbd>F3</kbd>                           | Jump to query parameters\n<kbd>F4</kbd>                           | Jump to HTTP method\n<kbd>F5</kbd>                           | Jump to request body\n<kbd>F6</kbd>                           | Jump to headers\n<kbd>F7</kbd>                           | Jump to search\n<kbd>F8</kbd>                           | Jump to response headers\n<kbd>F9</kbd>                           | Jump to response body\n<kbd>F11</kbd>                          | Redirects Restriction Mode\n\n\n### Context specific search\n\nWuzz accepts regular expressions by default to filter response body.\nCustom query syntax can be toggled by pressing <kbd>Ctrl+T</kbd>.\nThe following formats have context specific search syntax:\n\nResponse format  | Query syntax\n-----------------|----------------------------------------\nHTML             | https://github.com/PuerkitoBio/goquery\nJSON             | https://github.com/tidwall/gjson\n\n\n## TODO\n\n* Better navigation\n* Autocompletion\n* Tests\n\n\n## Bugs / Suggestions\n\nBugs or suggestions? Visit the [issue tracker](https://github.com/asciimoo/wuzz/issues)\nor join `#wuzz` on freenode\n"
  },
  {
    "path": "_config.yml",
    "content": "theme: jekyll-theme-cayman"
  },
  {
    "path": "commands.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"os/exec\"\n\t\"strings\"\n\t\"unicode\"\n\n\t\"github.com/awesome-gocui/gocui\"\n)\n\ntype CommandFunc func(*gocui.Gui, *gocui.View) error\n\nvar COMMANDS map[string]func(string, *App) CommandFunc = map[string]func(string, *App) CommandFunc{\n\t\"submit\": func(_ string, a *App) CommandFunc {\n\t\treturn a.SubmitRequest\n\t},\n\t\"saveResponse\": func(_ string, a *App) CommandFunc {\n\t\treturn func(g *gocui.Gui, _ *gocui.View) error {\n\t\t\treturn a.OpenSaveDialog(VIEW_TITLES[SAVE_RESPONSE_DIALOG_VIEW], g,\n\t\t\t\tfunc(g *gocui.Gui, _ *gocui.View) error {\n\t\t\t\t\tsaveLocation := getViewValue(g, SAVE_DIALOG_VIEW)\n\n\t\t\t\t\tif len(a.history) == 0 {\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t}\n\t\t\t\t\treq := a.history[a.historyIndex]\n\t\t\t\t\tif req.RawResponseBody == nil {\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t}\n\n\t\t\t\t\terr := ioutil.WriteFile(saveLocation, req.RawResponseBody, 0644)\n\n\t\t\t\t\tvar saveResult string\n\t\t\t\t\tif err == nil {\n\t\t\t\t\t\tsaveResult = \"Response saved successfully.\"\n\t\t\t\t\t} else {\n\t\t\t\t\t\tsaveResult = \"Error saving response: \" + err.Error()\n\t\t\t\t\t}\n\t\t\t\t\tviewErr := a.OpenSaveResultView(saveResult, g)\n\t\t\t\t\treturn viewErr\n\t\t\t\t})\n\t\t}\n\t},\n\t\"loadRequest\": func(_ string, a *App) CommandFunc {\n\t\treturn func(g *gocui.Gui, _ *gocui.View) error {\n\t\t\treturn a.OpenSaveDialog(VIEW_TITLES[LOAD_REQUEST_DIALOG_VIEW], g,\n\t\t\t\tfunc(g *gocui.Gui, _ *gocui.View) error {\n\t\t\t\t\tdefer a.closePopup(g, SAVE_DIALOG_VIEW)\n\t\t\t\t\tloadLocation := getViewValue(g, SAVE_DIALOG_VIEW)\n\t\t\t\t\treturn a.LoadRequest(g, loadLocation)\n\t\t\t\t})\n\t\t}\n\t},\n\t\"saveRequest\": func(_ string, a *App) CommandFunc {\n\t\treturn a.SaveRequest\n\t},\n\t\"history\": func(_ string, a *App) CommandFunc {\n\t\treturn a.ToggleHistory\n\t},\n\t\"quit\": func(_ string, _ *App) CommandFunc {\n\t\treturn quit\n\t},\n\t\"focus\": func(args string, a *App) CommandFunc {\n\t\treturn func(g *gocui.Gui, _ *gocui.View) error {\n\t\t\treturn a.setViewByName(g, args)\n\t\t}\n\t},\n\t\"nextView\": func(_ string, a *App) CommandFunc {\n\t\treturn a.NextView\n\t},\n\t\"prevView\": func(_ string, a *App) CommandFunc {\n\t\treturn a.PrevView\n\t},\n\t\"scrollDown\": func(_ string, _ *App) CommandFunc {\n\t\treturn scrollViewDown\n\t},\n\t\"scrollUp\": func(_ string, _ *App) CommandFunc {\n\t\treturn scrollViewUp\n\t},\n\t\"pageDown\": func(_ string, _ *App) CommandFunc {\n\t\treturn pageDown\n\t},\n\t\"pageUp\": func(_ string, _ *App) CommandFunc {\n\t\treturn pageUp\n\t},\n\t\"deleteLine\": func(_ string, _ *App) CommandFunc {\n\t\treturn deleteLine\n\t},\n\t\"deleteWord\": func(_ string, _ *App) CommandFunc {\n\t\treturn deleteWord\n\t},\n\t\"openEditor\": func(_ string, a *App) CommandFunc {\n\t\treturn func(g *gocui.Gui, v *gocui.View) error {\n\t\t\treturn openEditor(g, v, a.config.General.Editor)\n\t\t}\n\t},\n\t\"toggleContextSpecificSearch\": func(_ string, a *App) CommandFunc {\n\t\treturn func(g *gocui.Gui, _ *gocui.View) error {\n\t\t\ta.config.General.ContextSpecificSearch = !a.config.General.ContextSpecificSearch\n\t\t\ta.PrintBody(g)\n\t\t\treturn nil\n\t\t}\n\t},\n\t\"clearHistory\": func(_ string, a *App) CommandFunc {\n\t\treturn func(g *gocui.Gui, _ *gocui.View) error {\n\t\t\ta.history = make([]*Request, 0, 31)\n\t\t\ta.historyIndex = 0\n\t\t\ta.Layout(g)\n\t\t\treturn nil\n\t\t}\n\t},\n\t\"redirectRestriction\": func(_ string, a *App) CommandFunc {\n\t\treturn func(g *gocui.Gui, _ *gocui.View) error {\n\t\t\ta.config.General.FollowRedirects = !a.config.General.FollowRedirects\n\t\t\treturn nil\n\t\t}\n\t},\n\t\"clearTabs\": func(_ string, a *App) CommandFunc {\n\t\treturn func(g *gocui.Gui, _ *gocui.View) error {\n\t\t\tif a.currentPopup != \"\" {\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\ta.restoreRequest(g, 0, true)\n\t\t\tg.SetCurrentView(URL_VIEW)\n\t\t\treturn nil\n\t\t}\n\t},\n}\n\nfunc scrollView(v *gocui.View, dy int) error {\n\tv.Autoscroll = false\n\tox, oy := v.Origin()\n\tif oy+dy < 0 {\n\t\tdy = -oy\n\t}\n\tif _, err := v.Line(dy); dy > 0 && err != nil {\n\t\tdy = 0\n\t}\n\tv.SetOrigin(ox, oy+dy)\n\treturn nil\n}\n\nfunc scrollViewUp(_ *gocui.Gui, v *gocui.View) error {\n\treturn scrollView(v, -1)\n}\n\nfunc scrollViewDown(_ *gocui.Gui, v *gocui.View) error {\n\treturn scrollView(v, 1)\n}\n\nfunc pageUp(_ *gocui.Gui, v *gocui.View) error {\n\t_, height := v.Size()\n\tscrollView(v, -height*2/3)\n\treturn nil\n}\n\nfunc pageDown(_ *gocui.Gui, v *gocui.View) error {\n\t_, height := v.Size()\n\tscrollView(v, height*2/3)\n\treturn nil\n}\n\nfunc deleteLine(_ *gocui.Gui, v *gocui.View) error {\n\tif !v.Editable {\n\t\treturn nil\n\t}\n\t_, curY := v.Cursor()\n\t_, oY := v.Origin()\n\tcurrentLine := curY + oY\n\tviewLines := strings.Split(strings.TrimSpace(v.Buffer()), \"\\n\")\n\tif currentLine >= len(viewLines) {\n\t\treturn nil\n\t}\n\tv.Clear()\n\tif currentLine > 0 {\n\t\tfmt.Fprintln(v, strings.Join(viewLines[:currentLine], \"\\n\"))\n\t}\n\tfmt.Fprint(v, strings.Join(viewLines[currentLine+1:], \"\\n\"))\n\tv.SetCursor(0, currentLine)\n\tv.SetOrigin(0, oY)\n\treturn nil\n}\n\nfunc deleteWord(_ *gocui.Gui, v *gocui.View) error {\n\tcX, cY := v.Cursor()\n\toX, _ := v.Origin()\n\tcX = cX - 1 + oX\n\tline, err := v.Line(cY)\n\tif err != nil || line == \"\" || cX < 0 {\n\t\treturn nil\n\t}\n\tif cX >= len(line) {\n\t\tcX = len(line) - 1\n\t}\n\torigCharCateg := getCharCategory(rune(line[cX]))\n\tv.EditDelete(true)\n\tcX -= 1\n\tfor cX >= 0 {\n\t\tc := rune(line[cX])\n\t\tif origCharCateg != getCharCategory(c) {\n\t\t\tbreak\n\t\t}\n\t\tv.EditDelete(true)\n\t\tcX -= 1\n\t}\n\treturn nil\n}\n\nfunc getCharCategory(chr rune) int {\n\tswitch {\n\tcase unicode.IsDigit(chr):\n\t\treturn 0\n\tcase unicode.IsLetter(chr):\n\t\treturn 1\n\tcase unicode.IsSpace(chr):\n\t\treturn 2\n\tcase unicode.IsPunct(chr):\n\t\treturn 3\n\t}\n\treturn int(chr)\n}\n\nfunc quit(g *gocui.Gui, v *gocui.View) error {\n\treturn gocui.ErrQuit\n}\n\nfunc openEditor(g *gocui.Gui, v *gocui.View, editor string) error {\n\tfile, err := ioutil.TempFile(os.TempDir(), \"wuzz-\")\n\tif err != nil {\n\t\treturn nil\n\t}\n\tdefer os.Remove(file.Name())\n\n\tval := getViewValue(g, v.Name())\n\tif val != \"\" {\n\t\tfmt.Fprint(file, val)\n\t}\n\tfile.Close()\n\n\tinfo, err := os.Stat(file.Name())\n\tif err != nil {\n\t\treturn nil\n\t}\n\n\tgocui.Suspend()\n\n\tcmd := exec.Command(editor, file.Name())\n\tcmd.Stdout = os.Stdout\n\tcmd.Stdin = os.Stdin\n\tcmd.Stderr = os.Stderr\n\terr = cmd.Run()\n\n\tgocui.Resume()\n\n\t// sync termbox to reset console settings\n\t// this is required because the external editor can modify the console\n\tdefer g.Update(func(gui *gocui.Gui) error {\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\trv, _ := g.View(RESPONSE_BODY_VIEW)\n\t\trv.Clear()\n\t\tfmt.Fprintf(rv, \"Editor open error: %v\", err)\n\t\treturn nil\n\t}\n\n\tnewInfo, err := os.Stat(file.Name())\n\tif err != nil || newInfo.ModTime().Before(info.ModTime()) {\n\t\treturn nil\n\t}\n\n\tnewVal, err := ioutil.ReadFile(file.Name())\n\tif err != nil {\n\t\treturn nil\n\t}\n\n\tv.SetCursor(0, 0)\n\tv.SetOrigin(0, 0)\n\tv.Clear()\n\tfmt.Fprint(v, strings.TrimSpace(string(newVal)))\n\n\treturn nil\n}\n"
  },
  {
    "path": "config/config.go",
    "content": "package config\n\nimport (\n\t\"errors\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"runtime\"\n\t\"time\"\n\n\t\"github.com/BurntSushi/toml\"\n\t\"github.com/mitchellh/go-homedir\"\n)\n\nvar ContentTypes = map[string]string{\n\t\"json\":      \"application/json\",\n\t\"form\":      \"application/x-www-form-urlencoded\",\n\t\"multipart\": \"multipart/form-data\",\n}\n\n// Duration is used to automatically unmarshal timeout strings to\n// time.Duration values\ntype Duration struct {\n\ttime.Duration\n}\n\nfunc (d *Duration) UnmarshalText(text []byte) error {\n\tvar err error\n\td.Duration, err = time.ParseDuration(string(text))\n\treturn err\n}\n\ntype Config struct {\n\tGeneral GeneralOptions\n\tKeys    map[string]map[string]string\n}\n\ntype GeneralOptions struct {\n\tContextSpecificSearch  bool\n\tDefaultURLScheme       string\n\tEditor                 string\n\tFollowRedirects        bool\n\tFormatJSON             bool\n\tInsecure               bool\n\tPreserveScrollPosition bool\n\tStatusLine             string\n\tTLSVersionMax          uint16\n\tTLSVersionMin          uint16\n\tTimeout                Duration\n}\n\nvar defaultTimeoutDuration, _ = time.ParseDuration(\"1m\")\n\nvar DefaultKeys = map[string]map[string]string{\n\t\"global\": {\n\t\t\"CtrlR\": \"submit\",\n\t\t\"CtrlC\": \"quit\",\n\t\t\"CtrlS\": \"saveResponse\",\n\t\t\"CtrlF\": \"loadRequest\",\n\t\t\"CtrlE\": \"saveRequest\",\n\t\t\"CtrlD\": \"deleteLine\",\n\t\t\"CtrlW\": \"deleteWord\",\n\t\t\"CtrlO\": \"openEditor\",\n\t\t\"CtrlT\": \"toggleContextSpecificSearch\",\n\t\t\"CtrlX\": \"clearHistory\",\n\t\t\"CtrlL\": \"clearTabs\",\n\t\t\"Tab\":   \"nextView\",\n\t\t\"CtrlJ\": \"nextView\",\n\t\t\"CtrlK\": \"prevView\",\n\t\t\"AltH\":  \"history\",\n\t\t\"F2\":    \"focus url\",\n\t\t\"F3\":    \"focus get\",\n\t\t\"F4\":    \"focus method\",\n\t\t\"F5\":    \"focus data\",\n\t\t\"F6\":    \"focus headers\",\n\t\t\"F7\":    \"focus search\",\n\t\t\"F8\":    \"focus response-headers\",\n\t\t\"F9\":    \"focus response-body\",\n\t\t\"F11\":   \"redirectRestriction\",\n\t},\n\t\"url\": {\n\t\t\"Enter\": \"submit\",\n\t},\n\t\"response-headers\": {\n\t\t\"ArrowUp\":   \"scrollUp\",\n\t\t\"ArrowDown\": \"scrollDown\",\n\t\t\"PageUp\":    \"pageUp\",\n\t\t\"PageDown\":  \"pageDown\",\n\t},\n\t\"response-body\": {\n\t\t\"ArrowUp\":   \"scrollUp\",\n\t\t\"ArrowDown\": \"scrollDown\",\n\t\t\"PageUp\":    \"pageUp\",\n\t\t\"PageDown\":  \"pageDown\",\n\t},\n\t\"help\": {\n\t\t\"ArrowUp\":   \"scrollUp\",\n\t\t\"ArrowDown\": \"scrollDown\",\n\t\t\"PageUp\":    \"pageUp\",\n\t\t\"PageDown\":  \"pageDown\",\n\t},\n}\n\nvar DefaultConfig = Config{\n\tGeneral: GeneralOptions{\n\t\tDefaultURLScheme:       \"https\",\n\t\tEditor:                 \"vim\",\n\t\tFollowRedirects:        true,\n\t\tFormatJSON:             true,\n\t\tInsecure:               false,\n\t\tPreserveScrollPosition: true,\n\t\tStatusLine:             \"[wuzz {{.Version}}]{{if .Duration}} [Response time: {{.Duration}}]{{end}} [Request no.: {{.RequestNumber}}/{{.HistorySize}}] [Search type: {{.SearchType}}]{{if .DisableRedirect}} [Redirects Restricted Mode {{.DisableRedirect}}]{{end}}\",\n\t\tTimeout: Duration{\n\t\t\tdefaultTimeoutDuration,\n\t\t},\n\t},\n}\n\nfunc init() {\n\tif os.Getenv(\"EDITOR\") != \"\" {\n\t\tDefaultConfig.General.Editor = os.Getenv(\"EDITOR\")\n\t}\n}\n\nfunc LoadConfig(configFile string) (*Config, error) {\n\tif _, err := os.Stat(configFile); os.IsNotExist(err) {\n\t\treturn nil, errors.New(\"Config file does not exist.\")\n\t} else if err != nil {\n\t\treturn nil, err\n\t}\n\n\tconf := DefaultConfig\n\tif _, err := toml.DecodeFile(configFile, &conf); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif conf.Keys == nil {\n\t\tconf.Keys = DefaultKeys\n\t} else {\n\t\t// copy default keys\n\t\tfor keyCategory, keys := range DefaultKeys {\n\t\t\tconfKeys, found := conf.Keys[keyCategory]\n\t\t\tif found {\n\t\t\t\tfor key, action := range keys {\n\t\t\t\t\tif _, found := confKeys[key]; !found {\n\t\t\t\t\t\tconf.Keys[keyCategory][key] = action\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconf.Keys[keyCategory] = keys\n\t\t\t}\n\t\t}\n\t}\n\n\treturn &conf, nil\n}\n\nfunc GetDefaultConfigLocation() string {\n\tvar configFolderLocation string\n\tswitch runtime.GOOS {\n\tcase \"linux\":\n\t\t// Use the XDG_CONFIG_HOME variable if it is set, otherwise\n\t\t// $HOME/.config/wuzz/config.toml\n\t\txdgConfigHome := os.Getenv(\"XDG_CONFIG_HOME\")\n\t\tif xdgConfigHome != \"\" {\n\t\t\tconfigFolderLocation = xdgConfigHome\n\t\t} else {\n\t\t\tconfigFolderLocation, _ = homedir.Expand(\"~/.config/wuzz/\")\n\t\t}\n\n\tdefault:\n\t\t// On other platforms we just use $HOME/.wuzz\n\t\tconfigFolderLocation, _ = homedir.Expand(\"~/.wuzz/\")\n\t}\n\n\treturn filepath.Join(configFolderLocation, \"config.toml\")\n}\n"
  },
  {
    "path": "docker-entrypoint.sh",
    "content": "#!/bin/sh\nset -e\n\nif [ \"${1#-}\" != \"${1}\" ] || [ -z \"$(command -v \"${1}\")\" ]; then\n  sleep 0.01\n  set -- wuzz \"$@\"\nfi\n\nexec \"$@\""
  },
  {
    "path": "formatter/binary.go",
    "content": "package formatter\n\nimport (\n\t\"encoding/hex\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n)\n\ntype binaryFormatter struct {\n}\n\nfunc (f *binaryFormatter) Format(writer io.Writer, data []byte) error {\n\tfmt.Fprint(writer, hex.Dump(data))\n\treturn nil\n}\n\nfunc (f *binaryFormatter) Title() string {\n\treturn \"[binary]\"\n}\n\nfunc (f *binaryFormatter) Searchable() bool {\n\treturn false\n}\n\nfunc (f *binaryFormatter) Search(q string, body []byte) ([]string, error) {\n\treturn nil, errors.New(\"Cannot perform search on binary content type\")\n}\n"
  },
  {
    "path": "formatter/formatter.go",
    "content": "package formatter\n\nimport (\n\t\"io\"\n\t\"mime\"\n\t\"strings\"\n\n\t\"github.com/asciimoo/wuzz/config\"\n)\n\ntype ResponseFormatter interface {\n\tFormat(writer io.Writer, data []byte) error\n\tTitle() string\n\tSearchable() bool\n\tSearch(string, []byte) ([]string, error)\n}\n\nfunc New(appConfig *config.Config, contentType string) ResponseFormatter {\n\tctype, _, err := mime.ParseMediaType(contentType)\n\tif err == nil && appConfig.General.FormatJSON && (ctype == config.ContentTypes[\"json\"] || strings.HasSuffix(ctype, \"+json\")) {\n\t\treturn &jsonFormatter{}\n\t} else if strings.Contains(contentType, \"text/html\") {\n\t\treturn &htmlFormatter{}\n\t} else if strings.Index(contentType, \"text\") == -1 && strings.Index(contentType, \"application\") == -1 {\n\t\treturn &binaryFormatter{}\n\t} else {\n\t\treturn &TextFormatter{}\n\t}\n}\n"
  },
  {
    "path": "formatter/formatter_test.go",
    "content": "package formatter\n\nimport (\n\t\"bytes\"\n\t\"testing\"\n\n\t\"github.com/asciimoo/wuzz/config\"\n\t\"github.com/nwidger/jsoncolor\"\n\t\"github.com/x86kernel/htmlcolor\"\n)\n\nfunc TestFormat(t *testing.T) {\n\tvar binBuffer bytes.Buffer\n\tNew(configFixture(true), \"octet-stream\").Format(&binBuffer, []byte(\"some binary data\"))\n\tif binBuffer.String() != \"00000000  73 6f 6d 65 20 62 69 6e  61 72 79 20 64 61 74 61  |some binary data|\\n\" {\n\t\tt.Error(\"Expected binary to eq \" + binBuffer.String())\n\t}\n\n\tvar htmlBuffer bytes.Buffer\n\tNew(configFixture(true), \"text/html; charset=utf-8\").Format(&htmlBuffer, []byte(\"<html><span>unfomatted</span></html>\"))\n\tvar htmltargetBuffer bytes.Buffer\n\thtmlcolor.NewFormatter().Format(&htmltargetBuffer, []byte(\"<html><span>unfomatted</span></html>\"))\n\thtmltarget := htmltargetBuffer.String()\n\n\tif htmlBuffer.String() != htmltarget {\n\t\tt.Error(\"Expected html to eq \" + htmlBuffer.String())\n\t}\n\n\tvar jsonEnabledBuffer bytes.Buffer\n\tNew(configFixture(true), \"application/json; charset=utf-8\").Format(&jsonEnabledBuffer, []byte(\"{\\\"json\\\": \\\"some value\\\"}\"))\n\tvar jsontargetBuffer bytes.Buffer\n\tf := jsoncolor.NewFormatter()\n\tf.Indent = \"  \"\n\tf.Format(&jsontargetBuffer, []byte(\"{\\\"json\\\": \\\"some value\\\"}\"))\n\tjsontarget := jsontargetBuffer.String()\n\n\tif jsonEnabledBuffer.String() != jsontarget {\n\t\tt.Error(\"Expected json to eq \\n\" + jsonEnabledBuffer.String() + \"\\nbut not\\n\" + jsontarget)\n\t}\n\n\tvar jsonDisabledBuffer bytes.Buffer\n\tNew(configFixture(false), \"application/json; charset=utf-8\").Format(&jsonDisabledBuffer, []byte(\"{\\\"json\\\": \\\"some value\\\"}\"))\n\tif jsonDisabledBuffer.String() != \"{\\\"json\\\": \\\"some value\\\"}\" {\n\t\tt.Error(\"Expected json to eq \" + jsonDisabledBuffer.String())\n\t}\n\n\tvar textBuffer bytes.Buffer\n\tNew(configFixture(true), \"text/html; charset=utf-8\").Format(&textBuffer, []byte(\"some text\"))\n\tif textBuffer.String() != \"some text\" {\n\t\tt.Error(\"Expected text to eq \" + textBuffer.String())\n\t}\n}\n\nfunc TestTitle(t *testing.T) {\n\t//binary\n\ttitle := New(configFixture(true), \"octet-stream\").Title()\n\tif title != \"[binary]\" {\n\t\tt.Error(\"for octet-stream content type expected title \", title, \"to be [binary]\")\n\t}\n\n\t//html\n\ttitle = New(configFixture(true), \"text/html; charset=utf-8\").Title()\n\tif title != \"[html]\" {\n\t\tt.Error(\"For text/html content type expected title \", title, \" to be [html]\")\n\t}\n\n\t//json\n\ttitle = New(configFixture(true), \"application/json; charset=utf-8\").Title()\n\tif title != \"[json]\" {\n\t\tt.Error(\"For text/html content type expected title \", title, \" to be [json]\")\n\t}\n\n\t//text\n\ttitle = New(configFixture(true), \"text/plain; charset=utf-8\").Title()\n\tif title != \"[text]\" {\n\t\tt.Error(\"For text/html content type expected title \", title, \" to be [text]\")\n\t}\n}\n\nfunc TestSearchable(t *testing.T) {\n\tif New(configFixture(true), \"octet-stream\").Searchable() {\n\t\tt.Error(\"binary file can't be searchable\")\n\t}\n\n\tif !New(configFixture(true), \"text/html\").Searchable() {\n\t\tt.Error(\"text/html should be searchable\")\n\t}\n\n\tif !New(configFixture(true), \"application/json\").Searchable() {\n\t\tt.Error(\"application/json should be searchable\")\n\t}\n\tif !New(configFixture(true), \"text/plain\").Searchable() {\n\t\tt.Error(\"text/plain should be searchable\")\n\t}\n\n}\n\nfunc configFixture(jsonEnabled bool) *config.Config {\n\treturn &config.Config{\n\t\tGeneral: config.GeneralOptions{\n\t\t\tFormatJSON: jsonEnabled,\n\t\t},\n\t}\n}\n"
  },
  {
    "path": "formatter/html.go",
    "content": "package formatter\n\nimport (\n\t\"bytes\"\n\t\"errors\"\n\t\"io\"\n\n\t\"github.com/PuerkitoBio/goquery\"\n\t\"github.com/x86kernel/htmlcolor\"\n)\n\ntype htmlFormatter struct {\n\tparsedBody goquery.Document\n\tTextFormatter\n}\n\nfunc (f *htmlFormatter) Format(writer io.Writer, data []byte) error {\n\thtmlFormatter := htmlcolor.NewFormatter()\n\tbuf := bytes.NewBuffer(make([]byte, 0, len(data)))\n\terr := htmlFormatter.Format(buf, data)\n\n\tif err == io.EOF {\n\t\twriter.Write(buf.Bytes())\n\t\treturn nil\n\t}\n\n\treturn errors.New(\"html formatter error\")\n}\n\nfunc (f *htmlFormatter) Title() string {\n\treturn \"[html]\"\n}\n\nfunc (f *htmlFormatter) Search(q string, body []byte) ([]string, error) {\n\tif q == \"\" {\n\t\tbuf := bytes.NewBuffer(make([]byte, 0, len(body)))\n\t\terr := f.Format(buf, body)\n\t\treturn []string{buf.String()}, err\n\t}\n\tdoc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(body))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tresults := make([]string, 0, 8)\n\tdoc.Find(q).Each(func(_ int, s *goquery.Selection) {\n\t\thtmlResult, err := goquery.OuterHtml(s)\n\t\tif err == nil {\n\t\t\tresults = append(results, htmlResult)\n\t\t}\n\t})\n\n\treturn results, nil\n}\n"
  },
  {
    "path": "formatter/json.go",
    "content": "package formatter\n\nimport (\n\t\"bytes\"\n\t\"errors\"\n\t\"io\"\n\n\t\"github.com/nwidger/jsoncolor\"\n\t\"github.com/tidwall/gjson\"\n)\n\ntype jsonFormatter struct {\n\tparsedBody gjson.Result\n\tTextFormatter\n}\n\nfunc (f *jsonFormatter) Format(writer io.Writer, data []byte) error {\n\tjsonFormatter := jsoncolor.NewFormatter()\n\tjsonFormatter.Indent = \"  \"\n\tbuf := bytes.NewBuffer(make([]byte, 0, len(data)))\n\terr := jsonFormatter.Format(buf, data)\n\tif err == nil {\n\t\twriter.Write(buf.Bytes())\n\t\treturn nil\n\t}\n\treturn errors.New(\"json formatter error\")\n}\n\nfunc (f *jsonFormatter) Title() string {\n\treturn \"[json]\"\n}\n\nfunc (f *jsonFormatter) Search(q string, body []byte) ([]string, error) {\n\tif q != \"\" {\n\t\tif f.parsedBody.Type != gjson.JSON {\n\t\t\tf.parsedBody = gjson.ParseBytes(body)\n\t\t}\n\t\tsearchResult := f.parsedBody.Get(q)\n\t\tif searchResult.Type == gjson.Null {\n\t\t\treturn nil, errors.New(\"Invalid gjson query or no results found\")\n\t\t}\n\t\tif searchResult.Type != gjson.JSON {\n\t\t\treturn []string{searchResult.String()}, nil\n\t\t}\n\t\tbody = []byte(searchResult.String())\n\t}\n\tjsonFormatter := jsoncolor.NewFormatter()\n\tjsonFormatter.Indent = \"  \"\n\tbuf := bytes.NewBuffer(make([]byte, 0, len(body)))\n\terr := jsonFormatter.Format(buf, body)\n\tif err != nil {\n\t\treturn nil, errors.New(\"Invalid results\")\n\t}\n\treturn []string{string(buf.Bytes())}, nil\n}\n"
  },
  {
    "path": "formatter/text.go",
    "content": "package formatter\n\nimport (\n\t\"io\"\n\t\"regexp\"\n)\n\ntype TextFormatter struct {\n}\n\nfunc (f *TextFormatter) Format(writer io.Writer, data []byte) error {\n\t_, err := writer.Write(data)\n\treturn err\n}\n\nfunc (f *TextFormatter) Title() string {\n\treturn \"[text]\"\n}\n\nfunc (f *TextFormatter) Searchable() bool {\n\treturn true\n}\n\nfunc (f *TextFormatter) Search(q string, body []byte) ([]string, error) {\n\tsearch_re, err := regexp.Compile(q)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tret := make([]string, 0, 16)\n\tfor _, match := range search_re.FindAll(body, 1000) {\n\t\tret = append(ret, string(match))\n\t}\n\treturn ret, nil\n}\n"
  },
  {
    "path": "go.mod",
    "content": "module github.com/asciimoo/wuzz\n\ngo 1.24.0\n\ntoolchain go1.24.7\n\nrequire (\n\tgithub.com/BurntSushi/toml v1.5.0\n\tgithub.com/PuerkitoBio/goquery v1.10.3\n\tgithub.com/alessio/shellescape v1.4.2\n\tgithub.com/awesome-gocui/gocui v1.1.0\n\tgithub.com/mattn/go-runewidth v0.0.19\n\tgithub.com/mitchellh/go-homedir v1.1.0\n\tgithub.com/nwidger/jsoncolor v0.3.2\n\tgithub.com/tidwall/gjson v1.18.0\n\tgithub.com/x86kernel/htmlcolor v0.0.0-20190529101448-c589f58466d0\n\tgolang.org/x/net v0.46.0\n)\n\nrequire (\n\tgithub.com/andybalholm/cascadia v1.3.3 // indirect\n\tgithub.com/clipperhouse/stringish v0.1.1 // indirect\n\tgithub.com/clipperhouse/uax29/v2 v2.3.0 // indirect\n\tgithub.com/davecgh/go-spew v1.1.1 // indirect\n\tgithub.com/fatih/color v1.18.0 // indirect\n\tgithub.com/gdamore/encoding v1.0.1 // indirect\n\tgithub.com/gdamore/tcell/v2 v2.9.0 // indirect\n\tgithub.com/google/go-cmp v0.6.0 // indirect\n\tgithub.com/lucasb-eyer/go-colorful v1.3.0 // indirect\n\tgithub.com/mattn/go-colorable v0.1.14 // indirect\n\tgithub.com/mattn/go-isatty v0.0.20 // indirect\n\tgithub.com/pmezard/go-difflib v1.0.0 // indirect\n\tgithub.com/rivo/uniseg v0.4.7 // indirect\n\tgithub.com/stretchr/objx v0.5.2 // indirect\n\tgithub.com/stretchr/testify v1.10.0 // indirect\n\tgithub.com/tidwall/match v1.2.0 // indirect\n\tgithub.com/tidwall/pretty v1.2.1 // indirect\n\tgithub.com/yuin/goldmark v1.4.13 // indirect\n\tgolang.org/x/crypto v0.43.0 // indirect\n\tgolang.org/x/mod v0.28.0 // indirect\n\tgolang.org/x/sync v0.17.0 // indirect\n\tgolang.org/x/sys v0.37.0 // indirect\n\tgolang.org/x/telemetry v0.0.0-20250908211612-aef8a434d053 // indirect\n\tgolang.org/x/term v0.36.0 // indirect\n\tgolang.org/x/text v0.30.0 // indirect\n\tgolang.org/x/tools v0.37.0 // indirect\n\tgolang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect\n\tgopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 // indirect\n\tgopkg.in/yaml.v3 v3.0.1 // indirect\n)\n"
  },
  {
    "path": "go.sum",
    "content": "github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=\ngithub.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=\ngithub.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=\ngithub.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=\ngithub.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154OaKCSE=\ngithub.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=\ngithub.com/PuerkitoBio/goquery v1.10.3 h1:pFYcNSqHxBD06Fpj/KsbStFRsgRATgnf3LeXiUkhzPo=\ngithub.com/PuerkitoBio/goquery v1.10.3/go.mod h1:tMUX0zDMHXYlAQk6p35XxQMqMweEKB7iK7iLNd4RH4Y=\ngithub.com/alessio/shellescape v1.2.2 h1:8LnL+ncxhWT2TR00dfJRT25JWWrhkMZXneHVWnetDZg=\ngithub.com/alessio/shellescape v1.2.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=\ngithub.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0=\ngithub.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=\ngithub.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=\ngithub.com/andybalholm/cascadia v1.2.0 h1:vuRCkM5Ozh/BfmsaTm26kbjm0mIOM3yS5Ek/F5h18aE=\ngithub.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxBp0T0eFw1RUQY=\ngithub.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=\ngithub.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=\ngithub.com/awesome-gocui/gocui v1.1.0 h1:db2j7yFEoHZjpQFeE2xqiatS8bm1lO3THeLwE6MzOII=\ngithub.com/awesome-gocui/gocui v1.1.0/go.mod h1:M2BXkrp7PR97CKnPRT7Rk0+rtswChPtksw/vRAESGpg=\ngithub.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=\ngithub.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=\ngithub.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuhIGpJy4=\ngithub.com/clipperhouse/uax29/v2 v2.3.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=\ngithub.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=\ngithub.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=\ngithub.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=\ngithub.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=\ngithub.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=\ngithub.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=\ngithub.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=\ngithub.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=\ngithub.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=\ngithub.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=\ngithub.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=\ngithub.com/gdamore/tcell/v2 v2.4.0 h1:W6dxJEmaxYvhICFoTY3WrLLEXsQ11SaFnKGVEXW57KM=\ngithub.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=\ngithub.com/gdamore/tcell/v2 v2.9.0 h1:N6t+eqK7/xwtRPwxzs1PXeRWnm0H9l02CrgJ7DLn1ys=\ngithub.com/gdamore/tcell/v2 v2.9.0/go.mod h1:8/ZoqM9rxzYphT9tH/9LnunhV9oPBqwS8WHGYm5nrmo=\ngithub.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=\ngithub.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=\ngithub.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=\ngithub.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=\ngithub.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=\ngithub.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=\ngithub.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=\ngithub.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=\ngithub.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=\ngithub.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=\ngithub.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=\ngithub.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=\ngithub.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=\ngithub.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=\ngithub.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=\ngithub.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=\ngithub.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=\ngithub.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=\ngithub.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=\ngithub.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=\ngithub.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=\ngithub.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=\ngithub.com/nwidger/jsoncolor v0.3.0 h1:VdTH8Dc0SJoq4pJ8pRxxFZW0/5Ng5akbN4YToCBJDSU=\ngithub.com/nwidger/jsoncolor v0.3.0/go.mod h1:Cs34umxLbJvgBMnVNVqhji9BhoT/N/KinHqZptQ7cf4=\ngithub.com/nwidger/jsoncolor v0.3.2 h1:rVJJlwAWDJShnbTYOQ5RM7yTA20INyKXlJ/fg4JMhHQ=\ngithub.com/nwidger/jsoncolor v0.3.2/go.mod h1:Cs34umxLbJvgBMnVNVqhji9BhoT/N/KinHqZptQ7cf4=\ngithub.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=\ngithub.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=\ngithub.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=\ngithub.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=\ngithub.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=\ngithub.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=\ngithub.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=\ngithub.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=\ngithub.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=\ngithub.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=\ngithub.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=\ngithub.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=\ngithub.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=\ngithub.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=\ngithub.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=\ngithub.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=\ngithub.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=\ngithub.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=\ngithub.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=\ngithub.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=\ngithub.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=\ngithub.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=\ngithub.com/tidwall/match v1.2.0 h1:0pt8FlkOwjN2fPt4bIl4BoNxb98gGHN2ObFEDkrfZnM=\ngithub.com/tidwall/match v1.2.0/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=\ngithub.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=\ngithub.com/tidwall/pretty v1.0.1 h1:WE4RBSZ1x6McVVC8S/Md+Qse8YUv6HRObAx6ke00NY8=\ngithub.com/tidwall/pretty v1.0.1/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=\ngithub.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=\ngithub.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=\ngithub.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=\ngithub.com/x86kernel/htmlcolor v0.0.0-20190529101448-c589f58466d0 h1:eViiK7U+LXJuAEcnOdp+5jIDp7j9iE2FE8YfWoLExTE=\ngithub.com/x86kernel/htmlcolor v0.0.0-20190529101448-c589f58466d0/go.mod h1:pUZuomyrQzbA0SQPSwAnDB3TgChnUMfZnSSfcAzpVh8=\ngithub.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=\ngolang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=\ngolang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=\ngolang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=\ngolang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=\ngolang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=\ngolang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=\ngolang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=\ngolang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=\ngolang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=\ngolang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=\ngolang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=\ngolang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=\ngolang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=\ngolang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=\ngolang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=\ngolang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=\ngolang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM=\ngolang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=\ngolang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=\ngolang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=\ngolang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=\ngolang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=\ngolang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=\ngolang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=\ngolang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=\ngolang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=\ngolang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=\ngolang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=\ngolang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=\ngolang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=\ngolang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=\ngolang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=\ngolang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=\ngolang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=\ngolang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=\ngolang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=\ngolang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=\ngolang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=\ngolang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=\ngolang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=\ngolang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=\ngolang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=\ngolang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=\ngolang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=\ngolang.org/x/telemetry v0.0.0-20250908211612-aef8a434d053/go.mod h1:+nZKN+XVh4LCiA9DV3ywrzN4gumyCnKjau3NGb9SGoE=\ngolang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=\ngolang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=\ngolang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=\ngolang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=\ngolang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=\ngolang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=\ngolang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=\ngolang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=\ngolang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=\ngolang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=\ngolang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=\ngolang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=\ngolang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=\ngolang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=\ngolang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=\ngolang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=\ngolang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=\ngolang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=\ngolang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=\ngolang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=\ngolang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=\ngolang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=\ngolang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=\ngolang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=\ngolang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=\ngolang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=\ngolang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=\ngolang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=\ngolang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=\ngolang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=\ngolang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=\ngolang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=\ngopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=\ngopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=\ngopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=\ngopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=\ngopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=\n"
  },
  {
    "path": "keys.go",
    "content": "package main\n\nimport (\n\t\"github.com/awesome-gocui/gocui\"\n)\n\nvar KEYS = map[string]gocui.Key{\n\t\"F1\":             gocui.KeyF1,\n\t\"F2\":             gocui.KeyF2,\n\t\"F3\":             gocui.KeyF3,\n\t\"F4\":             gocui.KeyF4,\n\t\"F5\":             gocui.KeyF5,\n\t\"F6\":             gocui.KeyF6,\n\t\"F7\":             gocui.KeyF7,\n\t\"F8\":             gocui.KeyF8,\n\t\"F9\":             gocui.KeyF9,\n\t\"F10\":            gocui.KeyF10,\n\t\"F11\":            gocui.KeyF11,\n\t\"F12\":            gocui.KeyF12,\n\t\"Insert\":         gocui.KeyInsert,\n\t\"Delete\":         gocui.KeyDelete,\n\t\"Home\":           gocui.KeyHome,\n\t\"End\":            gocui.KeyEnd,\n\t\"PageUp\":         gocui.KeyPgup,\n\t\"PageDown\":       gocui.KeyPgdn,\n\t\"ArrowUp\":        gocui.KeyArrowUp,\n\t\"ArrowDown\":      gocui.KeyArrowDown,\n\t\"ArrowLeft\":      gocui.KeyArrowLeft,\n\t\"ArrowRight\":     gocui.KeyArrowRight,\n\t\"CtrlTilde\":      gocui.KeyCtrlTilde,\n\t\"Ctrl2\":          gocui.KeyCtrl2,\n\t\"CtrlSpace\":      gocui.KeyCtrlSpace,\n\t\"CtrlA\":          gocui.KeyCtrlA,\n\t\"CtrlB\":          gocui.KeyCtrlB,\n\t\"CtrlC\":          gocui.KeyCtrlC,\n\t\"CtrlD\":          gocui.KeyCtrlD,\n\t\"CtrlE\":          gocui.KeyCtrlE,\n\t\"CtrlF\":          gocui.KeyCtrlF,\n\t\"CtrlG\":          gocui.KeyCtrlG,\n\t\"Backspace\":      gocui.KeyBackspace,\n\t\"CtrlH\":          gocui.KeyCtrlH,\n\t\"Tab\":            gocui.KeyTab,\n\t\"CtrlI\":          gocui.KeyCtrlI,\n\t\"CtrlJ\":          gocui.KeyCtrlJ,\n\t\"CtrlK\":          gocui.KeyCtrlK,\n\t\"CtrlL\":          gocui.KeyCtrlL,\n\t\"Enter\":          gocui.KeyEnter,\n\t\"CtrlM\":          gocui.KeyCtrlM,\n\t\"CtrlN\":          gocui.KeyCtrlN,\n\t\"CtrlO\":          gocui.KeyCtrlO,\n\t\"CtrlP\":          gocui.KeyCtrlP,\n\t\"CtrlQ\":          gocui.KeyCtrlQ,\n\t\"CtrlR\":          gocui.KeyCtrlR,\n\t\"CtrlS\":          gocui.KeyCtrlS,\n\t\"CtrlT\":          gocui.KeyCtrlT,\n\t\"CtrlU\":          gocui.KeyCtrlU,\n\t\"CtrlV\":          gocui.KeyCtrlV,\n\t\"CtrlW\":          gocui.KeyCtrlW,\n\t\"CtrlX\":          gocui.KeyCtrlX,\n\t\"CtrlY\":          gocui.KeyCtrlY,\n\t\"CtrlZ\":          gocui.KeyCtrlZ,\n\t\"Esc\":            gocui.KeyEsc,\n\t\"CtrlLsqBracket\": gocui.KeyCtrlLsqBracket,\n\t\"Ctrl3\":          gocui.KeyCtrl3,\n\t\"Ctrl4\":          gocui.KeyCtrl4,\n\t\"CtrlBackslash\":  gocui.KeyCtrlBackslash,\n\t\"Ctrl5\":          gocui.KeyCtrl5,\n\t\"CtrlRsqBracket\": gocui.KeyCtrlRsqBracket,\n\t\"Ctrl6\":          gocui.KeyCtrl6,\n\t\"Ctrl7\":          gocui.KeyCtrl7,\n\t\"CtrlSlash\":      gocui.KeyCtrlSlash,\n\t\"CtrlUnderscore\": gocui.KeyCtrlUnderscore,\n\t\"Space\":          gocui.KeySpace,\n\t\"Backspace2\":     gocui.KeyBackspace2,\n\t\"Ctrl8\":          gocui.KeyCtrl8,\n}\n"
  },
  {
    "path": "request-headers.go",
    "content": "package main\n\nvar REQUEST_HEADERS = []string{\n\t\"Accept\",\n\t\"Accept-Charset\",\n\t\"Accept-Encoding\",\n\t\"Accept-Language\",\n\t\"Accept-Datetime\",\n\t\"Authorization\",\n\t\"Cache-Control\",\n\t\"Connection\",\n\t\"Cookie\",\n\t\"Content-Length\",\n\t\"Content-MD5\",\n\t\"Content-Type\",\n\t\"Date\",\n\t\"Expect\",\n\t\"Forwarded\",\n\t\"From\",\n\t\"Host\",\n\t\"If-Match\",\n\t\"If-Modified-Since\",\n\t\"If-None-Match\",\n\t\"If-Range\",\n\t\"If-Unmodified-Since\",\n\t\"Max-Forwards\",\n\t\"Origin\",\n\t\"Pragma\",\n\t\"Proxy-Authorization\",\n\t\"Range\",\n\t\"Referer\",\n\t\"TE\",\n\t\"User-Agent\",\n\t\"Upgrade\",\n\t\"Via\",\n\t\"Warning\",\n}\n"
  },
  {
    "path": "sample-config.toml",
    "content": "[general]\ntimeout = \"1m\"\nformatJSON = true\ninsecure = false\npreserveScrollPosition = true\nfollowRedirects = true\ndefaultURLScheme = \"https\"\nstatusLine = \"[wuzz {{.Version}}] [Response time: {{.Duration}}]\"\neditor = \"vim\"\n\n# KEYBINDINGS\n[keys.global]\nCtrlR = \"submit\"\nCtrlC = \"quit\"\nCtrlS = \"saveResponse\"\nCtrlD = \"deleteLine\"\nCtrlW = \"deleteWord\"\nCtrlF = \"loadRequest\"\nCtrlE = \"saveRequest\"\nCtrlT = \"toggleContextSpecificSearch\"\nCtrlX = \"clearHistory\"\nCtrlL = \"clearTabs\"\nTab = \"nextView\"\nCtrlJ = \"nextView\"\nCtrlK = \"prevView\"\nAltH = \"history\"\nF2 = \"focus url\"\nF3 = \"focus get\"\nF4 = \"focus method\"\nF5 = \"focus data\"\nF6 = \"focus headers\"\nF7 = \"focus search\"\nF8 = \"focus response-headers\"\nF9 = \"focus response-body\"\nF11 = \"redirectRestriction\"\n\n[keys.url]\nEnter = \"submit\"\n\n[keys.response-headers]\nArrowUp = \"scrollUp\"\nArrowDown = \"scrollDown\"\nPageUp = \"pageUp\"\nPageDown = \"pageDown\"\n\n[keys.response-body]\nArrowUp = \"scrollUp\"\nArrowDown = \"scrollDown\"\nPageUp = \"pageUp\"\nPageDown = \"pageDown\"\n\n[keys.help]\nArrowUp = \"scrollUp\"\nArrowDown = \"scrollDown\"\nPageUp = \"pageUp\"\nPageDown = \"pageDown\"\n"
  },
  {
    "path": "status-line.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\t\"text/template\"\n\n\t\"github.com/awesome-gocui/gocui\"\n)\n\ntype StatusLine struct {\n\ttpl *template.Template\n}\n\ntype StatusLineFunctions struct {\n\tapp *App\n}\n\nfunc (_ *StatusLineFunctions) Version() string {\n\treturn VERSION\n}\n\nfunc (s *StatusLineFunctions) Duration() string {\n\tif len(s.app.history) == 0 {\n\t\treturn \"\"\n\t}\n\treturn s.app.history[s.app.historyIndex].Duration.String()\n}\n\nfunc (s *StatusLineFunctions) HistorySize() string {\n\treturn strconv.Itoa(len(s.app.history))\n}\n\nfunc (s *StatusLineFunctions) RequestNumber() string {\n\ti := s.app.historyIndex\n\tif len(s.app.history) > 0 {\n\t\ti += 1\n\t}\n\treturn strconv.Itoa(i)\n}\n\nfunc (s *StatusLineFunctions) SearchType() string {\n\tif len(s.app.history) > 0 && !s.app.history[s.app.historyIndex].Formatter.Searchable() {\n\t\treturn \"none\"\n\t}\n\tif s.app.config.General.ContextSpecificSearch {\n\t\treturn \"response specific\"\n\t}\n\treturn \"regex\"\n}\n\nfunc (s *StatusLine) Update(v *gocui.View, a *App) {\n\tv.Clear()\n\terr := s.tpl.Execute(v, &StatusLineFunctions{app: a})\n\tif err != nil {\n\t\tfmt.Fprintf(v, \"StatusLine update error: %v\", err)\n\t}\n}\n\nfunc (s *StatusLineFunctions) DisableRedirect() string {\n\tif s.app.config.General.FollowRedirects {\n\t\treturn \"\"\n\t}\n\treturn \"Activated\"\n}\n\nfunc NewStatusLine(format string) (*StatusLine, error) {\n\ttpl, err := template.New(\"status line\").Parse(format)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn &StatusLine{\n\t\ttpl: tpl,\n\t}, nil\n}\n"
  },
  {
    "path": "wuzz.go",
    "content": "package main\n\nimport (\n\t\"bytes\"\n\t\"compress/gzip\"\n\t\"crypto/tls\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"mime/multipart\"\n\t\"net/http\"\n\t\"net/url\"\n\t\"os\"\n\t\"path\"\n\t\"regexp\"\n\t\"runtime\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n\t\"time\"\n\n\t\"golang.org/x/net/proxy\"\n\n\t\"github.com/asciimoo/wuzz/config\"\n\t\"github.com/asciimoo/wuzz/formatter\"\n\n\t\"github.com/alessio/shellescape\"\n\t\"github.com/awesome-gocui/gocui\"\n\t\"github.com/mattn/go-runewidth\"\n)\n\nconst VERSION = \"0.5.0\"\n\nconst TIMEOUT_DURATION = 5 // in seconds\nconst WINDOWS_OS = \"windows\"\nconst SEARCH_PROMPT = \"search> \"\n\nconst (\n\tALL_VIEWS = \"\"\n\n\tURL_VIEW              = \"url\"\n\tURL_PARAMS_VIEW       = \"get\"\n\tREQUEST_METHOD_VIEW   = \"method\"\n\tREQUEST_DATA_VIEW     = \"data\"\n\tREQUEST_HEADERS_VIEW  = \"headers\"\n\tSTATUSLINE_VIEW       = \"status-line\"\n\tSEARCH_VIEW           = \"search\"\n\tRESPONSE_HEADERS_VIEW = \"response-headers\"\n\tRESPONSE_BODY_VIEW    = \"response-body\"\n\n\tSEARCH_PROMPT_VIEW              = \"prompt\"\n\tPOPUP_VIEW                      = \"popup_view\"\n\tAUTOCOMPLETE_VIEW               = \"autocomplete_view\"\n\tERROR_VIEW                      = \"error_view\"\n\tHISTORY_VIEW                    = \"history\"\n\tSAVE_DIALOG_VIEW                = \"save-dialog\"\n\tSAVE_RESPONSE_DIALOG_VIEW       = \"save-response-dialog\"\n\tLOAD_REQUEST_DIALOG_VIEW        = \"load-request-dialog\"\n\tSAVE_REQUEST_FORMAT_DIALOG_VIEW = \"save-request-format-dialog\"\n\tSAVE_REQUEST_DIALOG_VIEW        = \"save-request-dialog\"\n\tSAVE_RESULT_VIEW                = \"save-result\"\n\tMETHOD_LIST_VIEW                = \"method-list\"\n\tHELP_VIEW                       = \"help\"\n)\n\nvar VIEW_TITLES = map[string]string{\n\tPOPUP_VIEW:                      \"Info\",\n\tERROR_VIEW:                      \"Error\",\n\tHISTORY_VIEW:                    \"History\",\n\tSAVE_RESPONSE_DIALOG_VIEW:       \"Save Response (enter to submit, ctrl+q to cancel)\",\n\tLOAD_REQUEST_DIALOG_VIEW:        \"Load Request (enter to submit, ctrl+q to cancel)\",\n\tSAVE_REQUEST_DIALOG_VIEW:        \"Save Request (enter to submit, ctrl+q to cancel)\",\n\tSAVE_REQUEST_FORMAT_DIALOG_VIEW: \"Choose export format\",\n\tSAVE_RESULT_VIEW:                \"Save Result (press enter to close)\",\n\tMETHOD_LIST_VIEW:                \"Methods\",\n\tHELP_VIEW:                       \"Help\",\n}\n\ntype position struct {\n\t// value = prc * MAX + abs\n\tpct float32\n\tabs int\n}\n\ntype viewPosition struct {\n\tx0, y0, x1, y1 position\n}\n\nvar VIEW_POSITIONS = map[string]viewPosition{\n\tURL_VIEW: {\n\t\tposition{0.0, 0},\n\t\tposition{0.0, 0},\n\t\tposition{1.0, -2},\n\t\tposition{0.0, 3}},\n\tURL_PARAMS_VIEW: {\n\t\tposition{0.0, 0},\n\t\tposition{0.0, 3},\n\t\tposition{0.3, 0},\n\t\tposition{0.25, 0}},\n\tREQUEST_METHOD_VIEW: {\n\t\tposition{0.0, 0},\n\t\tposition{0.25, 0},\n\t\tposition{0.3, 0},\n\t\tposition{0.25, 2}},\n\tREQUEST_DATA_VIEW: {\n\t\tposition{0.0, 0},\n\t\tposition{0.25, 2},\n\t\tposition{0.3, 0},\n\t\tposition{0.5, 1}},\n\tREQUEST_HEADERS_VIEW: {\n\t\tposition{0.0, 0},\n\t\tposition{0.5, 1},\n\t\tposition{0.3, 0},\n\t\tposition{1.0, -3}},\n\tRESPONSE_HEADERS_VIEW: {\n\t\tposition{0.3, 0},\n\t\tposition{0.0, 3},\n\t\tposition{1.0, -2},\n\t\tposition{0.25, 2}},\n\tRESPONSE_BODY_VIEW: {\n\t\tposition{0.3, 0},\n\t\tposition{0.25, 2},\n\t\tposition{1.0, -2},\n\t\tposition{1.0, -3}},\n\tSTATUSLINE_VIEW: {\n\t\tposition{0.0, -1},\n\t\tposition{1.0, -4},\n\t\tposition{1.0, 0},\n\t\tposition{1.0, -1}},\n\tSEARCH_VIEW: {\n\t\tposition{0.0, 7},\n\t\tposition{1.0, -3},\n\t\tposition{1.0, -1},\n\t\tposition{1.0, -1}},\n\tERROR_VIEW: {\n\t\tposition{0.0, 0},\n\t\tposition{0.0, 0},\n\t\tposition{1.0, -2},\n\t\tposition{1.0, -2}},\n\tSEARCH_PROMPT_VIEW: {\n\t\tposition{0.0, -1},\n\t\tposition{1.0, -3},\n\t\tposition{0.0, 8},\n\t\tposition{1.0, -1}},\n\tPOPUP_VIEW: {\n\t\tposition{0.5, -9999}, // set before usage using len(msg)\n\t\tposition{0.5, -1},\n\t\tposition{0.5, -9999}, // set before usage using len(msg)\n\t\tposition{0.5, 1}},\n\tAUTOCOMPLETE_VIEW: {\n\t\tposition{0, -9999},\n\t\tposition{0, -9999},\n\t\tposition{0, -9999},\n\t\tposition{0, -9999}},\n}\n\ntype viewProperties struct {\n\ttitle    string\n\tframe    bool\n\teditable bool\n\twrap     bool\n\teditor   gocui.Editor\n\ttext     string\n}\n\nvar VIEW_PROPERTIES = map[string]viewProperties{\n\tURL_VIEW: {\n\t\ttitle:    \"URL - press F1 for help\",\n\t\tframe:    true,\n\t\teditable: true,\n\t\twrap:     false,\n\t\teditor:   &singleLineEditor{&defaultEditor},\n\t},\n\tURL_PARAMS_VIEW: {\n\t\ttitle:    \"URL params\",\n\t\tframe:    true,\n\t\teditable: true,\n\t\twrap:     false,\n\t\teditor:   &defaultEditor,\n\t},\n\tREQUEST_METHOD_VIEW: {\n\t\ttitle:    \"Method\",\n\t\tframe:    true,\n\t\teditable: true,\n\t\twrap:     false,\n\t\teditor:   &singleLineEditor{&defaultEditor},\n\t\ttext:     DEFAULT_METHOD,\n\t},\n\tREQUEST_DATA_VIEW: {\n\t\ttitle:    \"Request data (POST/PUT/PATCH)\",\n\t\tframe:    true,\n\t\teditable: true,\n\t\twrap:     false,\n\t\teditor:   &defaultEditor,\n\t},\n\tREQUEST_HEADERS_VIEW: {\n\t\ttitle:    \"Request headers\",\n\t\tframe:    true,\n\t\teditable: true,\n\t\twrap:     false,\n\t\teditor: &AutocompleteEditor{&defaultEditor, func(str string) []string {\n\t\t\treturn completeFromSlice(str, REQUEST_HEADERS)\n\t\t}, []string{}, false},\n\t},\n\tRESPONSE_HEADERS_VIEW: {\n\t\ttitle:    \"Response headers\",\n\t\tframe:    true,\n\t\teditable: true,\n\t\twrap:     true,\n\t\teditor:   nil, // should be set using a.getViewEditor(g)\n\t},\n\tRESPONSE_BODY_VIEW: {\n\t\ttitle:    \"Response body\",\n\t\tframe:    true,\n\t\teditable: true,\n\t\twrap:     true,\n\t\teditor:   nil, // should be set using a.getViewEditor(g)\n\t},\n\tSEARCH_VIEW: {\n\t\ttitle:    \"\",\n\t\tframe:    false,\n\t\teditable: true,\n\t\twrap:     false,\n\t\teditor:   &singleLineEditor{&SearchEditor{&defaultEditor}},\n\t},\n\tSTATUSLINE_VIEW: {\n\t\ttitle:    \"\",\n\t\tframe:    false,\n\t\teditable: false,\n\t\twrap:     false,\n\t\teditor:   nil,\n\t\ttext:     \"\",\n\t},\n\tSEARCH_PROMPT_VIEW: {\n\t\ttitle:    \"\",\n\t\tframe:    false,\n\t\teditable: false,\n\t\twrap:     false,\n\t\teditor:   nil,\n\t\ttext:     SEARCH_PROMPT,\n\t},\n\tPOPUP_VIEW: {\n\t\ttitle:    \"Info\",\n\t\tframe:    true,\n\t\teditable: false,\n\t\twrap:     false,\n\t\teditor:   nil,\n\t},\n\tAUTOCOMPLETE_VIEW: {\n\t\ttitle:    \"\",\n\t\tframe:    false,\n\t\teditable: false,\n\t\twrap:     false,\n\t\teditor:   nil,\n\t},\n}\n\nvar METHODS = []string{\n\thttp.MethodGet,\n\thttp.MethodPost,\n\thttp.MethodPut,\n\thttp.MethodDelete,\n\thttp.MethodPatch,\n\thttp.MethodOptions,\n\thttp.MethodTrace,\n\thttp.MethodConnect,\n\thttp.MethodHead,\n}\n\nvar EXPORT_FORMATS = []struct {\n\tname   string\n\texport func(r Request) []byte\n}{\n\t{\n\t\tname:   \"JSON\",\n\t\texport: exportJSON,\n\t},\n\t{\n\t\tname:   \"curl\",\n\t\texport: exportCurl,\n\t},\n}\n\nconst DEFAULT_METHOD = http.MethodGet\n\nvar DEFAULT_FORMATTER = &formatter.TextFormatter{}\n\nvar CLIENT = &http.Client{\n\tTimeout: time.Duration(TIMEOUT_DURATION * time.Second),\n}\nvar TRANSPORT = &http.Transport{\n\tProxy: http.ProxyFromEnvironment,\n}\n\nvar VIEWS = []string{\n\tURL_VIEW,\n\tURL_PARAMS_VIEW,\n\tREQUEST_METHOD_VIEW,\n\tREQUEST_DATA_VIEW,\n\tREQUEST_HEADERS_VIEW,\n\tSEARCH_VIEW,\n\tRESPONSE_HEADERS_VIEW,\n\tRESPONSE_BODY_VIEW,\n}\n\nvar TLS_VERSIONS = map[string]uint16{\n\t\"SSL3.0\": tls.VersionSSL30,\n\t\"TLS1.0\": tls.VersionTLS10,\n\t\"TLS1.1\": tls.VersionTLS11,\n\t\"TLS1.2\": tls.VersionTLS12,\n}\n\nvar defaultEditor ViewEditor\n\nconst (\n\tMIN_WIDTH  = 60\n\tMIN_HEIGHT = 20\n)\n\ntype Request struct {\n\tUrl             string\n\tMethod          string\n\tGetParams       string\n\tData            string\n\tHeaders         string\n\tResponseHeaders string\n\tRawResponseBody []byte\n\tContentType     string\n\tDuration        time.Duration\n\tFormatter       formatter.ResponseFormatter\n}\n\ntype App struct {\n\tviewIndex    int\n\thistoryIndex int\n\tcurrentPopup string\n\thistory      []*Request\n\tconfig       *config.Config\n\tstatusLine   *StatusLine\n}\n\ntype ViewEditor struct {\n\tapp           *App\n\tg             *gocui.Gui\n\tbackTabEscape bool\n\torigEditor    gocui.Editor\n}\n\ntype AutocompleteEditor struct {\n\twuzzEditor         *ViewEditor\n\tcompletions        func(string) []string\n\tcurrentCompletions []string\n\tisAutocompleting   bool\n}\n\ntype SearchEditor struct {\n\twuzzEditor *ViewEditor\n}\n\n// The singleLineEditor removes multi lines capabilities\ntype singleLineEditor struct {\n\twuzzEditor gocui.Editor\n}\n\nfunc init() {\n\tTRANSPORT.DisableCompression = true\n\tCLIENT.Transport = TRANSPORT\n}\n\n// Editor funcs\n\nfunc (e *ViewEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {\n\t// handle back-tab (\\033[Z) sequence\n\tif e.backTabEscape {\n\t\tif ch == 'Z' {\n\t\t\te.app.PrevView(e.g, nil)\n\t\t\te.backTabEscape = false\n\t\t\treturn\n\t\t} else {\n\t\t\te.origEditor.Edit(v, 0, '[', gocui.ModAlt)\n\t\t}\n\t}\n\tif ch == '[' && mod == gocui.ModAlt {\n\t\te.backTabEscape = true\n\t\treturn\n\t}\n\n\t// disable infinite down scroll\n\tif key == gocui.KeyArrowDown && mod == gocui.ModNone {\n\t\t_, cY := v.Cursor()\n\t\t_, err := v.Line(cY)\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t}\n\n\te.origEditor.Edit(v, key, ch, mod)\n}\n\nvar symbolPattern = regexp.MustCompile(\"[a-zA-Z0-9-]+$\")\n\nfunc getLastSymbol(str string) string {\n\treturn symbolPattern.FindString(str)\n}\n\nfunc completeFromSlice(str string, completions []string) []string {\n\tcompleted := []string{}\n\tif str == \"\" || strings.TrimRight(str, \" \\n\") != str {\n\t\treturn completed\n\t}\n\tfor _, completion := range completions {\n\t\tif strings.HasPrefix(completion, str) && str != completion {\n\t\t\tcompleted = append(completed, completion)\n\t\t}\n\t}\n\treturn completed\n}\n\nfunc (e *AutocompleteEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {\n\tif key != gocui.KeyEnter {\n\t\te.wuzzEditor.Edit(v, key, ch, mod)\n\t}\n\n\tcx, cy := v.Cursor()\n\tline, err := v.Line(cy)\n\ttrimmedLine := line[:cx]\n\n\tif err != nil {\n\t\te.wuzzEditor.Edit(v, key, ch, mod)\n\t\treturn\n\t}\n\n\tlastSymbol := getLastSymbol(trimmedLine)\n\tif key == gocui.KeyEnter && e.isAutocompleting {\n\t\tcurrentCompletion := e.currentCompletions[0]\n\t\tshouldDelete := true\n\t\tif len(e.currentCompletions) == 1 {\n\t\t\tshouldDelete = false\n\t\t}\n\n\t\tif shouldDelete {\n\t\t\tfor range lastSymbol {\n\t\t\t\tv.EditDelete(true)\n\t\t\t}\n\t\t}\n\t\tfor _, char := range currentCompletion {\n\t\t\tv.EditWrite(char)\n\t\t}\n\t\tcloseAutocomplete(e.wuzzEditor.g)\n\t\te.isAutocompleting = false\n\t\treturn\n\t} else if key == gocui.KeyEnter {\n\t\te.wuzzEditor.Edit(v, key, ch, mod)\n\t}\n\n\tcloseAutocomplete(e.wuzzEditor.g)\n\te.isAutocompleting = false\n\n\tcompletions := e.completions(lastSymbol)\n\te.currentCompletions = completions\n\n\tcx, cy = v.Cursor()\n\tsx, _ := v.Size()\n\tox, oy, _, _, _ := e.wuzzEditor.g.ViewPosition(v.Name())\n\n\tmaxWidth := sx - cx\n\tmaxHeight := 10\n\n\tif len(completions) > 0 {\n\t\tcomps := completions\n\t\tx := ox + cx\n\t\ty := oy + cy\n\t\tif len(comps) == 1 {\n\t\t\tcomps[0] = comps[0][len(lastSymbol):]\n\t\t} else {\n\t\t\ty += 1\n\t\t\tx -= len(lastSymbol)\n\t\t\tmaxWidth += len(lastSymbol)\n\t\t}\n\t\tshowAutocomplete(comps, x, y, maxWidth, maxHeight, e.wuzzEditor.g)\n\t\te.isAutocompleting = true\n\t}\n}\n\nfunc (e *SearchEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {\n\te.wuzzEditor.Edit(v, key, ch, mod)\n\te.wuzzEditor.g.Update(func(g *gocui.Gui) error {\n\t\te.wuzzEditor.app.PrintBody(g)\n\t\treturn nil\n\t})\n}\n\n// The singleLineEditor removes multi lines capabilities\nfunc (e singleLineEditor) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {\n\tswitch {\n\tcase (ch != 0 || key == gocui.KeySpace) && mod == 0:\n\t\te.wuzzEditor.Edit(v, key, ch, mod)\n\t\t// At the end of the line the default gcui editor adds a whitespace\n\t\t// Force him to remove\n\t\tox, _ := v.Cursor()\n\t\tif ox > 1 && ox >= len(v.Buffer())-2 {\n\t\t\tv.EditDelete(false)\n\t\t}\n\t\treturn\n\tcase key == gocui.KeyEnter:\n\t\treturn\n\tcase key == gocui.KeyArrowRight:\n\t\tox, _ := v.Cursor()\n\t\tif ox >= len(v.Buffer())-1 {\n\t\t\treturn\n\t\t}\n\tcase key == gocui.KeyHome || key == gocui.KeyArrowUp:\n\t\tv.SetCursor(0, 0)\n\t\tv.SetOrigin(0, 0)\n\t\treturn\n\tcase key == gocui.KeyEnd || key == gocui.KeyArrowDown:\n\t\twidth, _ := v.Size()\n\t\tlineWidth := len(v.Buffer()) - 1\n\t\tif lineWidth > width {\n\t\t\tv.SetOrigin(lineWidth-width, 0)\n\t\t\tlineWidth = width - 1\n\t\t}\n\t\tv.SetCursor(lineWidth, 0)\n\t\treturn\n\t}\n\te.wuzzEditor.Edit(v, key, ch, mod)\n}\n\n//\n\nfunc (a *App) getResponseViewEditor(g *gocui.Gui) gocui.Editor {\n\treturn &ViewEditor{a, g, false, gocui.EditorFunc(func(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier) {\n\t\treturn\n\t})}\n}\n\nfunc (p position) getCoordinate(max int) int {\n\treturn int(p.pct*float32(max)) + p.abs\n}\n\nfunc setView(g *gocui.Gui, viewName string) (*gocui.View, error) {\n\tmaxX, maxY := g.Size()\n\tposition := VIEW_POSITIONS[viewName]\n\treturn g.SetView(viewName,\n\t\tposition.x0.getCoordinate(maxX+1),\n\t\tposition.y0.getCoordinate(maxY+1),\n\t\tposition.x1.getCoordinate(maxX+1),\n\t\tposition.y1.getCoordinate(maxY+1),\n\t\t0)\n}\n\nfunc setViewProperties(v *gocui.View, name string) {\n\tv.Title = VIEW_PROPERTIES[name].title\n\tv.Frame = VIEW_PROPERTIES[name].frame\n\tv.Editable = VIEW_PROPERTIES[name].editable\n\tv.Wrap = VIEW_PROPERTIES[name].wrap\n\tv.Editor = VIEW_PROPERTIES[name].editor\n\tsetViewTextAndCursor(v, VIEW_PROPERTIES[name].text)\n}\n\nfunc (a *App) Layout(g *gocui.Gui) error {\n\tmaxX, maxY := g.Size()\n\n\tif maxX < MIN_WIDTH || maxY < MIN_HEIGHT {\n\t\tif v, err := setView(g, ERROR_VIEW); err != nil {\n\t\t\tif err != gocui.ErrUnknownView {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tsetViewDefaults(v)\n\t\t\tv.Title = VIEW_TITLES[ERROR_VIEW]\n\t\t\tg.Cursor = false\n\t\t\tfmt.Fprintln(v, \"Terminal is too small\")\n\t\t}\n\t\treturn nil\n\t}\n\tif _, err := g.View(ERROR_VIEW); err == nil {\n\t\tg.DeleteView(ERROR_VIEW)\n\t\tg.Cursor = true\n\t\ta.setView(g)\n\t}\n\n\tfor _, name := range []string{RESPONSE_HEADERS_VIEW, RESPONSE_BODY_VIEW} {\n\t\tvp := VIEW_PROPERTIES[name]\n\t\tvp.editor = a.getResponseViewEditor(g)\n\t\tVIEW_PROPERTIES[name] = vp\n\t}\n\n\tif a.config.General.DefaultURLScheme != \"\" && !strings.HasSuffix(a.config.General.DefaultURLScheme, \"://\") {\n\t\tp := VIEW_PROPERTIES[URL_VIEW]\n\t\tp.text = a.config.General.DefaultURLScheme + \"://\"\n\t\tVIEW_PROPERTIES[URL_VIEW] = p\n\t}\n\n\tfor _, name := range []string{\n\t\tURL_VIEW,\n\t\tURL_PARAMS_VIEW,\n\t\tREQUEST_METHOD_VIEW,\n\t\tREQUEST_DATA_VIEW,\n\t\tREQUEST_HEADERS_VIEW,\n\t\tRESPONSE_HEADERS_VIEW,\n\t\tRESPONSE_BODY_VIEW,\n\t\tSTATUSLINE_VIEW,\n\t\tSEARCH_PROMPT_VIEW,\n\t\tSEARCH_VIEW,\n\t} {\n\t\tif v, err := setView(g, name); err != nil {\n\t\t\tif err != gocui.ErrUnknownView {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tsetViewProperties(v, name)\n\t\t}\n\t}\n\trefreshStatusLine(a, g)\n\n\treturn nil\n}\n\nfunc (a *App) NextView(g *gocui.Gui, v *gocui.View) error {\n\ta.viewIndex = (a.viewIndex + 1) % len(VIEWS)\n\treturn a.setView(g)\n}\n\nfunc (a *App) PrevView(g *gocui.Gui, v *gocui.View) error {\n\ta.viewIndex = (a.viewIndex - 1 + len(VIEWS)) % len(VIEWS)\n\treturn a.setView(g)\n}\n\nfunc (a *App) setView(g *gocui.Gui) error {\n\ta.closePopup(g, a.currentPopup)\n\t_, err := g.SetCurrentView(VIEWS[a.viewIndex])\n\treturn err\n}\n\nfunc (a *App) setViewByName(g *gocui.Gui, name string) error {\n\tfor i, v := range VIEWS {\n\t\tif v == name {\n\t\t\ta.viewIndex = i\n\t\t\treturn a.setView(g)\n\t\t}\n\t}\n\treturn fmt.Errorf(\"View not found\")\n}\n\nfunc popup(g *gocui.Gui, msg string) {\n\tpos := VIEW_POSITIONS[POPUP_VIEW]\n\tpos.x0.abs = -len(msg)/2 - 1\n\tpos.x1.abs = len(msg)/2 + 1\n\tVIEW_POSITIONS[POPUP_VIEW] = pos\n\n\tp := VIEW_PROPERTIES[POPUP_VIEW]\n\tp.text = msg\n\tVIEW_PROPERTIES[POPUP_VIEW] = p\n\n\tif v, err := setView(g, POPUP_VIEW); err != nil {\n\t\tif err != gocui.ErrUnknownView {\n\t\t\treturn\n\t\t}\n\t\tsetViewProperties(v, POPUP_VIEW)\n\t\tg.SetViewOnTop(POPUP_VIEW)\n\t}\n}\n\nfunc minInt(x, y int) int {\n\tif x < y {\n\t\treturn x\n\t}\n\treturn y\n}\n\nfunc closeAutocomplete(g *gocui.Gui) {\n\tg.DeleteView(AUTOCOMPLETE_VIEW)\n}\n\nfunc showAutocomplete(completions []string, left, top, maxWidth, maxHeight int, g *gocui.Gui) {\n\t// Get the width of the widest completion\n\tcompletionsWidth := 0\n\tfor _, completion := range completions {\n\t\tthisCompletionWidth := len(completion)\n\t\tif thisCompletionWidth > completionsWidth {\n\t\t\tcompletionsWidth = thisCompletionWidth\n\t\t}\n\t}\n\n\t// Get the width and height of the autocomplete window\n\twidth := minInt(completionsWidth, maxWidth)\n\theight := minInt(len(completions), maxHeight)\n\n\tnewPos := viewPosition{\n\t\tx0: position{0, left},\n\t\ty0: position{0, top},\n\t\tx1: position{0, left + width + 1},\n\t\ty1: position{0, top + height + 1},\n\t}\n\n\tVIEW_POSITIONS[AUTOCOMPLETE_VIEW] = newPos\n\n\tp := VIEW_PROPERTIES[AUTOCOMPLETE_VIEW]\n\tp.text = strings.Join(completions, \"\\n\")\n\tVIEW_PROPERTIES[AUTOCOMPLETE_VIEW] = p\n\n\tif v, err := setView(g, AUTOCOMPLETE_VIEW); err != nil {\n\t\tif err != gocui.ErrUnknownView {\n\t\t\treturn\n\t\t}\n\t\tsetViewProperties(v, AUTOCOMPLETE_VIEW)\n\t\tv.BgColor = gocui.ColorBlue\n\t\tv.FgColor = gocui.ColorDefault\n\t\tg.SetViewOnTop(AUTOCOMPLETE_VIEW)\n\t}\n}\n\nfunc writeSortedHeaders(output io.Writer, h http.Header) {\n\thkeys := make([]string, 0, len(h))\n\tfor hname := range h {\n\t\thkeys = append(hkeys, hname)\n\t}\n\n\tsort.Strings(hkeys)\n\n\tfor _, hname := range hkeys {\n\t\tfmt.Fprintf(output, \"\\x1b[0;33m%v:\\x1b[0;0m %v\\n\", hname, strings.Join(h[hname], \",\"))\n\t}\n}\n\nfunc (a *App) SubmitRequest(g *gocui.Gui, _ *gocui.View) error {\n\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\tvrb.Clear()\n\tvrh, _ := g.View(RESPONSE_HEADERS_VIEW)\n\tvrh.Clear()\n\tpopup(g, \"Sending request..\")\n\n\tvar r *Request = &Request{}\n\n\tgo func(g *gocui.Gui, a *App, r *Request) error {\n\t\tdefer g.DeleteView(POPUP_VIEW)\n\t\t// parse url\n\t\tr.Url = getViewValue(g, URL_VIEW)\n\t\tu, err := url.Parse(r.Url)\n\t\tif err != nil {\n\t\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\t\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\t\t\t\tfmt.Fprintf(vrb, \"URL parse error: %v\", err)\n\t\t\t\treturn nil\n\t\t\t})\n\t\t\treturn nil\n\t\t}\n\n\t\tq, err := url.ParseQuery(strings.Replace(getViewValue(g, URL_PARAMS_VIEW), \"\\n\", \"&\", -1))\n\t\tif err != nil {\n\t\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\t\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\t\t\t\tfmt.Fprintf(vrb, \"Invalid GET parameters: %v\", err)\n\t\t\t\treturn nil\n\t\t\t})\n\t\t\treturn nil\n\t\t}\n\t\toriginalQuery := u.Query()\n\t\tfor k, v := range q {\n\t\t\tfor _, qp := range v {\n\t\t\t\toriginalQuery.Add(k, qp)\n\t\t\t}\n\t\t}\n\t\tu.RawQuery = originalQuery.Encode()\n\t\tr.GetParams = u.RawQuery\n\n\t\t// parse method\n\t\tr.Method = getViewValue(g, REQUEST_METHOD_VIEW)\n\n\t\t// set headers\n\t\theaders := http.Header{}\n\t\theaders.Set(\"User-Agent\", \"\")\n\t\tr.Headers = getViewValue(g, REQUEST_HEADERS_VIEW)\n\t\tfor _, header := range strings.Split(r.Headers, \"\\n\") {\n\t\t\tif header != \"\" {\n\t\t\t\theader_parts := strings.SplitN(header, \": \", 2)\n\t\t\t\tif len(header_parts) != 2 {\n\t\t\t\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\t\t\t\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\t\t\t\t\t\tfmt.Fprintf(vrb, \"Invalid header: %v\", header)\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t})\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\theaders.Set(header_parts[0], header_parts[1])\n\t\t\t}\n\t\t}\n\n\t\tvar body io.Reader\n\n\t\t// parse POST/PUT/PATCH data\n\t\tif r.Method == http.MethodPost || r.Method == http.MethodPut || r.Method == http.MethodPatch {\n\t\t\tbodyStr := getViewValue(g, REQUEST_DATA_VIEW)\n\t\t\tr.Data = bodyStr\n\t\t\tif headers.Get(\"Content-Type\") != \"multipart/form-data\" {\n\t\t\t\tif headers.Get(\"Content-Type\") == \"application/x-www-form-urlencoded\" {\n\t\t\t\t\tbodyStr = strings.Replace(bodyStr, \"\\n\", \"&\", -1)\n\t\t\t\t}\n\t\t\t\tbody = bytes.NewBufferString(bodyStr)\n\t\t\t} else {\n\t\t\t\tvar bodyBytes bytes.Buffer\n\t\t\t\tmultiWriter := multipart.NewWriter(&bodyBytes)\n\t\t\t\tdefer multiWriter.Close()\n\t\t\t\tpostData, err := url.ParseQuery(strings.Replace(getViewValue(g, REQUEST_DATA_VIEW), \"\\n\", \"&\", -1))\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tfor postKey, postValues := range postData {\n\t\t\t\t\tfor i := range postValues {\n\t\t\t\t\t\tif len([]rune(postValues[i])) > 0 && postValues[i][0] == '@' {\n\t\t\t\t\t\t\tfile, err := os.Open(postValues[i][1:])\n\t\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\t\t\t\t\t\t\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\t\t\t\t\t\t\t\t\tfmt.Fprintf(vrb, \"Error: %v\", err)\n\t\t\t\t\t\t\t\t\treturn nil\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tdefer file.Close()\n\t\t\t\t\t\t\tfw, err := multiWriter.CreateFormFile(postKey, path.Base(postValues[i][1:]))\n\t\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif _, err := io.Copy(fw, file); err != nil {\n\t\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tfw, err := multiWriter.CreateFormField(postKey)\n\t\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif _, err := fw.Write([]byte(postValues[i])); err != nil {\n\t\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbody = bytes.NewReader(bodyBytes.Bytes())\n\t\t\t}\n\t\t}\n\n\t\t// create request\n\t\treq, err := http.NewRequest(r.Method, u.String(), body)\n\t\tif err != nil {\n\t\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\t\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\t\t\t\tfmt.Fprintf(vrb, \"Request error: %v\", err)\n\t\t\t\treturn nil\n\t\t\t})\n\t\t\treturn nil\n\t\t}\n\t\treq.Header = headers\n\n\t\t// set the `Host` header\n\t\tif headers.Get(\"Host\") != \"\" {\n\t\t\treq.Host = headers.Get(\"Host\")\n\t\t}\n\n\t\t// do request\n\t\tstart := time.Now()\n\t\tresponse, err := CLIENT.Do(req)\n\t\tr.Duration = time.Since(start)\n\t\tif err != nil {\n\t\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\t\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\t\t\t\tfmt.Fprintf(vrb, \"Response error: %v\", err)\n\t\t\t\treturn nil\n\t\t\t})\n\t\t\treturn nil\n\t\t}\n\t\tdefer response.Body.Close()\n\n\t\t// extract body\n\t\tr.ContentType = response.Header.Get(\"Content-Type\")\n\t\tif response.Header.Get(\"Content-Encoding\") == \"gzip\" {\n\t\t\treader, err := gzip.NewReader(response.Body)\n\t\t\tif err == nil {\n\t\t\t\tdefer reader.Close()\n\t\t\t\tresponse.Body = reader\n\t\t\t} else {\n\t\t\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\t\t\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\t\t\t\t\tfmt.Fprintf(vrb, \"Cannot uncompress response: %v\", err)\n\t\t\t\t\treturn nil\n\t\t\t\t})\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\n\t\tbodyBytes, err := ioutil.ReadAll(response.Body)\n\t\tif err == nil {\n\t\t\tr.RawResponseBody = bodyBytes\n\t\t}\n\n\t\tr.Formatter = formatter.New(a.config, r.ContentType)\n\n\t\t// add to history\n\t\ta.history = append(a.history, r)\n\t\ta.historyIndex = len(a.history) - 1\n\n\t\t// render response\n\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\tvrh, _ := g.View(RESPONSE_HEADERS_VIEW)\n\n\t\t\ta.PrintBody(g)\n\n\t\t\t// print status code\n\t\t\tstatus_color := 32\n\t\t\tif response.StatusCode != 200 {\n\t\t\t\tstatus_color = 31\n\t\t\t}\n\t\t\theader := &strings.Builder{}\n\t\t\tfmt.Fprintf(\n\t\t\t\theader,\n\t\t\t\t\"\\x1b[0;%dmHTTP/1.1 %v %v\\x1b[0;0m\\n\",\n\t\t\t\tstatus_color,\n\t\t\t\tresponse.StatusCode,\n\t\t\t\thttp.StatusText(response.StatusCode),\n\t\t\t)\n\n\t\t\twriteSortedHeaders(header, response.Header)\n\n\t\t\t// According to the Go documentation, the Trailer maps trailer\n\t\t\t// keys to values in the same format as Header\n\t\t\twriteSortedHeaders(header, response.Trailer)\n\n\t\t\tr.ResponseHeaders = header.String()\n\n\t\t\tfmt.Fprint(vrh, r.ResponseHeaders)\n\t\t\tif _, err := vrh.Line(0); err != nil {\n\t\t\t\tvrh.SetOrigin(0, 0)\n\t\t\t}\n\n\t\t\treturn nil\n\t\t})\n\t\treturn nil\n\t}(g, a, r)\n\n\treturn nil\n}\n\nfunc (a *App) PrintBody(g *gocui.Gui) {\n\tg.Update(func(g *gocui.Gui) error {\n\t\tif len(a.history) == 0 {\n\t\t\treturn nil\n\t\t}\n\t\treq := a.history[a.historyIndex]\n\t\tif req.RawResponseBody == nil {\n\t\t\treturn nil\n\t\t}\n\t\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\t\tvrb.Clear()\n\n\t\tvar responseFormatter formatter.ResponseFormatter\n\t\tresponseFormatter = req.Formatter\n\n\t\tvrb.Title = VIEW_PROPERTIES[vrb.Name()].title + \" \" + responseFormatter.Title()\n\n\t\tsearch_text := getViewValue(g, \"search\")\n\t\tif search_text == \"\" || !responseFormatter.Searchable() {\n\t\t\terr := responseFormatter.Format(vrb, req.RawResponseBody)\n\t\t\tif err != nil {\n\t\t\t\tfmt.Fprintf(vrb, \"Error: cannot decode response body: %v\", err)\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tif _, err := vrb.Line(0); !a.config.General.PreserveScrollPosition || err != nil {\n\t\t\t\tvrb.SetOrigin(0, 0)\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\t\tif !a.config.General.ContextSpecificSearch {\n\t\t\tresponseFormatter = DEFAULT_FORMATTER\n\t\t}\n\t\tvrb.SetOrigin(0, 0)\n\t\tresults, err := responseFormatter.Search(search_text, req.RawResponseBody)\n\t\tif err != nil {\n\t\t\tfmt.Fprint(vrb, \"Search error: \", err)\n\t\t\treturn nil\n\t\t}\n\t\tif len(results) == 0 {\n\t\t\tvrb.Title = \"No results\"\n\t\t\tfmt.Fprint(vrb, \"Error: no results\")\n\t\t\treturn nil\n\t\t}\n\t\tvrb.Title = fmt.Sprintf(\"%d results\", len(results))\n\t\tfor _, result := range results {\n\t\t\tfmt.Fprintf(vrb, \"-----\\n%s\\n\", result)\n\t\t}\n\t\treturn nil\n\t})\n}\n\nfunc parseKey(k string) (interface{}, gocui.Modifier, error) {\n\tmod := gocui.ModNone\n\tif strings.Index(k, \"Alt\") == 0 {\n\t\tmod = gocui.ModAlt\n\t\tk = k[3:]\n\t}\n\tswitch len(k) {\n\tcase 0:\n\t\treturn 0, 0, errors.New(\"Empty key string\")\n\tcase 1:\n\t\tif mod != gocui.ModNone {\n\t\t\tk = strings.ToLower(k)\n\t\t}\n\t\treturn rune(k[0]), mod, nil\n\t}\n\n\tkey, found := KEYS[k]\n\tif !found {\n\t\treturn 0, 0, fmt.Errorf(\"Unknown key: %v\", k)\n\t}\n\treturn key, mod, nil\n}\n\nfunc (a *App) setKey(g *gocui.Gui, keyStr, commandStr, viewName string) error {\n\tif commandStr == \"\" {\n\t\treturn nil\n\t}\n\tkey, mod, err := parseKey(keyStr)\n\tif err != nil {\n\t\treturn err\n\t}\n\tcommandParts := strings.SplitN(commandStr, \" \", 2)\n\tcommand := commandParts[0]\n\tvar commandArgs string\n\tif len(commandParts) == 2 {\n\t\tcommandArgs = commandParts[1]\n\t}\n\tkeyFnGen, found := COMMANDS[command]\n\tif !found {\n\t\treturn fmt.Errorf(\"Unknown command: %v\", command)\n\t}\n\tkeyFn := keyFnGen(commandArgs, a)\n\tif err := g.SetKeybinding(viewName, key, mod, keyFn); err != nil {\n\t\treturn fmt.Errorf(\"Failed to set key '%v': %v\", keyStr, err)\n\t}\n\treturn nil\n}\n\nfunc (a *App) printViewKeybindings(v io.Writer, viewName string) {\n\tkeys, found := a.config.Keys[viewName]\n\tif !found {\n\t\treturn\n\t}\n\tmk := make([]string, len(keys))\n\ti := 0\n\tfor k := range keys {\n\t\tmk[i] = k\n\t\ti++\n\t}\n\tsort.Strings(mk)\n\tfmt.Fprintf(v, \"\\n %v\\n\", viewName)\n\tfor _, key := range mk {\n\t\tfmt.Fprintf(v, \"  %-15v %v\\n\", key, keys[key])\n\t}\n}\n\nfunc (a *App) SetKeys(g *gocui.Gui) error {\n\t// load config keybindings\n\tfor viewName, keys := range a.config.Keys {\n\t\tif viewName == \"global\" {\n\t\t\tviewName = ALL_VIEWS\n\t\t}\n\t\tfor keyStr, commandStr := range keys {\n\t\t\tif err := a.setKey(g, keyStr, commandStr, viewName); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\n\tg.SetKeybinding(ALL_VIEWS, gocui.KeyF1, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {\n\t\tif a.currentPopup == HELP_VIEW {\n\t\t\ta.closePopup(g, HELP_VIEW)\n\t\t\treturn nil\n\t\t}\n\n\t\thelp, err := a.CreatePopupView(HELP_VIEW, 60, 40, g)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\thelp.Title = VIEW_TITLES[HELP_VIEW]\n\t\thelp.Highlight = false\n\t\tfmt.Fprint(help, \"Keybindings:\\n\")\n\t\ta.printViewKeybindings(help, \"global\")\n\t\tfor _, viewName := range VIEWS {\n\t\t\tif _, found := a.config.Keys[viewName]; !found {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ta.printViewKeybindings(help, viewName)\n\t\t}\n\t\tg.SetViewOnTop(HELP_VIEW)\n\t\tg.SetCurrentView(HELP_VIEW)\n\t\treturn nil\n\t})\n\n\tg.SetKeybinding(ALL_VIEWS, gocui.KeyF11, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {\n\t\ta.config.General.FollowRedirects = !a.config.General.FollowRedirects\n\t\trefreshStatusLine(a, g)\n\t\treturn nil\n\t})\n\n\tg.SetKeybinding(ALL_VIEWS, gocui.KeyCtrlL, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {\n\t\tif a.currentPopup != \"\" {\n\t\t\treturn nil\n\t\t}\n\n\t\ta.restoreRequest(g, 0, true)\n\t\tg.SetCurrentView(URL_VIEW)\n\t\treturn nil\n\t})\n\n\tg.SetKeybinding(REQUEST_METHOD_VIEW, gocui.KeyEnter, gocui.ModNone, a.ToggleMethodList)\n\n\tcursDown := func(g *gocui.Gui, v *gocui.View) error {\n\t\tcx, cy := v.Cursor()\n\t\tv.SetCursor(cx, cy+1)\n\t\treturn nil\n\t}\n\tcursUp := func(g *gocui.Gui, v *gocui.View) error {\n\t\tcx, cy := v.Cursor()\n\t\tif cy > 0 {\n\t\t\tcy -= 1\n\t\t}\n\t\tv.SetCursor(cx, cy)\n\t\treturn nil\n\t}\n\t// history key bindings\n\tg.SetKeybinding(HISTORY_VIEW, gocui.KeyArrowDown, gocui.ModNone, cursDown)\n\tg.SetKeybinding(HISTORY_VIEW, gocui.KeyArrowUp, gocui.ModNone, cursUp)\n\tg.SetKeybinding(HISTORY_VIEW, gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {\n\t\t_, cy := v.Cursor()\n\t\t// TODO error\n\t\tif len(a.history) <= cy {\n\t\t\treturn nil\n\t\t}\n\t\ta.restoreRequest(g, cy, false)\n\t\treturn nil\n\t})\n\n\t// method key bindings\n\tg.SetKeybinding(REQUEST_METHOD_VIEW, gocui.KeyArrowDown, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {\n\t\tvalue := strings.TrimSpace(v.Buffer())\n\t\tfor i, val := range METHODS {\n\t\t\tif val == value && i != len(METHODS)-1 {\n\t\t\t\tsetViewTextAndCursor(v, METHODS[i+1])\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t})\n\n\tg.SetKeybinding(REQUEST_METHOD_VIEW, gocui.KeyArrowUp, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {\n\t\tvalue := strings.TrimSpace(v.Buffer())\n\t\tfor i, val := range METHODS {\n\t\t\tif val == value && i != 0 {\n\t\t\t\tsetViewTextAndCursor(v, METHODS[i-1])\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t})\n\tg.SetKeybinding(METHOD_LIST_VIEW, gocui.KeyArrowDown, gocui.ModNone, cursDown)\n\tg.SetKeybinding(METHOD_LIST_VIEW, gocui.KeyArrowUp, gocui.ModNone, cursUp)\n\tg.SetKeybinding(METHOD_LIST_VIEW, gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {\n\t\t_, cy := v.Cursor()\n\t\tv, _ = g.View(REQUEST_METHOD_VIEW)\n\t\tsetViewTextAndCursor(v, METHODS[cy])\n\t\ta.closePopup(g, METHOD_LIST_VIEW)\n\t\treturn nil\n\t})\n\tg.SetKeybinding(SAVE_REQUEST_FORMAT_DIALOG_VIEW, gocui.KeyArrowDown, gocui.ModNone, cursDown)\n\tg.SetKeybinding(SAVE_REQUEST_FORMAT_DIALOG_VIEW, gocui.KeyArrowUp, gocui.ModNone, cursUp)\n\n\tg.SetKeybinding(SAVE_DIALOG_VIEW, gocui.KeyCtrlQ, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {\n\t\ta.closePopup(g, SAVE_DIALOG_VIEW)\n\t\treturn nil\n\t})\n\n\tg.SetKeybinding(SAVE_RESULT_VIEW, gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {\n\t\ta.closePopup(g, SAVE_RESULT_VIEW)\n\t\treturn nil\n\t})\n\treturn nil\n}\n\nfunc (a *App) closePopup(g *gocui.Gui, viewname string) {\n\t_, err := g.View(viewname)\n\tif err == nil {\n\t\ta.currentPopup = \"\"\n\t\tg.DeleteView(viewname)\n\t\tg.SetCurrentView(VIEWS[a.viewIndex%len(VIEWS)])\n\t\tg.Cursor = true\n\t}\n}\n\n// CreatePopupView create a popup like view\nfunc (a *App) CreatePopupView(name string, width, height int, g *gocui.Gui) (v *gocui.View, err error) {\n\t// Remove any concurrent popup\n\ta.closePopup(g, a.currentPopup)\n\n\tg.Cursor = false\n\tmaxX, maxY := g.Size()\n\tif height > maxY-4 {\n\t\theight = maxY - 4\n\t}\n\tif width > maxX-4 {\n\t\twidth = maxX - 4\n\t}\n\tv, err = g.SetView(name, maxX/2-width/2-1, maxY/2-height/2-1, maxX/2+width/2, maxY/2+height/2+1, 0)\n\tif err != nil && err != gocui.ErrUnknownView {\n\t\treturn\n\t}\n\terr = nil\n\tv.Wrap = false\n\tv.Frame = true\n\tv.Highlight = true\n\tv.SelFgColor = gocui.ColorYellow\n\tv.SelBgColor = gocui.ColorDefault\n\ta.currentPopup = name\n\treturn\n}\n\nfunc (a *App) LoadRequest(g *gocui.Gui, loadLocation string) (err error) {\n\trequestJson, ioErr := ioutil.ReadFile(loadLocation)\n\tif ioErr != nil {\n\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\t\t\tvrb.Clear()\n\t\t\tfmt.Fprintf(vrb, \"File reading error: %v\", ioErr)\n\t\t\treturn nil\n\t\t})\n\t\treturn nil\n\t}\n\n\tvar requestMap map[string]string\n\tjsonErr := json.Unmarshal(requestJson, &requestMap)\n\tif jsonErr != nil {\n\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\tvrb, _ := g.View(RESPONSE_BODY_VIEW)\n\t\t\tvrb.Clear()\n\t\t\tfmt.Fprintf(vrb, \"JSON decoding error: %v\", jsonErr)\n\t\t\treturn nil\n\t\t})\n\t\treturn nil\n\t}\n\n\tvar v *gocui.View\n\turl, exists := requestMap[URL_VIEW]\n\tif exists {\n\t\tv, _ = g.View(URL_VIEW)\n\t\tsetViewTextAndCursor(v, url)\n\t}\n\n\tmethod, exists := requestMap[REQUEST_METHOD_VIEW]\n\tif exists {\n\t\tv, _ = g.View(REQUEST_METHOD_VIEW)\n\t\tsetViewTextAndCursor(v, method)\n\t}\n\n\tparams, exists := requestMap[URL_PARAMS_VIEW]\n\tif exists {\n\t\tv, _ = g.View(URL_PARAMS_VIEW)\n\t\tsetViewTextAndCursor(v, params)\n\t}\n\n\tdata, exists := requestMap[REQUEST_DATA_VIEW]\n\tif exists {\n\t\tg.Update(func(g *gocui.Gui) error {\n\t\t\tv, _ = g.View(REQUEST_DATA_VIEW)\n\t\t\tv.Clear()\n\t\t\tfmt.Fprintf(v, \"%v\", data)\n\t\t\treturn nil\n\t\t})\n\t}\n\n\theaders, exists := requestMap[REQUEST_HEADERS_VIEW]\n\tif exists {\n\t\tv, _ = g.View(REQUEST_HEADERS_VIEW)\n\t\tsetViewTextAndCursor(v, headers)\n\t}\n\treturn nil\n}\n\nfunc (a *App) ToggleHistory(g *gocui.Gui, _ *gocui.View) (err error) {\n\t// Destroy if present\n\tif a.currentPopup == HISTORY_VIEW {\n\t\ta.closePopup(g, HISTORY_VIEW)\n\t\treturn\n\t}\n\n\thistory, err := a.CreatePopupView(HISTORY_VIEW, 100, len(a.history), g)\n\tif err != nil {\n\t\treturn\n\t}\n\n\thistory.Title = VIEW_TITLES[HISTORY_VIEW]\n\n\tif len(a.history) == 0 {\n\t\tsetViewTextAndCursor(history, \"[!] No items in history\")\n\t\treturn\n\t}\n\tfor i, r := range a.history {\n\t\treq_str := fmt.Sprintf(\"[%02d] %v %v\", i, r.Method, r.Url)\n\t\tif r.GetParams != \"\" {\n\t\t\treq_str += fmt.Sprintf(\"?%v\", strings.Replace(r.GetParams, \"\\n\", \"&\", -1))\n\t\t}\n\t\tif r.Data != \"\" {\n\t\t\treq_str += fmt.Sprintf(\" %v\", strings.Replace(r.Data, \"\\n\", \"&\", -1))\n\t\t}\n\t\tif r.Headers != \"\" {\n\t\t\treq_str += fmt.Sprintf(\" %v\", strings.Replace(r.Headers, \"\\n\", \";\", -1))\n\t\t}\n\t\tfmt.Fprintln(history, req_str)\n\t}\n\tg.SetViewOnTop(HISTORY_VIEW)\n\tg.SetCurrentView(HISTORY_VIEW)\n\thistory.SetCursor(0, a.historyIndex)\n\treturn\n}\n\nfunc (a *App) SaveRequest(g *gocui.Gui, _ *gocui.View) (err error) {\n\t// Destroy if present\n\tif a.currentPopup == SAVE_REQUEST_FORMAT_DIALOG_VIEW {\n\t\ta.closePopup(g, SAVE_REQUEST_FORMAT_DIALOG_VIEW)\n\t\treturn\n\t}\n\t// Create the view listing the possible formats\n\tpopup, err := a.CreatePopupView(SAVE_REQUEST_FORMAT_DIALOG_VIEW, 30, len(EXPORT_FORMATS), g)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tpopup.Title = VIEW_TITLES[SAVE_REQUEST_FORMAT_DIALOG_VIEW]\n\n\t// Populate the popup with the available formats\n\tfor _, r := range EXPORT_FORMATS {\n\t\tfmt.Fprintln(popup, r.name)\n\t}\n\n\tg.SetViewOnTop(SAVE_REQUEST_FORMAT_DIALOG_VIEW)\n\tg.SetCurrentView(SAVE_REQUEST_FORMAT_DIALOG_VIEW)\n\tpopup.SetCursor(0, 0)\n\n\t// Bind the enter key, when the format is chosen, save the choice and open\n\t// the save popup\n\tg.SetKeybinding(SAVE_REQUEST_FORMAT_DIALOG_VIEW, gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {\n\t\t// Save the format index\n\t\t_, format := v.Cursor()\n\t\t// Open the Save popup\n\t\treturn a.OpenSaveDialog(VIEW_TITLES[SAVE_REQUEST_DIALOG_VIEW], g,\n\t\t\tfunc(g *gocui.Gui, _ *gocui.View) error {\n\t\t\t\tdefer a.closePopup(g, SAVE_DIALOG_VIEW)\n\t\t\t\tsaveLocation := getViewValue(g, SAVE_DIALOG_VIEW)\n\n\t\t\t\tr := Request{\n\t\t\t\t\tUrl:       getViewValue(g, URL_VIEW),\n\t\t\t\t\tMethod:    getViewValue(g, REQUEST_METHOD_VIEW),\n\t\t\t\t\tGetParams: getViewValue(g, URL_PARAMS_VIEW),\n\t\t\t\t\tData:      getViewValue(g, REQUEST_DATA_VIEW),\n\t\t\t\t\tHeaders:   getViewValue(g, REQUEST_HEADERS_VIEW),\n\t\t\t\t}\n\n\t\t\t\t// Export the request using the chosent format\n\t\t\t\trequest := EXPORT_FORMATS[format].export(r)\n\n\t\t\t\t// Write the file\n\t\t\t\tioerr := ioutil.WriteFile(saveLocation, []byte(request), 0644)\n\n\t\t\t\tsaveResult := fmt.Sprintf(\"Request saved successfully in %s\", EXPORT_FORMATS[format].name)\n\t\t\t\tif ioerr != nil {\n\t\t\t\t\tsaveResult = \"Error saving request: \" + ioerr.Error()\n\t\t\t\t}\n\t\t\t\tviewErr := a.OpenSaveResultView(saveResult, g)\n\n\t\t\t\treturn viewErr\n\t\t\t},\n\t\t)\n\t})\n\n\treturn\n}\n\nfunc (a *App) ToggleMethodList(g *gocui.Gui, _ *gocui.View) (err error) {\n\t// Destroy if present\n\tif a.currentPopup == METHOD_LIST_VIEW {\n\t\ta.closePopup(g, METHOD_LIST_VIEW)\n\t\treturn\n\t}\n\n\tmethod, err := a.CreatePopupView(METHOD_LIST_VIEW, 50, len(METHODS), g)\n\tif err != nil {\n\t\treturn\n\t}\n\tmethod.Title = VIEW_TITLES[METHOD_LIST_VIEW]\n\n\tcur := getViewValue(g, REQUEST_METHOD_VIEW)\n\n\tfor i, r := range METHODS {\n\t\tfmt.Fprintln(method, r)\n\t\tif cur == r {\n\t\t\tmethod.SetCursor(0, i)\n\t\t}\n\t}\n\tg.SetViewOnTop(METHOD_LIST_VIEW)\n\tg.SetCurrentView(METHOD_LIST_VIEW)\n\treturn\n}\n\nfunc (a *App) OpenSaveDialog(title string, g *gocui.Gui, save func(g *gocui.Gui, v *gocui.View) error) error {\n\tdialog, err := a.CreatePopupView(SAVE_DIALOG_VIEW, 60, 1, g)\n\tif err != nil {\n\t\treturn err\n\t}\n\tg.Cursor = true\n\n\tdialog.Title = title\n\tdialog.Editable = true\n\tdialog.Wrap = false\n\n\tcurrentDir, err := os.Getwd()\n\tif err != nil {\n\t\tcurrentDir = \"\"\n\t}\n\tcurrentDir += \"/\"\n\n\tsetViewTextAndCursor(dialog, currentDir)\n\n\tg.SetViewOnTop(SAVE_DIALOG_VIEW)\n\tg.SetCurrentView(SAVE_DIALOG_VIEW)\n\tdialog.SetCursor(0, len(currentDir))\n\tg.DeleteKeybinding(SAVE_DIALOG_VIEW, gocui.KeyEnter, gocui.ModNone)\n\tg.SetKeybinding(SAVE_DIALOG_VIEW, gocui.KeyEnter, gocui.ModNone, save)\n\treturn nil\n}\n\nfunc (a *App) OpenSaveResultView(saveResult string, g *gocui.Gui) (err error) {\n\tpopupTitle := VIEW_TITLES[SAVE_RESULT_VIEW]\n\tsaveResHeight := 1\n\tsaveResWidth := len(saveResult) + 1\n\tif len(popupTitle)+2 > saveResWidth {\n\t\tsaveResWidth = len(popupTitle) + 2\n\t}\n\tmaxX, _ := g.Size()\n\tif saveResWidth > maxX {\n\t\tsaveResHeight = saveResWidth/maxX + 1\n\t\tsaveResWidth = maxX\n\t}\n\n\tsaveResultPopup, err := a.CreatePopupView(SAVE_RESULT_VIEW, saveResWidth, saveResHeight, g)\n\tsaveResultPopup.Title = popupTitle\n\tsetViewTextAndCursor(saveResultPopup, saveResult)\n\tg.SetViewOnTop(SAVE_RESULT_VIEW)\n\tg.SetCurrentView(SAVE_RESULT_VIEW)\n\treturn err\n}\n\nfunc (a *App) restoreRequest(g *gocui.Gui, idx int, isCleanToggle bool) {\n\tif (idx < 0 || idx >= len(a.history)) && !isCleanToggle {\n\t\treturn\n\t}\n\tr := &Request{\n\t\tUrl:    fmt.Sprintf(\"%s://\", a.config.General.DefaultURLScheme),\n\t\tMethod: http.MethodGet,\n\t}\n\tif !isCleanToggle {\n\t\ta.closePopup(g, HISTORY_VIEW)\n\t\ta.historyIndex = idx\n\t\tr = a.history[idx]\n\t}\n\n\tv, _ := g.View(URL_VIEW)\n\tsetViewTextAndCursor(v, r.Url)\n\n\tv, _ = g.View(REQUEST_METHOD_VIEW)\n\tsetViewTextAndCursor(v, r.Method)\n\n\tv, _ = g.View(URL_PARAMS_VIEW)\n\tsetViewTextAndCursor(v, r.GetParams)\n\n\tv, _ = g.View(REQUEST_DATA_VIEW)\n\tsetViewTextAndCursor(v, r.Data)\n\n\tv, _ = g.View(REQUEST_HEADERS_VIEW)\n\tsetViewTextAndCursor(v, r.Headers)\n\n\tv, _ = g.View(RESPONSE_HEADERS_VIEW)\n\tsetViewTextAndCursor(v, r.ResponseHeaders)\n\n\tswitch isCleanToggle {\n\tcase true:\n\t\tv, _ = g.View(RESPONSE_BODY_VIEW)\n\t\tsetViewTextAndCursor(v, \"\")\n\tdefault:\n\t\ta.PrintBody(g)\n\t}\n}\n\nfunc (a *App) LoadConfig(configPath string) error {\n\tif configPath == \"\" {\n\t\t// Load config from default path\n\t\tconfigPath = config.GetDefaultConfigLocation()\n\t}\n\n\t// If the config file doesn't exist, load the default config\n\tif _, err := os.Stat(configPath); os.IsNotExist(err) {\n\t\ta.config = &config.DefaultConfig\n\t\ta.config.Keys = config.DefaultKeys\n\t\ta.statusLine, _ = NewStatusLine(a.config.General.StatusLine)\n\t\treturn nil\n\t}\n\n\tconf, err := config.LoadConfig(configPath)\n\tif err != nil {\n\t\ta.config = &config.DefaultConfig\n\t\ta.config.Keys = config.DefaultKeys\n\t\treturn err\n\t}\n\n\ta.config = conf\n\tsl, err := NewStatusLine(conf.General.StatusLine)\n\tif err != nil {\n\t\ta.config = &config.DefaultConfig\n\t\ta.config.Keys = config.DefaultKeys\n\t\treturn err\n\t}\n\ta.statusLine = sl\n\treturn nil\n}\n\nfunc (a *App) ParseArgs(g *gocui.Gui, args []string) error {\n\ta.Layout(g)\n\tg.SetCurrentView(VIEWS[a.viewIndex])\n\tvheader, err := g.View(REQUEST_HEADERS_VIEW)\n\tif err != nil {\n\t\treturn errors.New(\"Too small screen\")\n\t}\n\tvheader.Clear()\n\tvget, _ := g.View(URL_PARAMS_VIEW)\n\tvget.Clear()\n\tcontent_type := \"\"\n\tset_data := false\n\tset_method := false\n\tset_binary_data := false\n\targ_index := 1\n\targs_len := len(args)\n\taccept_types := make([]string, 0, 8)\n\tvar body_data []string\n\tfor arg_index < args_len {\n\t\targ := args[arg_index]\n\t\tswitch arg {\n\t\tcase \"-H\", \"--header\":\n\t\t\tif arg_index == args_len-1 {\n\t\t\t\treturn errors.New(\"No header value specified\")\n\t\t\t}\n\t\t\targ_index += 1\n\t\t\theader := args[arg_index]\n\t\t\tfmt.Fprintf(vheader, \"%v\\n\", header)\n\t\tcase \"-d\", \"--data\", \"--data-binary\", \"--data-urlencode\":\n\t\t\tif arg_index == args_len-1 {\n\t\t\t\treturn errors.New(\"No POST/PUT/PATCH value specified\")\n\t\t\t}\n\n\t\t\targ_index += 1\n\t\t\tset_data = true\n\t\t\tset_binary_data = arg == \"--data-binary\"\n\t\t\targ_data := args[arg_index]\n\n\t\t\tif !set_binary_data {\n\t\t\t\tcontent_type = \"form\"\n\t\t\t}\n\n\t\t\tif arg == \"--data-urlencode\" {\n\t\t\t\t// TODO: Replace with `url.PathEscape(..)` in Go 1.8\n\t\t\t\targ_data_url := &url.URL{Path: arg_data}\n\t\t\t\targ_data = arg_data_url.String()\n\t\t\t}\n\n\t\t\tbody_data = append(body_data, arg_data)\n\t\tcase \"-j\", \"--json\":\n\t\t\tif arg_index == args_len-1 {\n\t\t\t\treturn errors.New(\"No POST/PUT/PATCH value specified\")\n\t\t\t}\n\n\t\t\targ_index += 1\n\t\t\tjson_str := args[arg_index]\n\t\t\tcontent_type = \"json\"\n\t\t\taccept_types = append(accept_types, config.ContentTypes[\"json\"])\n\t\t\tset_data = true\n\t\t\tvdata, _ := g.View(REQUEST_DATA_VIEW)\n\t\t\tsetViewTextAndCursor(vdata, json_str)\n\t\tcase \"-X\", \"--request\":\n\t\t\tif arg_index == args_len-1 {\n\t\t\t\treturn errors.New(\"No HTTP method specified\")\n\t\t\t}\n\t\t\targ_index++\n\t\t\tset_method = true\n\t\t\tmethod := args[arg_index]\n\t\t\tif content_type == \"\" && (method == http.MethodPost || method == http.MethodPut || method == http.MethodPatch) {\n\t\t\t\tcontent_type = \"form\"\n\t\t\t}\n\t\t\tvmethod, _ := g.View(REQUEST_METHOD_VIEW)\n\t\t\tsetViewTextAndCursor(vmethod, method)\n\t\tcase \"-t\", \"--timeout\":\n\t\t\tif arg_index == args_len-1 {\n\t\t\t\treturn errors.New(\"No timeout value specified\")\n\t\t\t}\n\t\t\targ_index += 1\n\t\t\ttimeout, err := strconv.Atoi(args[arg_index])\n\t\t\tif err != nil || timeout <= 0 {\n\t\t\t\treturn errors.New(\"Invalid timeout value\")\n\t\t\t}\n\t\t\ta.config.General.Timeout = config.Duration{Duration: time.Duration(timeout) * time.Millisecond}\n\t\tcase \"--compressed\":\n\t\t\tvh, _ := g.View(REQUEST_HEADERS_VIEW)\n\t\t\tif !strings.Contains(getViewValue(g, REQUEST_HEADERS_VIEW), \"Accept-Encoding\") {\n\t\t\t\tfmt.Fprintln(vh, \"Accept-Encoding: gzip, deflate\")\n\t\t\t}\n\t\tcase \"-e\", \"--editor\":\n\t\t\tif arg_index == args_len-1 {\n\t\t\t\treturn errors.New(\"No timeout value specified\")\n\t\t\t}\n\t\t\targ_index += 1\n\t\t\ta.config.General.Editor = args[arg_index]\n\t\tcase \"-k\", \"--insecure\":\n\t\t\ta.config.General.Insecure = true\n\t\tcase \"-R\", \"--disable-redirects\":\n\t\t\ta.config.General.FollowRedirects = false\n\t\tcase \"--tlsv1.0\":\n\t\t\ta.config.General.TLSVersionMin = tls.VersionTLS10\n\t\t\ta.config.General.TLSVersionMax = tls.VersionTLS10\n\t\tcase \"--tlsv1.1\":\n\t\t\ta.config.General.TLSVersionMin = tls.VersionTLS11\n\t\t\ta.config.General.TLSVersionMax = tls.VersionTLS11\n\t\tcase \"--tlsv1.2\":\n\t\t\ta.config.General.TLSVersionMin = tls.VersionTLS12\n\t\t\ta.config.General.TLSVersionMax = tls.VersionTLS12\n\t\tcase \"-1\", \"--tlsv1\":\n\t\t\ta.config.General.TLSVersionMin = tls.VersionTLS10\n\t\t\ta.config.General.TLSVersionMax = tls.VersionTLS12\n\t\tcase \"-T\", \"--tls\":\n\t\t\tif arg_index >= args_len-1 {\n\t\t\t\treturn errors.New(\"Missing TLS version range: MIN,MAX\")\n\t\t\t}\n\t\t\targ_index++\n\t\t\targ := args[arg_index]\n\t\t\tv := strings.Split(arg, \",\")\n\t\t\tmin := v[0]\n\t\t\tmax := min\n\t\t\tif len(v) > 1 {\n\t\t\t\tmax = v[1]\n\t\t\t}\n\t\t\tminV, minFound := TLS_VERSIONS[min]\n\t\t\tif !minFound {\n\t\t\t\treturn errors.New(\"Minimum TLS version not found: \" + min)\n\t\t\t}\n\t\t\tmaxV, maxFound := TLS_VERSIONS[max]\n\t\t\tif !maxFound {\n\t\t\t\treturn errors.New(\"Maximum TLS version not found: \" + max)\n\t\t\t}\n\t\t\ta.config.General.TLSVersionMin = minV\n\t\t\ta.config.General.TLSVersionMax = maxV\n\t\tcase \"-x\", \"--proxy\":\n\t\t\tif arg_index == args_len-1 {\n\t\t\t\treturn errors.New(\"Missing proxy URL\")\n\t\t\t}\n\t\t\targ_index += 1\n\t\t\tu, err := url.Parse(args[arg_index])\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"Invalid proxy URL: %v\", err)\n\t\t\t}\n\t\t\tswitch u.Scheme {\n\t\t\tcase \"\", \"http\", \"https\":\n\t\t\t\tTRANSPORT.Proxy = http.ProxyURL(u)\n\t\t\tcase \"socks\", \"socks5\":\n\t\t\t\tdialer, err := proxy.SOCKS5(\"tcp\", u.Host, nil, proxy.Direct)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"Can't connect to proxy: %v\", err)\n\t\t\t\t}\n\t\t\t\tTRANSPORT.Dial = dialer.Dial\n\t\t\tdefault:\n\t\t\t\treturn errors.New(\"Unknown proxy protocol\")\n\t\t\t}\n\t\tcase \"-F\", \"--form\":\n\t\t\tif arg_index == args_len-1 {\n\t\t\t\treturn errors.New(\"No POST/PUT/PATCH value specified\")\n\t\t\t}\n\n\t\t\targ_index += 1\n\t\t\tform_str := args[arg_index]\n\t\t\tcontent_type = \"multipart\"\n\t\t\tset_data = true\n\t\t\tvdata, _ := g.View(REQUEST_DATA_VIEW)\n\t\t\tsetViewTextAndCursor(vdata, form_str)\n\t\tcase \"-f\", \"--file\":\n\t\t\tif arg_index == args_len-1 {\n\t\t\t\treturn errors.New(\"-f or --file requires a file path be provided as an argument\")\n\t\t\t}\n\t\t\targ_index += 1\n\t\t\tloadLocation := args[arg_index]\n\t\t\ta.LoadRequest(g, loadLocation)\n\t\tdefault:\n\t\t\tu := args[arg_index]\n\t\t\tif strings.Index(u, \"http://\") != 0 && strings.Index(u, \"https://\") != 0 {\n\t\t\t\tu = fmt.Sprintf(\"%v://%v\", a.config.General.DefaultURLScheme, u)\n\t\t\t}\n\t\t\tparsed_url, err := url.Parse(u)\n\t\t\tif err != nil || parsed_url.Host == \"\" {\n\t\t\t\treturn errors.New(\"Invalid url\")\n\t\t\t}\n\t\t\tif parsed_url.Path == \"\" {\n\t\t\t\tparsed_url.Path = \"/\"\n\t\t\t}\n\t\t\tvurl, _ := g.View(URL_VIEW)\n\t\t\tvurl.Clear()\n\t\t\tfor k, v := range parsed_url.Query() {\n\t\t\t\tfor _, vv := range v {\n\t\t\t\t\tfmt.Fprintf(vget, \"%v=%v\\n\", k, vv)\n\t\t\t\t}\n\t\t\t}\n\t\t\tparsed_url.RawQuery = \"\"\n\t\t\tsetViewTextAndCursor(vurl, parsed_url.String())\n\t\t}\n\t\targ_index += 1\n\t}\n\n\tif set_data && !set_method {\n\t\tvmethod, _ := g.View(REQUEST_METHOD_VIEW)\n\t\tsetViewTextAndCursor(vmethod, http.MethodPost)\n\t}\n\n\tif !set_binary_data && content_type != \"\" && !a.hasHeader(g, \"Content-Type\") {\n\t\tfmt.Fprintf(vheader, \"Content-Type: %v\\n\", config.ContentTypes[content_type])\n\t}\n\n\tif len(accept_types) > 0 && !a.hasHeader(g, \"Accept\") {\n\t\tfmt.Fprintf(vheader, \"Accept: %v\\n\", strings.Join(accept_types, \",\"))\n\t}\n\n\tvar merged_body_data string\n\tif set_data && !set_binary_data {\n\t\tmerged_body_data = strings.Join(body_data, \"&\")\n\t}\n\n\tvdata, _ := g.View(REQUEST_DATA_VIEW)\n\tsetViewTextAndCursor(vdata, merged_body_data)\n\n\treturn nil\n}\n\nfunc (a *App) hasHeader(g *gocui.Gui, h string) bool {\n\tfor _, header := range strings.Split(getViewValue(g, REQUEST_HEADERS_VIEW), \"\\n\") {\n\t\tif header == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\theader_parts := strings.SplitN(header, \": \", 2)\n\t\tif len(header_parts) != 2 {\n\t\t\tcontinue\n\t\t}\n\t\tif header_parts[0] == h {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n// Apply startup config values. This is run after a.ParseArgs, so that\n// args can override the provided config values\nfunc (a *App) InitConfig() {\n\tCLIENT.Timeout = a.config.General.Timeout.Duration\n\tTRANSPORT.TLSClientConfig = &tls.Config{\n\t\tInsecureSkipVerify: a.config.General.Insecure,\n\t\tMinVersion:         a.config.General.TLSVersionMin,\n\t\tMaxVersion:         a.config.General.TLSVersionMax,\n\t}\n\tCLIENT.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {\n\t\tif a.config.General.FollowRedirects {\n\t\t\treturn nil\n\t\t}\n\t\treturn http.ErrUseLastResponse\n\t}\n}\n\nfunc refreshStatusLine(a *App, g *gocui.Gui) {\n\tsv, _ := g.View(STATUSLINE_VIEW)\n\tsv.BgColor = gocui.ColorDefault | gocui.AttrReverse\n\tsv.FgColor = gocui.ColorDefault | gocui.AttrReverse\n\ta.statusLine.Update(sv, a)\n}\n\nfunc initApp(a *App, g *gocui.Gui) {\n\tg.Cursor = true\n\tg.InputEsc = false\n\tg.BgColor = gocui.ColorDefault\n\tg.FgColor = gocui.ColorDefault\n\tg.SetManagerFunc(a.Layout)\n}\n\nfunc getViewValue(g *gocui.Gui, name string) string {\n\tv, err := g.View(name)\n\tif err != nil {\n\t\treturn \"\"\n\t}\n\treturn strings.TrimSpace(v.Buffer())\n}\n\nfunc setViewDefaults(v *gocui.View) {\n\tv.Frame = true\n\tv.Wrap = false\n}\n\nfunc setViewTextAndCursor(v *gocui.View, s string) {\n\tv.Clear()\n\tfmt.Fprint(v, s)\n\tv.SetCursor(len(s), 0)\n}\n\nfunc help() {\n\tfmt.Println(`wuzz - Interactive cli tool for HTTP inspection\n\nUsage: wuzz [-H|--header HEADER]... [-d|--data|--data-binary DATA] [-X|--request METHOD] [-t|--timeout MSECS] [URL]\n\nOther command line options:\n  -c, --config PATH        Specify custom configuration file\n  -e, --editor EDITOR      Specify external editor command\n  -f, --file REQUEST       Load a previous request\n  -F, --form DATA          Add multipart form request data and set related request headers\n                           If the value starts with @ it will be handled as a file path for upload\n  -h, --help               Show this\n  -j, --json JSON          Add JSON request data and set related request headers\n  -k, --insecure           Allow insecure SSL certs\n  -R, --disable-redirects  Do not follow HTTP redirects\n  -T, --tls MIN,MAX        Restrict allowed TLS versions (values: SSL3.0,TLS1.0,TLS1.1,TLS1.2)\n                           Examples: wuzz -T TLS1.1        (TLS1.1 only)\n                                     wuzz -T TLS1.0,TLS1.1 (from TLS1.0 up to TLS1.1)\n  --tlsv1.0                Forces TLS1.0 only\n  --tlsv1.1                Forces TLS1.1 only\n  --tlsv1.2                Forces TLS1.2 only\n  -1, --tlsv1              Forces TLS version 1.x (1.0, 1.1 or 1.2)\n  -v, --version            Display version number\n  -x, --proxy URL          Set HTTP(S) or SOCKS5 proxy\n\nKey bindings:\n  ctrl+r              Send request\n  ctrl+s              Save response\n  ctrl+e              Save request\n  ctrl+f              Load request\n  tab, ctrl+j         Next window\n  shift+tab, ctrl+k   Previous window\n  alt+h               Show history\n  pageUp              Scroll up the current window\n  pageDown            Scroll down the current window`,\n\t)\n}\n\nfunc main() {\n\tconfigPath := \"\"\n\targs := os.Args\n\tfor i, arg := range os.Args {\n\t\tswitch arg {\n\t\tcase \"-h\", \"--help\":\n\t\t\thelp()\n\t\t\treturn\n\t\tcase \"-v\", \"--version\":\n\t\t\tfmt.Printf(\"wuzz %v\\n\", VERSION)\n\t\t\treturn\n\t\tcase \"-c\", \"--config\":\n\t\t\tconfigPath = os.Args[i+1]\n\t\t\targs = append(os.Args[:i], os.Args[i+2:]...)\n\t\t\tif _, err := os.Stat(configPath); os.IsNotExist(err) {\n\t\t\t\tlog.Fatal(\"Config file specified but does not exist: \\\"\" + configPath + \"\\\"\")\n\t\t\t}\n\t\t}\n\t}\n\tvar g *gocui.Gui\n\tvar err error\n\tfor _, outputMode := range []gocui.OutputMode{gocui.Output256, gocui.OutputNormal} {\n\t\tg, err = gocui.NewGui(outputMode, true)\n\t\tif err == nil {\n\t\t\tbreak\n\t\t}\n\t}\n\tif err != nil {\n\t\tlog.Panicln(err)\n\t}\n\n\tif runtime.GOOS == WINDOWS_OS && runewidth.IsEastAsian() {\n\t\tg.ASCII = true\n\t}\n\n\tapp := &App{history: make([]*Request, 0, 31)}\n\n\t// overwrite default editor\n\tdefaultEditor = ViewEditor{app, g, false, gocui.DefaultEditor}\n\n\tinitApp(app, g)\n\n\t// load config (must be done *before* app.ParseArgs, as arguments\n\t// should be able to override config values). An empty string passed\n\t// to LoadConfig results in LoadConfig loading the default config\n\t// location. If there is no config, the values in\n\t// config.DefaultConfig will be used.\n\terr = app.LoadConfig(configPath)\n\tif err != nil {\n\t\tg.Close()\n\t\tlog.Fatalf(\"Error loading config file: %v\", err)\n\t}\n\n\terr = app.ParseArgs(g, args)\n\n\t// Some of the values in the config need to have some startup\n\t// behavior associated with them. This is run after ParseArgs so\n\t// that command-line arguments can override configuration values.\n\tapp.InitConfig()\n\n\tif err != nil {\n\t\tg.Close()\n\t\tfmt.Println(\"Error!\", err)\n\t\tos.Exit(1)\n\t}\n\n\terr = app.SetKeys(g)\n\n\tif err != nil {\n\t\tg.Close()\n\t\tfmt.Println(\"Error!\", err)\n\t\tos.Exit(1)\n\t}\n\n\tdefer g.Close()\n\n\tif err := g.MainLoop(); err != nil && err != gocui.ErrQuit {\n\t\tlog.Panicln(err)\n\t}\n}\n\nfunc exportJSON(r Request) []byte {\n\trequestMap := map[string]string{\n\t\tURL_VIEW:             r.Url,\n\t\tREQUEST_METHOD_VIEW:  r.Method,\n\t\tURL_PARAMS_VIEW:      r.GetParams,\n\t\tREQUEST_DATA_VIEW:    r.Data,\n\t\tREQUEST_HEADERS_VIEW: r.Headers,\n\t}\n\n\trequest, err := json.Marshal(requestMap)\n\tif err != nil {\n\t\treturn []byte{}\n\t}\n\treturn request\n}\n\nfunc exportCurl(r Request) []byte {\n\tvar headers, params string\n\tfor _, header := range strings.Split(r.Headers, \"\\n\") {\n\t\tif header == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\theaders = fmt.Sprintf(\"%s -H %s\", headers, shellescape.Quote(header))\n\t}\n\tif r.GetParams != \"\" {\n\t\tparams = fmt.Sprintf(\"?%s\", r.GetParams)\n\t}\n\treturn []byte(fmt.Sprintf(\"curl %s -X %s -d %s %s\\n\", headers, r.Method, shellescape.Quote(r.Data), shellescape.Quote(r.Url+params)))\n}\n"
  }
]