mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
misc: updated dependencies
This commit is contained in:
parent
696c056b56
commit
c0d3c314fc
70 changed files with 6328 additions and 1494 deletions
10
vendor/github.com/evilsocket/islazy/ops/base.go
generated
vendored
Normal file
10
vendor/github.com/evilsocket/islazy/ops/base.go
generated
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
package ops
|
||||
|
||||
// Ternary is the standard ternary operator which returns posVal
|
||||
// if the boolean condition is true, otherwise negVal.
|
||||
func Ternary(cond bool, posVal interface{}, negVal interface{}) interface{} {
|
||||
if cond {
|
||||
return posVal
|
||||
}
|
||||
return negVal
|
||||
}
|
2
vendor/github.com/evilsocket/islazy/ops/doc.go
generated
vendored
Normal file
2
vendor/github.com/evilsocket/islazy/ops/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
// Package ops contains helper operators.
|
||||
package ops
|
19
vendor/github.com/gorilla/context/.travis.yml
generated
vendored
19
vendor/github.com/gorilla/context/.travis.yml
generated
vendored
|
@ -1,19 +0,0 @@
|
|||
language: go
|
||||
sudo: false
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- go: 1.3
|
||||
- go: 1.4
|
||||
- go: 1.5
|
||||
- go: 1.6
|
||||
- go: 1.7
|
||||
- go: tip
|
||||
allow_failures:
|
||||
- go: tip
|
||||
|
||||
script:
|
||||
- go get -t -v ./...
|
||||
- diff -u <(echo -n) <(gofmt -d .)
|
||||
- go vet $(go list ./... | grep -v /vendor/)
|
||||
- go test -v -race ./...
|
27
vendor/github.com/gorilla/context/LICENSE
generated
vendored
27
vendor/github.com/gorilla/context/LICENSE
generated
vendored
|
@ -1,27 +0,0 @@
|
|||
Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
10
vendor/github.com/gorilla/context/README.md
generated
vendored
10
vendor/github.com/gorilla/context/README.md
generated
vendored
|
@ -1,10 +0,0 @@
|
|||
context
|
||||
=======
|
||||
[](https://travis-ci.org/gorilla/context)
|
||||
|
||||
gorilla/context is a general purpose registry for global request variables.
|
||||
|
||||
> Note: gorilla/context, having been born well before `context.Context` existed, does not play well
|
||||
> with the shallow copying of the request that [`http.Request.WithContext`](https://golang.org/pkg/net/http/#Request.WithContext) (added to net/http Go 1.7 onwards) performs. You should either use *just* gorilla/context, or moving forward, the new `http.Request.Context()`.
|
||||
|
||||
Read the full documentation here: http://www.gorillatoolkit.org/pkg/context
|
143
vendor/github.com/gorilla/context/context.go
generated
vendored
143
vendor/github.com/gorilla/context/context.go
generated
vendored
|
@ -1,143 +0,0 @@
|
|||
// Copyright 2012 The Gorilla Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package context
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
mutex sync.RWMutex
|
||||
data = make(map[*http.Request]map[interface{}]interface{})
|
||||
datat = make(map[*http.Request]int64)
|
||||
)
|
||||
|
||||
// Set stores a value for a given key in a given request.
|
||||
func Set(r *http.Request, key, val interface{}) {
|
||||
mutex.Lock()
|
||||
if data[r] == nil {
|
||||
data[r] = make(map[interface{}]interface{})
|
||||
datat[r] = time.Now().Unix()
|
||||
}
|
||||
data[r][key] = val
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
||||
// Get returns a value stored for a given key in a given request.
|
||||
func Get(r *http.Request, key interface{}) interface{} {
|
||||
mutex.RLock()
|
||||
if ctx := data[r]; ctx != nil {
|
||||
value := ctx[key]
|
||||
mutex.RUnlock()
|
||||
return value
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOk returns stored value and presence state like multi-value return of map access.
|
||||
func GetOk(r *http.Request, key interface{}) (interface{}, bool) {
|
||||
mutex.RLock()
|
||||
if _, ok := data[r]; ok {
|
||||
value, ok := data[r][key]
|
||||
mutex.RUnlock()
|
||||
return value, ok
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// GetAll returns all stored values for the request as a map. Nil is returned for invalid requests.
|
||||
func GetAll(r *http.Request) map[interface{}]interface{} {
|
||||
mutex.RLock()
|
||||
if context, ok := data[r]; ok {
|
||||
result := make(map[interface{}]interface{}, len(context))
|
||||
for k, v := range context {
|
||||
result[k] = v
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return result
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAllOk returns all stored values for the request as a map and a boolean value that indicates if
|
||||
// the request was registered.
|
||||
func GetAllOk(r *http.Request) (map[interface{}]interface{}, bool) {
|
||||
mutex.RLock()
|
||||
context, ok := data[r]
|
||||
result := make(map[interface{}]interface{}, len(context))
|
||||
for k, v := range context {
|
||||
result[k] = v
|
||||
}
|
||||
mutex.RUnlock()
|
||||
return result, ok
|
||||
}
|
||||
|
||||
// Delete removes a value stored for a given key in a given request.
|
||||
func Delete(r *http.Request, key interface{}) {
|
||||
mutex.Lock()
|
||||
if data[r] != nil {
|
||||
delete(data[r], key)
|
||||
}
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
||||
// Clear removes all values stored for a given request.
|
||||
//
|
||||
// This is usually called by a handler wrapper to clean up request
|
||||
// variables at the end of a request lifetime. See ClearHandler().
|
||||
func Clear(r *http.Request) {
|
||||
mutex.Lock()
|
||||
clear(r)
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
||||
// clear is Clear without the lock.
|
||||
func clear(r *http.Request) {
|
||||
delete(data, r)
|
||||
delete(datat, r)
|
||||
}
|
||||
|
||||
// Purge removes request data stored for longer than maxAge, in seconds.
|
||||
// It returns the amount of requests removed.
|
||||
//
|
||||
// If maxAge <= 0, all request data is removed.
|
||||
//
|
||||
// This is only used for sanity check: in case context cleaning was not
|
||||
// properly set some request data can be kept forever, consuming an increasing
|
||||
// amount of memory. In case this is detected, Purge() must be called
|
||||
// periodically until the problem is fixed.
|
||||
func Purge(maxAge int) int {
|
||||
mutex.Lock()
|
||||
count := 0
|
||||
if maxAge <= 0 {
|
||||
count = len(data)
|
||||
data = make(map[*http.Request]map[interface{}]interface{})
|
||||
datat = make(map[*http.Request]int64)
|
||||
} else {
|
||||
min := time.Now().Unix() - int64(maxAge)
|
||||
for r := range data {
|
||||
if datat[r] < min {
|
||||
clear(r)
|
||||
count++
|
||||
}
|
||||
}
|
||||
}
|
||||
mutex.Unlock()
|
||||
return count
|
||||
}
|
||||
|
||||
// ClearHandler wraps an http.Handler and clears request values at the end
|
||||
// of a request lifetime.
|
||||
func ClearHandler(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer Clear(r)
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
88
vendor/github.com/gorilla/context/doc.go
generated
vendored
88
vendor/github.com/gorilla/context/doc.go
generated
vendored
|
@ -1,88 +0,0 @@
|
|||
// Copyright 2012 The Gorilla Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
/*
|
||||
Package context stores values shared during a request lifetime.
|
||||
|
||||
Note: gorilla/context, having been born well before `context.Context` existed,
|
||||
does not play well > with the shallow copying of the request that
|
||||
[`http.Request.WithContext`](https://golang.org/pkg/net/http/#Request.WithContext)
|
||||
(added to net/http Go 1.7 onwards) performs. You should either use *just*
|
||||
gorilla/context, or moving forward, the new `http.Request.Context()`.
|
||||
|
||||
For example, a router can set variables extracted from the URL and later
|
||||
application handlers can access those values, or it can be used to store
|
||||
sessions values to be saved at the end of a request. There are several
|
||||
others common uses.
|
||||
|
||||
The idea was posted by Brad Fitzpatrick to the go-nuts mailing list:
|
||||
|
||||
http://groups.google.com/group/golang-nuts/msg/e2d679d303aa5d53
|
||||
|
||||
Here's the basic usage: first define the keys that you will need. The key
|
||||
type is interface{} so a key can be of any type that supports equality.
|
||||
Here we define a key using a custom int type to avoid name collisions:
|
||||
|
||||
package foo
|
||||
|
||||
import (
|
||||
"github.com/gorilla/context"
|
||||
)
|
||||
|
||||
type key int
|
||||
|
||||
const MyKey key = 0
|
||||
|
||||
Then set a variable. Variables are bound to an http.Request object, so you
|
||||
need a request instance to set a value:
|
||||
|
||||
context.Set(r, MyKey, "bar")
|
||||
|
||||
The application can later access the variable using the same key you provided:
|
||||
|
||||
func MyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// val is "bar".
|
||||
val := context.Get(r, foo.MyKey)
|
||||
|
||||
// returns ("bar", true)
|
||||
val, ok := context.GetOk(r, foo.MyKey)
|
||||
// ...
|
||||
}
|
||||
|
||||
And that's all about the basic usage. We discuss some other ideas below.
|
||||
|
||||
Any type can be stored in the context. To enforce a given type, make the key
|
||||
private and wrap Get() and Set() to accept and return values of a specific
|
||||
type:
|
||||
|
||||
type key int
|
||||
|
||||
const mykey key = 0
|
||||
|
||||
// GetMyKey returns a value for this package from the request values.
|
||||
func GetMyKey(r *http.Request) SomeType {
|
||||
if rv := context.Get(r, mykey); rv != nil {
|
||||
return rv.(SomeType)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetMyKey sets a value for this package in the request values.
|
||||
func SetMyKey(r *http.Request, val SomeType) {
|
||||
context.Set(r, mykey, val)
|
||||
}
|
||||
|
||||
Variables must be cleared at the end of a request, to remove all values
|
||||
that were stored. This can be done in an http.Handler, after a request was
|
||||
served. Just call Clear() passing the request:
|
||||
|
||||
context.Clear(r)
|
||||
|
||||
...or use ClearHandler(), which conveniently wraps an http.Handler to clear
|
||||
variables at the end of a request lifetime.
|
||||
|
||||
The Routers from the packages gorilla/mux and gorilla/pat call Clear()
|
||||
so if you are using either of them you don't need to clear the context manually.
|
||||
*/
|
||||
package context
|
7
vendor/github.com/gorilla/mux/.travis.yml
generated
vendored
7
vendor/github.com/gorilla/mux/.travis.yml
generated
vendored
|
@ -3,12 +3,13 @@ sudo: false
|
|||
|
||||
matrix:
|
||||
include:
|
||||
- go: 1.5.x
|
||||
- go: 1.6.x
|
||||
- go: 1.7.x
|
||||
- go: 1.8.x
|
||||
- go: 1.9.x
|
||||
- go: 1.10.x
|
||||
- go: 1.11.x
|
||||
- go: 1.x
|
||||
env: LATEST=true
|
||||
- go: tip
|
||||
allow_failures:
|
||||
- go: tip
|
||||
|
@ -19,5 +20,5 @@ install:
|
|||
script:
|
||||
- go get -t -v ./...
|
||||
- diff -u <(echo -n) <(gofmt -d .)
|
||||
- go tool vet .
|
||||
- if [[ "$LATEST" = true ]]; then go tool vet .; fi
|
||||
- go test -v -race ./...
|
||||
|
|
8
vendor/github.com/gorilla/mux/AUTHORS
generated
vendored
Normal file
8
vendor/github.com/gorilla/mux/AUTHORS
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
# This is the official list of gorilla/mux authors for copyright purposes.
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
Google LLC (https://opensource.google.com/)
|
||||
Kamil Kisielk <kamil@kamilkisiel.net>
|
||||
Matt Silverlock <matt@eatsleeprepeat.net>
|
||||
Rodrigo Moraes (https://github.com/moraes)
|
2
vendor/github.com/gorilla/mux/LICENSE
generated
vendored
2
vendor/github.com/gorilla/mux/LICENSE
generated
vendored
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
|
||||
Copyright (c) 2012-2018 The Gorilla Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
|
|
16
vendor/github.com/gorilla/mux/README.md
generated
vendored
16
vendor/github.com/gorilla/mux/README.md
generated
vendored
|
@ -6,7 +6,7 @@
|
|||
|
||||

|
||||
|
||||
http://www.gorillatoolkit.org/pkg/mux
|
||||
https://www.gorillatoolkit.org/pkg/mux
|
||||
|
||||
Package `gorilla/mux` implements a request router and dispatcher for matching incoming requests to
|
||||
their respective handler.
|
||||
|
@ -88,7 +88,7 @@ r := mux.NewRouter()
|
|||
// Only matches if domain is "www.example.com".
|
||||
r.Host("www.example.com")
|
||||
// Matches a dynamic subdomain.
|
||||
r.Host("{subdomain:[a-z]+}.domain.com")
|
||||
r.Host("{subdomain:[a-z]+}.example.com")
|
||||
```
|
||||
|
||||
There are several other matchers that can be added. To match path prefixes:
|
||||
|
@ -238,13 +238,13 @@ This also works for host and query value variables:
|
|||
|
||||
```go
|
||||
r := mux.NewRouter()
|
||||
r.Host("{subdomain}.domain.com").
|
||||
r.Host("{subdomain}.example.com").
|
||||
Path("/articles/{category}/{id:[0-9]+}").
|
||||
Queries("filter", "{filter}").
|
||||
HandlerFunc(ArticleHandler).
|
||||
Name("article")
|
||||
|
||||
// url.String() will be "http://news.domain.com/articles/technology/42?filter=gorilla"
|
||||
// url.String() will be "http://news.example.com/articles/technology/42?filter=gorilla"
|
||||
url, err := r.Get("article").URL("subdomain", "news",
|
||||
"category", "technology",
|
||||
"id", "42",
|
||||
|
@ -264,7 +264,7 @@ r.HeadersRegexp("Content-Type", "application/(text|json)")
|
|||
There's also a way to build only the URL host or path for a route: use the methods `URLHost()` or `URLPath()` instead. For the previous route, we would do:
|
||||
|
||||
```go
|
||||
// "http://news.domain.com/"
|
||||
// "http://news.example.com/"
|
||||
host, err := r.Get("article").URLHost("subdomain", "news")
|
||||
|
||||
// "/articles/technology/42"
|
||||
|
@ -275,12 +275,12 @@ And if you use subrouters, host and path defined separately can be built as well
|
|||
|
||||
```go
|
||||
r := mux.NewRouter()
|
||||
s := r.Host("{subdomain}.domain.com").Subrouter()
|
||||
s := r.Host("{subdomain}.example.com").Subrouter()
|
||||
s.Path("/articles/{category}/{id:[0-9]+}").
|
||||
HandlerFunc(ArticleHandler).
|
||||
Name("article")
|
||||
|
||||
// "http://news.domain.com/articles/technology/42"
|
||||
// "http://news.example.com/articles/technology/42"
|
||||
url, err := r.Get("article").URL("subdomain", "news",
|
||||
"category", "technology",
|
||||
"id", "42")
|
||||
|
@ -503,8 +503,8 @@ package main
|
|||
|
||||
func HealthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// A very simple health check.
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
// In the future we could report back on the status of our DB, or our cache
|
||||
// (e.g. Redis) by performing a simple PING, and include them in the response.
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build go1.7
|
||||
|
||||
package mux
|
||||
|
||||
import (
|
||||
|
@ -18,7 +16,3 @@ func contextSet(r *http.Request, key, val interface{}) *http.Request {
|
|||
|
||||
return r.WithContext(context.WithValue(r.Context(), key, val))
|
||||
}
|
||||
|
||||
func contextClear(r *http.Request) {
|
||||
return
|
||||
}
|
26
vendor/github.com/gorilla/mux/context_gorilla.go
generated
vendored
26
vendor/github.com/gorilla/mux/context_gorilla.go
generated
vendored
|
@ -1,26 +0,0 @@
|
|||
// +build !go1.7
|
||||
|
||||
package mux
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/context"
|
||||
)
|
||||
|
||||
func contextGet(r *http.Request, key interface{}) interface{} {
|
||||
return context.Get(r, key)
|
||||
}
|
||||
|
||||
func contextSet(r *http.Request, key, val interface{}) *http.Request {
|
||||
if val == nil {
|
||||
return r
|
||||
}
|
||||
|
||||
context.Set(r, key, val)
|
||||
return r
|
||||
}
|
||||
|
||||
func contextClear(r *http.Request) {
|
||||
context.Clear(r)
|
||||
}
|
1
vendor/github.com/gorilla/mux/go.mod
generated
vendored
Normal file
1
vendor/github.com/gorilla/mux/go.mod
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
module github.com/gorilla/mux
|
123
vendor/github.com/gorilla/mux/mux.go
generated
vendored
123
vendor/github.com/gorilla/mux/mux.go
generated
vendored
|
@ -22,7 +22,7 @@ var (
|
|||
|
||||
// NewRouter returns a new router instance.
|
||||
func NewRouter() *Router {
|
||||
return &Router{namedRoutes: make(map[string]*Route), KeepContext: false}
|
||||
return &Router{namedRoutes: make(map[string]*Route)}
|
||||
}
|
||||
|
||||
// Router registers routes to be matched and dispatches a handler.
|
||||
|
@ -50,24 +50,78 @@ type Router struct {
|
|||
// Configurable Handler to be used when the request method does not match the route.
|
||||
MethodNotAllowedHandler http.Handler
|
||||
|
||||
// Parent route, if this is a subrouter.
|
||||
parent parentRoute
|
||||
// Routes to be matched, in order.
|
||||
routes []*Route
|
||||
|
||||
// Routes by name for URL building.
|
||||
namedRoutes map[string]*Route
|
||||
// See Router.StrictSlash(). This defines the flag for new routes.
|
||||
strictSlash bool
|
||||
// See Router.SkipClean(). This defines the flag for new routes.
|
||||
skipClean bool
|
||||
|
||||
// If true, do not clear the request context after handling the request.
|
||||
// This has no effect when go1.7+ is used, since the context is stored
|
||||
//
|
||||
// Deprecated: No effect when go1.7+ is used, since the context is stored
|
||||
// on the request itself.
|
||||
KeepContext bool
|
||||
// see Router.UseEncodedPath(). This defines a flag for all routes.
|
||||
useEncodedPath bool
|
||||
|
||||
// Slice of middlewares to be called after a match is found
|
||||
middlewares []middleware
|
||||
|
||||
// configuration shared with `Route`
|
||||
routeConf
|
||||
}
|
||||
|
||||
// common route configuration shared between `Router` and `Route`
|
||||
type routeConf struct {
|
||||
// If true, "/path/foo%2Fbar/to" will match the path "/path/{var}/to"
|
||||
useEncodedPath bool
|
||||
|
||||
// If true, when the path pattern is "/path/", accessing "/path" will
|
||||
// redirect to the former and vice versa.
|
||||
strictSlash bool
|
||||
|
||||
// If true, when the path pattern is "/path//to", accessing "/path//to"
|
||||
// will not redirect
|
||||
skipClean bool
|
||||
|
||||
// Manager for the variables from host and path.
|
||||
regexp routeRegexpGroup
|
||||
|
||||
// List of matchers.
|
||||
matchers []matcher
|
||||
|
||||
// The scheme used when building URLs.
|
||||
buildScheme string
|
||||
|
||||
buildVarsFunc BuildVarsFunc
|
||||
}
|
||||
|
||||
// returns an effective deep copy of `routeConf`
|
||||
func copyRouteConf(r routeConf) routeConf {
|
||||
c := r
|
||||
|
||||
if r.regexp.path != nil {
|
||||
c.regexp.path = copyRouteRegexp(r.regexp.path)
|
||||
}
|
||||
|
||||
if r.regexp.host != nil {
|
||||
c.regexp.host = copyRouteRegexp(r.regexp.host)
|
||||
}
|
||||
|
||||
c.regexp.queries = make([]*routeRegexp, 0, len(r.regexp.queries))
|
||||
for _, q := range r.regexp.queries {
|
||||
c.regexp.queries = append(c.regexp.queries, copyRouteRegexp(q))
|
||||
}
|
||||
|
||||
c.matchers = make([]matcher, 0, len(r.matchers))
|
||||
for _, m := range r.matchers {
|
||||
c.matchers = append(c.matchers, m)
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func copyRouteRegexp(r *routeRegexp) *routeRegexp {
|
||||
c := *r
|
||||
return &c
|
||||
}
|
||||
|
||||
// Match attempts to match the given request against the router's registered routes.
|
||||
|
@ -155,22 +209,18 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
handler = http.NotFoundHandler()
|
||||
}
|
||||
|
||||
if !r.KeepContext {
|
||||
defer contextClear(req)
|
||||
}
|
||||
|
||||
handler.ServeHTTP(w, req)
|
||||
}
|
||||
|
||||
// Get returns a route registered with the given name.
|
||||
func (r *Router) Get(name string) *Route {
|
||||
return r.getNamedRoutes()[name]
|
||||
return r.namedRoutes[name]
|
||||
}
|
||||
|
||||
// GetRoute returns a route registered with the given name. This method
|
||||
// was renamed to Get() and remains here for backwards compatibility.
|
||||
func (r *Router) GetRoute(name string) *Route {
|
||||
return r.getNamedRoutes()[name]
|
||||
return r.namedRoutes[name]
|
||||
}
|
||||
|
||||
// StrictSlash defines the trailing slash behavior for new routes. The initial
|
||||
|
@ -221,51 +271,14 @@ func (r *Router) UseEncodedPath() *Router {
|
|||
return r
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// parentRoute
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
func (r *Router) getBuildScheme() string {
|
||||
if r.parent != nil {
|
||||
return r.parent.getBuildScheme()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// getNamedRoutes returns the map where named routes are registered.
|
||||
func (r *Router) getNamedRoutes() map[string]*Route {
|
||||
if r.namedRoutes == nil {
|
||||
if r.parent != nil {
|
||||
r.namedRoutes = r.parent.getNamedRoutes()
|
||||
} else {
|
||||
r.namedRoutes = make(map[string]*Route)
|
||||
}
|
||||
}
|
||||
return r.namedRoutes
|
||||
}
|
||||
|
||||
// getRegexpGroup returns regexp definitions from the parent route, if any.
|
||||
func (r *Router) getRegexpGroup() *routeRegexpGroup {
|
||||
if r.parent != nil {
|
||||
return r.parent.getRegexpGroup()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Router) buildVars(m map[string]string) map[string]string {
|
||||
if r.parent != nil {
|
||||
m = r.parent.buildVars(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Route factories
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// NewRoute registers an empty route.
|
||||
func (r *Router) NewRoute() *Route {
|
||||
route := &Route{parent: r, strictSlash: r.strictSlash, skipClean: r.skipClean, useEncodedPath: r.useEncodedPath}
|
||||
// initialize a route with a copy of the parent router's configuration
|
||||
route := &Route{routeConf: copyRouteConf(r.routeConf), namedRoutes: r.namedRoutes}
|
||||
r.routes = append(r.routes, route)
|
||||
return route
|
||||
}
|
||||
|
|
14
vendor/github.com/gorilla/mux/regexp.go
generated
vendored
14
vendor/github.com/gorilla/mux/regexp.go
generated
vendored
|
@ -267,7 +267,7 @@ type routeRegexpGroup struct {
|
|||
}
|
||||
|
||||
// setMatch extracts the variables from the URL once a route matches.
|
||||
func (v *routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) {
|
||||
func (v routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) {
|
||||
// Store host variables.
|
||||
if v.host != nil {
|
||||
host := getHost(req)
|
||||
|
@ -296,7 +296,7 @@ func (v *routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route)
|
|||
} else {
|
||||
u.Path += "/"
|
||||
}
|
||||
m.Handler = http.RedirectHandler(u.String(), 301)
|
||||
m.Handler = http.RedirectHandler(u.String(), http.StatusMovedPermanently)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -312,17 +312,13 @@ func (v *routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route)
|
|||
}
|
||||
|
||||
// getHost tries its best to return the request host.
|
||||
// According to section 14.23 of RFC 2616 the Host header
|
||||
// can include the port number if the default value of 80 is not used.
|
||||
func getHost(r *http.Request) string {
|
||||
if r.URL.IsAbs() {
|
||||
return r.URL.Host
|
||||
}
|
||||
host := r.Host
|
||||
// Slice off any port information.
|
||||
if i := strings.Index(host, ":"); i != -1 {
|
||||
host = host[:i]
|
||||
}
|
||||
return host
|
||||
|
||||
return r.Host
|
||||
}
|
||||
|
||||
func extractVars(input string, matches []int, names []string, output map[string]string) {
|
||||
|
|
139
vendor/github.com/gorilla/mux/route.go
generated
vendored
139
vendor/github.com/gorilla/mux/route.go
generated
vendored
|
@ -15,24 +15,8 @@ import (
|
|||
|
||||
// Route stores information to match a request and build URLs.
|
||||
type Route struct {
|
||||
// Parent where the route was registered (a Router).
|
||||
parent parentRoute
|
||||
// Request handler for the route.
|
||||
handler http.Handler
|
||||
// List of matchers.
|
||||
matchers []matcher
|
||||
// Manager for the variables from host and path.
|
||||
regexp *routeRegexpGroup
|
||||
// If true, when the path pattern is "/path/", accessing "/path" will
|
||||
// redirect to the former and vice versa.
|
||||
strictSlash bool
|
||||
// If true, when the path pattern is "/path//to", accessing "/path//to"
|
||||
// will not redirect
|
||||
skipClean bool
|
||||
// If true, "/path/foo%2Fbar/to" will match the path "/path/{var}/to"
|
||||
useEncodedPath bool
|
||||
// The scheme used when building URLs.
|
||||
buildScheme string
|
||||
// If true, this route never matches: it is only used to build URLs.
|
||||
buildOnly bool
|
||||
// The name used to build URLs.
|
||||
|
@ -40,7 +24,11 @@ type Route struct {
|
|||
// Error resulted from building a route.
|
||||
err error
|
||||
|
||||
buildVarsFunc BuildVarsFunc
|
||||
// "global" reference to all named routes
|
||||
namedRoutes map[string]*Route
|
||||
|
||||
// config possibly passed in from `Router`
|
||||
routeConf
|
||||
}
|
||||
|
||||
// SkipClean reports whether path cleaning is enabled for this route via
|
||||
|
@ -64,6 +52,18 @@ func (r *Route) Match(req *http.Request, match *RouteMatch) bool {
|
|||
matchErr = ErrMethodMismatch
|
||||
continue
|
||||
}
|
||||
|
||||
// Ignore ErrNotFound errors. These errors arise from match call
|
||||
// to Subrouters.
|
||||
//
|
||||
// This prevents subsequent matching subrouters from failing to
|
||||
// run middleware. If not ignored, the middleware would see a
|
||||
// non-nil MatchErr and be skipped, even when there was a
|
||||
// matching route.
|
||||
if match.MatchErr == ErrNotFound {
|
||||
match.MatchErr = nil
|
||||
}
|
||||
|
||||
matchErr = nil
|
||||
return false
|
||||
}
|
||||
|
@ -93,9 +93,7 @@ func (r *Route) Match(req *http.Request, match *RouteMatch) bool {
|
|||
}
|
||||
|
||||
// Set variables.
|
||||
if r.regexp != nil {
|
||||
r.regexp.setMatch(req, match, r)
|
||||
}
|
||||
r.regexp.setMatch(req, match, r)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -137,7 +135,7 @@ func (r *Route) GetHandler() http.Handler {
|
|||
// Name -----------------------------------------------------------------------
|
||||
|
||||
// Name sets the name for the route, used to build URLs.
|
||||
// If the name was registered already it will be overwritten.
|
||||
// It is an error to call Name more than once on a route.
|
||||
func (r *Route) Name(name string) *Route {
|
||||
if r.name != "" {
|
||||
r.err = fmt.Errorf("mux: route already has name %q, can't set %q",
|
||||
|
@ -145,7 +143,7 @@ func (r *Route) Name(name string) *Route {
|
|||
}
|
||||
if r.err == nil {
|
||||
r.name = name
|
||||
r.getNamedRoutes()[name] = r
|
||||
r.namedRoutes[name] = r
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
@ -177,7 +175,6 @@ func (r *Route) addRegexpMatcher(tpl string, typ regexpType) error {
|
|||
if r.err != nil {
|
||||
return r.err
|
||||
}
|
||||
r.regexp = r.getRegexpGroup()
|
||||
if typ == regexpTypePath || typ == regexpTypePrefix {
|
||||
if len(tpl) > 0 && tpl[0] != '/' {
|
||||
return fmt.Errorf("mux: path must start with a slash, got %q", tpl)
|
||||
|
@ -424,7 +421,7 @@ func (r *Route) Schemes(schemes ...string) *Route {
|
|||
for k, v := range schemes {
|
||||
schemes[k] = strings.ToLower(v)
|
||||
}
|
||||
if r.buildScheme == "" && len(schemes) > 0 {
|
||||
if len(schemes) > 0 {
|
||||
r.buildScheme = schemes[0]
|
||||
}
|
||||
return r.addMatcher(schemeMatcher(schemes))
|
||||
|
@ -439,7 +436,15 @@ type BuildVarsFunc func(map[string]string) map[string]string
|
|||
// BuildVarsFunc adds a custom function to be used to modify build variables
|
||||
// before a route's URL is built.
|
||||
func (r *Route) BuildVarsFunc(f BuildVarsFunc) *Route {
|
||||
r.buildVarsFunc = f
|
||||
if r.buildVarsFunc != nil {
|
||||
// compose the old and new functions
|
||||
old := r.buildVarsFunc
|
||||
r.buildVarsFunc = func(m map[string]string) map[string]string {
|
||||
return f(old(m))
|
||||
}
|
||||
} else {
|
||||
r.buildVarsFunc = f
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
|
@ -458,7 +463,8 @@ func (r *Route) BuildVarsFunc(f BuildVarsFunc) *Route {
|
|||
// Here, the routes registered in the subrouter won't be tested if the host
|
||||
// doesn't match.
|
||||
func (r *Route) Subrouter() *Router {
|
||||
router := &Router{parent: r, strictSlash: r.strictSlash}
|
||||
// initialize a subrouter with a copy of the parent route's configuration
|
||||
router := &Router{routeConf: copyRouteConf(r.routeConf), namedRoutes: r.namedRoutes}
|
||||
r.addMatcher(router)
|
||||
return router
|
||||
}
|
||||
|
@ -502,9 +508,6 @@ func (r *Route) URL(pairs ...string) (*url.URL, error) {
|
|||
if r.err != nil {
|
||||
return nil, r.err
|
||||
}
|
||||
if r.regexp == nil {
|
||||
return nil, errors.New("mux: route doesn't have a host or path")
|
||||
}
|
||||
values, err := r.prepareVars(pairs...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -516,8 +519,8 @@ func (r *Route) URL(pairs ...string) (*url.URL, error) {
|
|||
return nil, err
|
||||
}
|
||||
scheme = "http"
|
||||
if s := r.getBuildScheme(); s != "" {
|
||||
scheme = s
|
||||
if r.buildScheme != "" {
|
||||
scheme = r.buildScheme
|
||||
}
|
||||
}
|
||||
if r.regexp.path != nil {
|
||||
|
@ -547,7 +550,7 @@ func (r *Route) URLHost(pairs ...string) (*url.URL, error) {
|
|||
if r.err != nil {
|
||||
return nil, r.err
|
||||
}
|
||||
if r.regexp == nil || r.regexp.host == nil {
|
||||
if r.regexp.host == nil {
|
||||
return nil, errors.New("mux: route doesn't have a host")
|
||||
}
|
||||
values, err := r.prepareVars(pairs...)
|
||||
|
@ -562,8 +565,8 @@ func (r *Route) URLHost(pairs ...string) (*url.URL, error) {
|
|||
Scheme: "http",
|
||||
Host: host,
|
||||
}
|
||||
if s := r.getBuildScheme(); s != "" {
|
||||
u.Scheme = s
|
||||
if r.buildScheme != "" {
|
||||
u.Scheme = r.buildScheme
|
||||
}
|
||||
return u, nil
|
||||
}
|
||||
|
@ -575,7 +578,7 @@ func (r *Route) URLPath(pairs ...string) (*url.URL, error) {
|
|||
if r.err != nil {
|
||||
return nil, r.err
|
||||
}
|
||||
if r.regexp == nil || r.regexp.path == nil {
|
||||
if r.regexp.path == nil {
|
||||
return nil, errors.New("mux: route doesn't have a path")
|
||||
}
|
||||
values, err := r.prepareVars(pairs...)
|
||||
|
@ -600,7 +603,7 @@ func (r *Route) GetPathTemplate() (string, error) {
|
|||
if r.err != nil {
|
||||
return "", r.err
|
||||
}
|
||||
if r.regexp == nil || r.regexp.path == nil {
|
||||
if r.regexp.path == nil {
|
||||
return "", errors.New("mux: route doesn't have a path")
|
||||
}
|
||||
return r.regexp.path.template, nil
|
||||
|
@ -614,7 +617,7 @@ func (r *Route) GetPathRegexp() (string, error) {
|
|||
if r.err != nil {
|
||||
return "", r.err
|
||||
}
|
||||
if r.regexp == nil || r.regexp.path == nil {
|
||||
if r.regexp.path == nil {
|
||||
return "", errors.New("mux: route does not have a path")
|
||||
}
|
||||
return r.regexp.path.regexp.String(), nil
|
||||
|
@ -629,7 +632,7 @@ func (r *Route) GetQueriesRegexp() ([]string, error) {
|
|||
if r.err != nil {
|
||||
return nil, r.err
|
||||
}
|
||||
if r.regexp == nil || r.regexp.queries == nil {
|
||||
if r.regexp.queries == nil {
|
||||
return nil, errors.New("mux: route doesn't have queries")
|
||||
}
|
||||
var queries []string
|
||||
|
@ -648,7 +651,7 @@ func (r *Route) GetQueriesTemplates() ([]string, error) {
|
|||
if r.err != nil {
|
||||
return nil, r.err
|
||||
}
|
||||
if r.regexp == nil || r.regexp.queries == nil {
|
||||
if r.regexp.queries == nil {
|
||||
return nil, errors.New("mux: route doesn't have queries")
|
||||
}
|
||||
var queries []string
|
||||
|
@ -683,7 +686,7 @@ func (r *Route) GetHostTemplate() (string, error) {
|
|||
if r.err != nil {
|
||||
return "", r.err
|
||||
}
|
||||
if r.regexp == nil || r.regexp.host == nil {
|
||||
if r.regexp.host == nil {
|
||||
return "", errors.New("mux: route doesn't have a host")
|
||||
}
|
||||
return r.regexp.host.template, nil
|
||||
|
@ -700,64 +703,8 @@ func (r *Route) prepareVars(pairs ...string) (map[string]string, error) {
|
|||
}
|
||||
|
||||
func (r *Route) buildVars(m map[string]string) map[string]string {
|
||||
if r.parent != nil {
|
||||
m = r.parent.buildVars(m)
|
||||
}
|
||||
if r.buildVarsFunc != nil {
|
||||
m = r.buildVarsFunc(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// parentRoute
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// parentRoute allows routes to know about parent host and path definitions.
|
||||
type parentRoute interface {
|
||||
getBuildScheme() string
|
||||
getNamedRoutes() map[string]*Route
|
||||
getRegexpGroup() *routeRegexpGroup
|
||||
buildVars(map[string]string) map[string]string
|
||||
}
|
||||
|
||||
func (r *Route) getBuildScheme() string {
|
||||
if r.buildScheme != "" {
|
||||
return r.buildScheme
|
||||
}
|
||||
if r.parent != nil {
|
||||
return r.parent.getBuildScheme()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// getNamedRoutes returns the map where named routes are registered.
|
||||
func (r *Route) getNamedRoutes() map[string]*Route {
|
||||
if r.parent == nil {
|
||||
// During tests router is not always set.
|
||||
r.parent = NewRouter()
|
||||
}
|
||||
return r.parent.getNamedRoutes()
|
||||
}
|
||||
|
||||
// getRegexpGroup returns regexp definitions from this route.
|
||||
func (r *Route) getRegexpGroup() *routeRegexpGroup {
|
||||
if r.regexp == nil {
|
||||
if r.parent == nil {
|
||||
// During tests router is not always set.
|
||||
r.parent = NewRouter()
|
||||
}
|
||||
regexp := r.parent.getRegexpGroup()
|
||||
if regexp == nil {
|
||||
r.regexp = new(routeRegexpGroup)
|
||||
} else {
|
||||
// Copy.
|
||||
r.regexp = &routeRegexpGroup{
|
||||
host: regexp.host,
|
||||
path: regexp.path,
|
||||
queries: regexp.queries,
|
||||
}
|
||||
}
|
||||
}
|
||||
return r.regexp
|
||||
}
|
||||
|
|
35
vendor/github.com/jpillora/go-tld/README.md
generated
vendored
35
vendor/github.com/jpillora/go-tld/README.md
generated
vendored
|
@ -1,15 +1,9 @@
|
|||
This was written for fun, please use
|
||||
|
||||
http://golang.org/x/net/publicsuffix
|
||||
|
||||
instead.
|
||||
|
||||
---
|
||||
|
||||
# TLD Parser in Go
|
||||
|
||||
The `tld` package has the same API ([see godoc](http://godoc.org/github.com/jpillora/go-tld)) as `net/url` except `tld.URL` contains extra fields: `Subdomain`, `Domain`, `TLD` and `Port`.
|
||||
|
||||
_Note:_ This was written for fun, please use http://golang.org/x/net/publicsuffix instead.
|
||||
|
||||
### Install
|
||||
|
||||
```
|
||||
|
@ -18,7 +12,7 @@ go get github.com/jpillora/go-tld
|
|||
|
||||
### Usage
|
||||
|
||||
``` go
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -28,20 +22,33 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
u, _ := tld.Parse("http://a.very.complex-domain.co.uk:8080/foo/bar")
|
||||
|
||||
fmt.Printf("[ %s ] [ %s ] [ %s ] [ %s ] [ %s ]", u.Subdomain, u.Domain, u.TLD, u.Port, u.Path)
|
||||
urls := []string{
|
||||
"http://google.com",
|
||||
"http://blog.google",
|
||||
"https://www.medi-cal.ca.gov/",
|
||||
"https://ato.gov.au",
|
||||
"http://a.very.complex-domain.co.uk:8080/foo/bar",
|
||||
}
|
||||
for _, url := range urls {
|
||||
u, _ := tld.Parse(url)
|
||||
fmt.Printf("%50s = [ %s ] [ %s ] [ %s ] [ %s ] [ %s ]\n",
|
||||
u, u.Subdomain, u.Domain, u.TLD, u.Port, u.Path)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
$ go run main.go
|
||||
[ a.very ] [ complex-domain ] [ co.uk ] [ 8080 ] [ /foo/bar ]
|
||||
http://google.com = [ ] [ google ] [ com ] [ ] [ ]
|
||||
http://blog.google = [ ] [ blog ] [ google ] [ ] [ ]
|
||||
https://www.medi-cal.ca.gov/ = [ www.medi-cal ] [ ca ] [ gov ] [ ] [ / ]
|
||||
https://ato.gov.au = [ ] [ ato ] [ gov.au ] [ ] [ ]
|
||||
http://a.very.complex-domain.co.uk:8080/foo/bar = [ a.very ] [ complex-domain ] [ co.uk ] [ 8080 ] [ /foo/bar ]
|
||||
```
|
||||
|
||||
#### MIT License
|
||||
|
||||
Copyright © 2015 Jaime Pillora <dev@jpillora.com>
|
||||
Copyright © 2019 Jaime Pillora <dev@jpillora.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
|
10
vendor/github.com/jpillora/go-tld/parse.go
generated
vendored
10
vendor/github.com/jpillora/go-tld/parse.go
generated
vendored
|
@ -1,6 +1,6 @@
|
|||
//go:generate sh generate.sh
|
||||
|
||||
//The tld package has the same API as net/url except
|
||||
//Package tld has the same API as net/url except
|
||||
//tld.URL contains extra fields: Subdomain, Domain, TLD and Port.
|
||||
package tld
|
||||
|
||||
|
@ -28,11 +28,9 @@ func Parse(s string) (*URL, error) {
|
|||
return &URL{URL: url}, nil
|
||||
}
|
||||
|
||||
dom, port := domainPort(url.Host)
|
||||
//index of tld
|
||||
tld := 0
|
||||
|
||||
dom, port := domainPort(url.Host)
|
||||
|
||||
i := 0
|
||||
l := len(dom) - 1
|
||||
|
||||
|
@ -47,7 +45,7 @@ func Parse(s string) (*URL, error) {
|
|||
//for binary search debugging...
|
||||
// log.Printf("[%d - %d - %d] %s == %s (%s)", lo, mid, hi, string(dom[l-i]), string(guess[i]), guess)
|
||||
|
||||
if i < len(guess) && guess[i] == dom[l-i] {
|
||||
if i < len(guess) && i <= l && guess[i] == dom[l-i] {
|
||||
//store partial match
|
||||
if i > tld && guess[i] == '.' {
|
||||
tld = i
|
||||
|
@ -59,7 +57,7 @@ func Parse(s string) (*URL, error) {
|
|||
tld = i
|
||||
break
|
||||
}
|
||||
} else if i >= len(guess) || guess[i] < dom[l-i] {
|
||||
} else if i >= len(guess) || (i <= l && guess[i] < dom[l-i]) {
|
||||
lo = mid
|
||||
i = 0
|
||||
} else {
|
||||
|
|
89
vendor/github.com/jpillora/go-tld/parse_list.go
generated
vendored
89
vendor/github.com/jpillora/go-tld/parse_list.go
generated
vendored
|
@ -1,5 +1,5 @@
|
|||
package tld
|
||||
//generated on 'Wed 8 Aug 2018 21:43:57 UTC'
|
||||
//generated on 'Sat 2 Feb 2019 07:25:29 UTC'
|
||||
|
||||
//list contains all TLDs reversed, then sorted
|
||||
var list = []string{
|
||||
|
@ -167,7 +167,6 @@ var list = []string{
|
|||
"atelhta",
|
||||
"atled",
|
||||
"atoyot",
|
||||
"atsiv",
|
||||
"au",
|
||||
"au.acinniv",
|
||||
"au.aemirc",
|
||||
|
@ -374,7 +373,6 @@ var list = []string{
|
|||
"cl.ude",
|
||||
"cl.vog",
|
||||
"cl.yo",
|
||||
"clj",
|
||||
"cll",
|
||||
"cm",
|
||||
"cm.mt",
|
||||
|
@ -436,6 +434,7 @@ var list = []string{
|
|||
"di.oc.topsgolb",
|
||||
"di.og",
|
||||
"di.ro",
|
||||
"di.sepnop",
|
||||
"di.ten",
|
||||
"di.ym",
|
||||
"di.zib",
|
||||
|
@ -1282,10 +1281,12 @@ var list = []string{
|
|||
"hsiri",
|
||||
"ht",
|
||||
"ht.ca",
|
||||
"ht.enilno",
|
||||
"ht.im",
|
||||
"ht.ni",
|
||||
"ht.oc",
|
||||
"ht.og",
|
||||
"ht.pohs",
|
||||
"ht.ro",
|
||||
"ht.ten",
|
||||
"htiaf",
|
||||
|
@ -1305,7 +1306,6 @@ var list = []string{
|
|||
"ia.ten",
|
||||
"iabud",
|
||||
"iadnuyh",
|
||||
"iarenap",
|
||||
"iatnihc",
|
||||
"ib",
|
||||
"ib.gro",
|
||||
|
@ -1567,6 +1567,8 @@ var list = []string{
|
|||
"ku.oc.elddiwg",
|
||||
"ku.oc.enilnoysrab",
|
||||
"ku.oc.enozgniebllew",
|
||||
"ku.oc.krametyb.hd",
|
||||
"ku.oc.krametyb.mv",
|
||||
"ku.oc.pi-on",
|
||||
"ku.oc.topsgolb",
|
||||
"ku.oc.vres-hn",
|
||||
|
@ -1651,7 +1653,6 @@ var list = []string{
|
|||
"liamg",
|
||||
"liamtoh",
|
||||
"lim",
|
||||
"liotats",
|
||||
"lir",
|
||||
"lixil",
|
||||
"llabesab",
|
||||
|
@ -1679,7 +1680,6 @@ var list = []string{
|
|||
"ln.oc",
|
||||
"ln.retsulc-gnitsoh",
|
||||
"ln.topsgolb",
|
||||
"ln.vb",
|
||||
"lnb",
|
||||
"lno",
|
||||
"loa",
|
||||
|
@ -1709,6 +1709,7 @@ var list = []string{
|
|||
"lp.alow-awolats",
|
||||
"lp.alowoksnok",
|
||||
"lp.animg",
|
||||
"lp.anzcel",
|
||||
"lp.arog-aibab",
|
||||
"lp.arog-ainelej",
|
||||
"lp.arogj",
|
||||
|
@ -1720,6 +1721,7 @@ var list = []string{
|
|||
"lp.awalo",
|
||||
"lp.awazsraw",
|
||||
"lp.awonamil",
|
||||
"lp.awotainop",
|
||||
"lp.azeiwolaib",
|
||||
"lp.azmol",
|
||||
"lp.ceiwalselob",
|
||||
|
@ -1759,6 +1761,8 @@ var list = []string{
|
|||
"lp.kerut",
|
||||
"lp.kewalcolw",
|
||||
"lp.kinbyr",
|
||||
"lp.kindiws",
|
||||
"lp.kinsark",
|
||||
"lp.kle",
|
||||
"lp.konas",
|
||||
"lp.kotsylaib",
|
||||
|
@ -1786,6 +1790,7 @@ var list = []string{
|
|||
"lp.nanzop",
|
||||
"lp.nibul",
|
||||
"lp.nicezczs",
|
||||
"lp.nilbul",
|
||||
"lp.nimolow",
|
||||
"lp.ninok",
|
||||
"lp.nizdeb",
|
||||
|
@ -1880,6 +1885,7 @@ var list = []string{
|
|||
"lp.wokzsurp",
|
||||
"lp.woraz",
|
||||
"lp.worgew",
|
||||
"lp.wotrabul",
|
||||
"lp.wotsugua",
|
||||
"lp.wozcoks",
|
||||
"lp.wozsezr",
|
||||
|
@ -2089,6 +2095,7 @@ var list = []string{
|
|||
"moc.eziig",
|
||||
"moc.fehc-a-si",
|
||||
"moc.gnigats-swennwot",
|
||||
"moc.gnigatsmocpw",
|
||||
"moc.gniksndd",
|
||||
"moc.gnirobsikrow",
|
||||
"moc.gofgp",
|
||||
|
@ -2264,6 +2271,7 @@ var list = []string{
|
|||
"moc.sretsohmaerd",
|
||||
"moc.ssel-rof-slles",
|
||||
"moc.ssertca-na-si",
|
||||
"moc.ssibodym",
|
||||
"moc.su",
|
||||
"moc.swanozama.1-htuos-pa-3s",
|
||||
"moc.swanozama.1-htuos-pa.3s",
|
||||
|
@ -2328,6 +2336,7 @@ var list = []string{
|
|||
"moc.tneduts-a-si",
|
||||
"moc.tner-ot-ecaps",
|
||||
"moc.tnetnocresubuhtig",
|
||||
"moc.tnetnocresupl",
|
||||
"moc.topsedoc",
|
||||
"moc.topsgolb",
|
||||
"moc.topsppa",
|
||||
|
@ -2970,6 +2979,12 @@ var list = []string{
|
|||
"nauqna",
|
||||
"navarac",
|
||||
"nayalo",
|
||||
"nb",
|
||||
"nb.gro",
|
||||
"nb.moc",
|
||||
"nb.ten",
|
||||
"nb.ude",
|
||||
"nb.vog",
|
||||
"nbc",
|
||||
"nc",
|
||||
"nc.ah",
|
||||
|
@ -2978,6 +2993,7 @@ var list = []string{
|
|||
"nc.cs",
|
||||
"nc.dg",
|
||||
"nc.ds",
|
||||
"nc.duolctnatsni",
|
||||
"nc.eh",
|
||||
"nc.gro",
|
||||
"nc.ha",
|
||||
|
@ -2997,6 +3013,7 @@ var list = []string{
|
|||
"nc.moc",
|
||||
"nc.moc.swanozama.1-htron-nc.3s",
|
||||
"nc.moc.swanozama.be.1-htron-nc",
|
||||
"nc.moc.swanozama.be.1-tsewhtron-nc",
|
||||
"nc.nh",
|
||||
"nc.nl",
|
||||
"nc.ns",
|
||||
|
@ -3245,6 +3262,9 @@ var list = []string{
|
|||
"oc.mrif",
|
||||
"oc.mudon",
|
||||
"oc.ofni",
|
||||
"oc.piv-og",
|
||||
"oc.segapdael",
|
||||
"oc.segapl",
|
||||
"oc.stra",
|
||||
"oc.t4n",
|
||||
"oc.ten",
|
||||
|
@ -3316,6 +3336,7 @@ var list = []string{
|
|||
"oi.duolcropav",
|
||||
"oi.durd",
|
||||
"oi.ecivedniser",
|
||||
"oi.eegipa",
|
||||
"oi.esufxob",
|
||||
"oi.etisnoehtnap",
|
||||
"oi.etnewtu",
|
||||
|
@ -3329,9 +3350,11 @@ var list = []string{
|
|||
"oi.ppaenalpkcab",
|
||||
"oi.reniatnoceruza",
|
||||
"oi.rial.sppa",
|
||||
"oi.scodehtdaer",
|
||||
"oi.spparevelc",
|
||||
"oi.stacdnas",
|
||||
"oi.tenotorp",
|
||||
"oi.tibelet",
|
||||
"oi.tidetfihs",
|
||||
"oi.tikecaps",
|
||||
"oi.traedon.egats",
|
||||
|
@ -6096,6 +6119,9 @@ var list = []string{
|
|||
"pot.snd-won",
|
||||
"ppa",
|
||||
"ppa.arusah",
|
||||
"ppa.nur",
|
||||
"ppa.nur.a",
|
||||
"ppa.tibelet",
|
||||
"praa",
|
||||
"prahs",
|
||||
"puekam",
|
||||
|
@ -6212,6 +6238,7 @@ var list = []string{
|
|||
"rb.glz",
|
||||
"rb.gnc",
|
||||
"rb.gne",
|
||||
"rb.gno",
|
||||
"rb.golb",
|
||||
"rb.golf",
|
||||
"rb.golv",
|
||||
|
@ -6552,7 +6579,6 @@ var list = []string{
|
|||
"sda",
|
||||
"sdd",
|
||||
"sdl",
|
||||
"sdnahdoog",
|
||||
"sdniwriaf",
|
||||
"sdnomaid",
|
||||
"sdoogemoh",
|
||||
|
@ -6616,8 +6642,15 @@ var list = []string{
|
|||
"skcus",
|
||||
"skrow",
|
||||
"sl",
|
||||
"sl.ca",
|
||||
"sl.cs",
|
||||
"sl.gro",
|
||||
"sl.oc",
|
||||
"sl.ofni",
|
||||
"sl.ten",
|
||||
"sl.ude",
|
||||
"sl.vog",
|
||||
"sl.zib",
|
||||
"slaed",
|
||||
"slatner",
|
||||
"slessurb",
|
||||
|
@ -7066,6 +7099,7 @@ var list = []string{
|
|||
"ten.es",
|
||||
"ten.etis-repparcs",
|
||||
"ten.ezamkcar",
|
||||
"ten.faeletis",
|
||||
"ten.fehc-a-si",
|
||||
"ten.gnitsohnnylf",
|
||||
"ten.golbevres",
|
||||
|
@ -7248,9 +7282,9 @@ var list = []string{
|
|||
"ti.anedom",
|
||||
"ti.aneis",
|
||||
"ti.anesec-ilrof",
|
||||
"ti.anesec-̀ilrof",
|
||||
"ti.anesec-ìlrof",
|
||||
"ti.anesecilrof",
|
||||
"ti.anesec̀ilrof",
|
||||
"ti.anesecìlrof",
|
||||
"ti.angamor-ailime",
|
||||
"ti.angamorailime",
|
||||
"ti.angedras",
|
||||
|
@ -7366,13 +7400,13 @@ var list = []string{
|
|||
"ti.etseirt",
|
||||
"ti.etsoa",
|
||||
"ti.etsoa-d-eellav",
|
||||
"ti.etsoa-d-éellav",
|
||||
"ti.etsoa-d-eéllav",
|
||||
"ti.etsoa-eellav",
|
||||
"ti.etsoa-éellav",
|
||||
"ti.etsoa-eéllav",
|
||||
"ti.etsoadeellav",
|
||||
"ti.etsoadéellav",
|
||||
"ti.etsoadeéllav",
|
||||
"ti.etsoaeellav",
|
||||
"ti.etsoaéellav",
|
||||
"ti.etsoaeéllav",
|
||||
"ti.ev",
|
||||
"ti.eznerif",
|
||||
"ti.ga",
|
||||
|
@ -7424,10 +7458,10 @@ var list = []string{
|
|||
"ti.lorit-dus-onitnert",
|
||||
"ti.lorit-dusnitnert",
|
||||
"ti.lorit-dusonitnert",
|
||||
"ti.lorit-d̈us-nitnert",
|
||||
"ti.lorit-d̈us-onitnert",
|
||||
"ti.lorit-d̈usnitnert",
|
||||
"ti.lorit-d̈usonitnert",
|
||||
"ti.lorit-düs-nitnert",
|
||||
"ti.lorit-düs-onitnert",
|
||||
"ti.lorit-düsnitnert",
|
||||
"ti.lorit-düsonitnert",
|
||||
"ti.lorit-s-onitnert",
|
||||
"ti.lorit-sonitnert",
|
||||
"ti.loritdeus",
|
||||
|
@ -7445,14 +7479,14 @@ var list = []string{
|
|||
"ti.loritdus-onitnert",
|
||||
"ti.loritdusnitnert",
|
||||
"ti.loritdusonitnert",
|
||||
"ti.loritd̈us",
|
||||
"ti.loritd̈us-naslab",
|
||||
"ti.loritd̈us-naslub",
|
||||
"ti.loritd̈us-nezob",
|
||||
"ti.loritd̈us-nitnert",
|
||||
"ti.loritd̈us-onitnert",
|
||||
"ti.loritd̈usnitnert",
|
||||
"ti.loritd̈usonitnert",
|
||||
"ti.loritdüs",
|
||||
"ti.loritdüs-naslab",
|
||||
"ti.loritdüs-naslub",
|
||||
"ti.loritdüs-nezob",
|
||||
"ti.loritdüs-nitnert",
|
||||
"ti.loritdüs-onitnert",
|
||||
"ti.loritdüsnitnert",
|
||||
"ti.loritdüsonitnert",
|
||||
"ti.lorits-onitnert",
|
||||
"ti.loritsonitnert",
|
||||
"ti.mac",
|
||||
|
@ -7592,8 +7626,8 @@ var list = []string{
|
|||
"ti.zb",
|
||||
"ti.zc",
|
||||
"ti.zp",
|
||||
"ti.̀ilrof-anesec",
|
||||
"ti.̀ilrofanesec",
|
||||
"ti.ìlrof-anesec",
|
||||
"ti.ìlrofanesec",
|
||||
"tiderc",
|
||||
"tier",
|
||||
"tif",
|
||||
|
@ -8228,7 +8262,6 @@ var list = []string{
|
|||
"yspil",
|
||||
"ytefas",
|
||||
"ytic",
|
||||
"yticelet",
|
||||
"ytiledif",
|
||||
"ytinifx",
|
||||
"ytinummoc",
|
||||
|
|
214
vendor/github.com/mattn/go-colorable/colorable_windows.go
generated
vendored
214
vendor/github.com/mattn/go-colorable/colorable_windows.go
generated
vendored
|
@ -29,6 +29,15 @@ const (
|
|||
backgroundMask = (backgroundRed | backgroundBlue | backgroundGreen | backgroundIntensity)
|
||||
)
|
||||
|
||||
const (
|
||||
genericRead = 0x80000000
|
||||
genericWrite = 0x40000000
|
||||
)
|
||||
|
||||
const (
|
||||
consoleTextmodeBuffer = 0x1
|
||||
)
|
||||
|
||||
type wchar uint16
|
||||
type short int16
|
||||
type dword uint32
|
||||
|
@ -69,14 +78,17 @@ var (
|
|||
procGetConsoleCursorInfo = kernel32.NewProc("GetConsoleCursorInfo")
|
||||
procSetConsoleCursorInfo = kernel32.NewProc("SetConsoleCursorInfo")
|
||||
procSetConsoleTitle = kernel32.NewProc("SetConsoleTitleW")
|
||||
procCreateConsoleScreenBuffer = kernel32.NewProc("CreateConsoleScreenBuffer")
|
||||
)
|
||||
|
||||
// Writer provide colorable Writer to the console
|
||||
type Writer struct {
|
||||
out io.Writer
|
||||
handle syscall.Handle
|
||||
oldattr word
|
||||
oldpos coord
|
||||
out io.Writer
|
||||
handle syscall.Handle
|
||||
althandle syscall.Handle
|
||||
oldattr word
|
||||
oldpos coord
|
||||
rest bytes.Buffer
|
||||
}
|
||||
|
||||
// NewColorable return new instance of Writer which handle escape sequence from File.
|
||||
|
@ -407,7 +419,18 @@ func (w *Writer) Write(data []byte) (n int, err error) {
|
|||
var csbi consoleScreenBufferInfo
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
|
||||
er := bytes.NewReader(data)
|
||||
handle := w.handle
|
||||
|
||||
var er *bytes.Reader
|
||||
if w.rest.Len() > 0 {
|
||||
var rest bytes.Buffer
|
||||
w.rest.WriteTo(&rest)
|
||||
w.rest.Reset()
|
||||
rest.Write(data)
|
||||
er = bytes.NewReader(rest.Bytes())
|
||||
} else {
|
||||
er = bytes.NewReader(data)
|
||||
}
|
||||
var bw [1]byte
|
||||
loop:
|
||||
for {
|
||||
|
@ -425,29 +448,55 @@ loop:
|
|||
break loop
|
||||
}
|
||||
|
||||
if c2 == ']' {
|
||||
if err := doTitleSequence(er); err != nil {
|
||||
switch c2 {
|
||||
case '>':
|
||||
continue
|
||||
case ']':
|
||||
w.rest.WriteByte(c1)
|
||||
w.rest.WriteByte(c2)
|
||||
er.WriteTo(&w.rest)
|
||||
if bytes.IndexByte(w.rest.Bytes(), 0x07) == -1 {
|
||||
break loop
|
||||
}
|
||||
continue
|
||||
}
|
||||
if c2 != 0x5b {
|
||||
continue
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
var m byte
|
||||
for {
|
||||
c, err := er.ReadByte()
|
||||
er = bytes.NewReader(w.rest.Bytes()[2:])
|
||||
err := doTitleSequence(er)
|
||||
if err != nil {
|
||||
break loop
|
||||
}
|
||||
w.rest.Reset()
|
||||
continue
|
||||
// https://github.com/mattn/go-colorable/issues/27
|
||||
case '7':
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
w.oldpos = csbi.cursorPosition
|
||||
continue
|
||||
case '8':
|
||||
procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&w.oldpos)))
|
||||
continue
|
||||
case 0x5b:
|
||||
// execute part after switch
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
w.rest.WriteByte(c1)
|
||||
w.rest.WriteByte(c2)
|
||||
er.WriteTo(&w.rest)
|
||||
|
||||
var buf bytes.Buffer
|
||||
var m byte
|
||||
for i, c := range w.rest.Bytes()[2:] {
|
||||
if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' {
|
||||
m = c
|
||||
er = bytes.NewReader(w.rest.Bytes()[2+i+1:])
|
||||
w.rest.Reset()
|
||||
break
|
||||
}
|
||||
buf.Write([]byte(string(c)))
|
||||
}
|
||||
if m == 0 {
|
||||
break loop
|
||||
}
|
||||
|
||||
switch m {
|
||||
case 'A':
|
||||
|
@ -455,61 +504,64 @@ loop:
|
|||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.y -= short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'B':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.y += short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'C':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.x += short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'D':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.x -= short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
if csbi.cursorPosition.x < 0 {
|
||||
csbi.cursorPosition.x = 0
|
||||
}
|
||||
procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'E':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.x = 0
|
||||
csbi.cursorPosition.y += short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'F':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.x = 0
|
||||
csbi.cursorPosition.y -= short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'G':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.x = short(n - 1)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'H', 'f':
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
if buf.Len() > 0 {
|
||||
token := strings.Split(buf.String(), ";")
|
||||
switch len(token) {
|
||||
|
@ -534,7 +586,7 @@ loop:
|
|||
} else {
|
||||
csbi.cursorPosition.y = 0
|
||||
}
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'J':
|
||||
n := 0
|
||||
if buf.Len() > 0 {
|
||||
|
@ -545,20 +597,20 @@ loop:
|
|||
}
|
||||
var count, written dword
|
||||
var cursor coord
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
switch n {
|
||||
case 0:
|
||||
cursor = coord{x: csbi.cursorPosition.x, y: csbi.cursorPosition.y}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.size.y-csbi.cursorPosition.y)*csbi.size.x)
|
||||
count = dword(csbi.size.x) - dword(csbi.cursorPosition.x) + dword(csbi.size.y-csbi.cursorPosition.y)*dword(csbi.size.x)
|
||||
case 1:
|
||||
cursor = coord{x: csbi.window.left, y: csbi.window.top}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.window.top-csbi.cursorPosition.y)*csbi.size.x)
|
||||
count = dword(csbi.size.x) - dword(csbi.cursorPosition.x) + dword(csbi.window.top-csbi.cursorPosition.y)*dword(csbi.size.x)
|
||||
case 2:
|
||||
cursor = coord{x: csbi.window.left, y: csbi.window.top}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.size.y-csbi.cursorPosition.y)*csbi.size.x)
|
||||
count = dword(csbi.size.x) - dword(csbi.cursorPosition.x) + dword(csbi.size.y-csbi.cursorPosition.y)*dword(csbi.size.x)
|
||||
}
|
||||
procFillConsoleOutputCharacter.Call(uintptr(w.handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
procFillConsoleOutputAttribute.Call(uintptr(w.handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
procFillConsoleOutputAttribute.Call(uintptr(handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
case 'K':
|
||||
n := 0
|
||||
if buf.Len() > 0 {
|
||||
|
@ -567,28 +619,28 @@ loop:
|
|||
continue
|
||||
}
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
var cursor coord
|
||||
var count, written dword
|
||||
switch n {
|
||||
case 0:
|
||||
cursor = coord{x: csbi.cursorPosition.x + 1, y: csbi.cursorPosition.y}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x - 1)
|
||||
cursor = coord{x: csbi.cursorPosition.x, y: csbi.cursorPosition.y}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x)
|
||||
case 1:
|
||||
cursor = coord{x: csbi.window.left, y: csbi.window.top + csbi.cursorPosition.y}
|
||||
cursor = coord{x: csbi.window.left, y: csbi.cursorPosition.y}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x)
|
||||
case 2:
|
||||
cursor = coord{x: csbi.window.left, y: csbi.window.top + csbi.cursorPosition.y}
|
||||
cursor = coord{x: csbi.window.left, y: csbi.cursorPosition.y}
|
||||
count = dword(csbi.size.x)
|
||||
}
|
||||
procFillConsoleOutputCharacter.Call(uintptr(w.handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
procFillConsoleOutputAttribute.Call(uintptr(w.handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
procFillConsoleOutputAttribute.Call(uintptr(handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
case 'm':
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
attr := csbi.attributes
|
||||
cs := buf.String()
|
||||
if cs == "" {
|
||||
procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(w.oldattr))
|
||||
procSetConsoleTextAttribute.Call(uintptr(handle), uintptr(w.oldattr))
|
||||
continue
|
||||
}
|
||||
token := strings.Split(cs, ";")
|
||||
|
@ -627,6 +679,21 @@ loop:
|
|||
attr |= n256foreAttr[n256]
|
||||
i += 2
|
||||
}
|
||||
} else if len(token) == 5 && token[i+1] == "2" {
|
||||
var r, g, b int
|
||||
r, _ = strconv.Atoi(token[i+2])
|
||||
g, _ = strconv.Atoi(token[i+3])
|
||||
b, _ = strconv.Atoi(token[i+4])
|
||||
i += 4
|
||||
if r > 127 {
|
||||
attr |= foregroundRed
|
||||
}
|
||||
if g > 127 {
|
||||
attr |= foregroundGreen
|
||||
}
|
||||
if b > 127 {
|
||||
attr |= foregroundBlue
|
||||
}
|
||||
} else {
|
||||
attr = attr & (w.oldattr & backgroundMask)
|
||||
}
|
||||
|
@ -654,6 +721,21 @@ loop:
|
|||
attr |= n256backAttr[n256]
|
||||
i += 2
|
||||
}
|
||||
} else if len(token) == 5 && token[i+1] == "2" {
|
||||
var r, g, b int
|
||||
r, _ = strconv.Atoi(token[i+2])
|
||||
g, _ = strconv.Atoi(token[i+3])
|
||||
b, _ = strconv.Atoi(token[i+4])
|
||||
i += 4
|
||||
if r > 127 {
|
||||
attr |= backgroundRed
|
||||
}
|
||||
if g > 127 {
|
||||
attr |= backgroundGreen
|
||||
}
|
||||
if b > 127 {
|
||||
attr |= backgroundBlue
|
||||
}
|
||||
} else {
|
||||
attr = attr & (w.oldattr & foregroundMask)
|
||||
}
|
||||
|
@ -685,38 +767,52 @@ loop:
|
|||
attr |= backgroundBlue
|
||||
}
|
||||
}
|
||||
procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(attr))
|
||||
procSetConsoleTextAttribute.Call(uintptr(handle), uintptr(attr))
|
||||
}
|
||||
}
|
||||
case 'h':
|
||||
var ci consoleCursorInfo
|
||||
cs := buf.String()
|
||||
if cs == "5>" {
|
||||
procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci)))
|
||||
ci.visible = 0
|
||||
procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci)))
|
||||
} else if cs == "?25" {
|
||||
procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci)))
|
||||
ci.visible = 1
|
||||
procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci)))
|
||||
} else if cs == "?1049" {
|
||||
if w.althandle == 0 {
|
||||
h, _, _ := procCreateConsoleScreenBuffer.Call(uintptr(genericRead|genericWrite), 0, 0, uintptr(consoleTextmodeBuffer), 0, 0)
|
||||
w.althandle = syscall.Handle(h)
|
||||
if w.althandle != 0 {
|
||||
handle = w.althandle
|
||||
}
|
||||
}
|
||||
}
|
||||
case 'l':
|
||||
var ci consoleCursorInfo
|
||||
cs := buf.String()
|
||||
if cs == "5>" {
|
||||
procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci)))
|
||||
ci.visible = 1
|
||||
procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci)))
|
||||
} else if cs == "?25" {
|
||||
procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
procGetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci)))
|
||||
ci.visible = 0
|
||||
procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
procSetConsoleCursorInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&ci)))
|
||||
} else if cs == "?1049" {
|
||||
if w.althandle != 0 {
|
||||
syscall.CloseHandle(w.althandle)
|
||||
w.althandle = 0
|
||||
handle = w.handle
|
||||
}
|
||||
}
|
||||
case 's':
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
w.oldpos = csbi.cursorPosition
|
||||
case 'u':
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&w.oldpos)))
|
||||
procSetConsoleCursorPosition.Call(uintptr(handle), *(*uintptr)(unsafe.Pointer(&w.oldpos)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue