Working auth and photo json endpoint
Signed-off-by: Kris Nóva <kris@nivenly.com>
This commit is contained in:
parent
ef275f97f4
commit
e4323b6047
2032 changed files with 821464 additions and 52 deletions
33
vendor/github.com/kris-nova/lolgopher/Gopkg.lock
generated
vendored
Normal file
33
vendor/github.com/kris-nova/lolgopher/Gopkg.lock
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/CrowdSurge/banner"
|
||||
packages = [".","fonts"]
|
||||
revision = "8c0e79dc5ff70fb2919f0d662f44fd72ccdf9be2"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-colorable"
|
||||
packages = ["."]
|
||||
revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
|
||||
version = "v0.0.9"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-isatty"
|
||||
packages = ["."]
|
||||
revision = "fc9e8d8ef48496124e79ae0df75490096eccf6fe"
|
||||
version = "v0.0.2"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/sys"
|
||||
packages = ["unix"]
|
||||
revision = "e42485b6e20ae7d2304ec72e535b103ed350cc02"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "62e505d253abb5182341a550e55ec60aa59bfd5411fd080c9cc4852a14cd5ef7"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
71
vendor/github.com/kris-nova/lolgopher/Gopkg.toml
generated
vendored
Normal file
71
vendor/github.com/kris-nova/lolgopher/Gopkg.toml
generated
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
|
||||
## Gopkg.toml example (these lines may be deleted)
|
||||
|
||||
## "metadata" defines metadata about the project that could be used by other independent
|
||||
## systems. The metadata defined here will be ignored by dep.
|
||||
# [metadata]
|
||||
# key1 = "value that convey data to other systems"
|
||||
# system1-data = "value that is used by a system"
|
||||
# system2-data = "value that is used by another system"
|
||||
|
||||
## "required" lists a set of packages (not projects) that must be included in
|
||||
## Gopkg.lock. This list is merged with the set of packages imported by the current
|
||||
## project. Use it when your project needs a package it doesn't explicitly import -
|
||||
## including "main" packages.
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
|
||||
## "ignored" lists a set of packages (not projects) that are ignored when
|
||||
## dep statically analyzes source code. Ignored packages can be in this project,
|
||||
## or in a dependency.
|
||||
# ignored = ["github.com/user/project/badpkg"]
|
||||
|
||||
## Constraints are rules for how directly imported projects
|
||||
## may be incorporated into the depgraph. They are respected by
|
||||
## dep whether coming from the Gopkg.toml of the current project or a dependency.
|
||||
# [[constraint]]
|
||||
## Required: the root import path of the project being constrained.
|
||||
# name = "github.com/user/project"
|
||||
#
|
||||
## Recommended: the version constraint to enforce for the project.
|
||||
## Only one of "branch", "version" or "revision" can be specified.
|
||||
# version = "1.0.0"
|
||||
# branch = "master"
|
||||
# revision = "abc123"
|
||||
#
|
||||
## Optional: an alternate location (URL or import path) for the project's source.
|
||||
# source = "https://github.com/myfork/package.git"
|
||||
#
|
||||
## "metadata" defines metadata about the dependency or override that could be used
|
||||
## by other independent systems. The metadata defined here will be ignored by dep.
|
||||
# [metadata]
|
||||
# key1 = "value that convey data to other systems"
|
||||
# system1-data = "value that is used by a system"
|
||||
# system2-data = "value that is used by another system"
|
||||
|
||||
## Overrides have the same structure as [[constraint]], but supersede all
|
||||
## [[constraint]] declarations from all projects. Only [[override]] from
|
||||
## the current project's are applied.
|
||||
##
|
||||
## Overrides are a sledgehammer. Use them only as a last resort.
|
||||
# [[override]]
|
||||
## Required: the root import path of the project being constrained.
|
||||
# name = "github.com/user/project"
|
||||
#
|
||||
## Optional: specifying a version constraint override will cause all other
|
||||
## constraints on this project to be ignored; only the overridden constraint
|
||||
## need be satisfied.
|
||||
## Again, only one of "branch", "version" or "revision" can be specified.
|
||||
# version = "1.0.0"
|
||||
# branch = "master"
|
||||
# revision = "abc123"
|
||||
#
|
||||
## Optional: specifying an alternate source location as an override will
|
||||
## enforce that the alternate location is used for that project, regardless of
|
||||
## what source location any dependent projects specify.
|
||||
# source = "https://github.com/myfork/package.git"
|
||||
|
||||
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/CrowdSurge/banner"
|
201
vendor/github.com/kris-nova/lolgopher/LICENSE.md
generated
vendored
Normal file
201
vendor/github.com/kris-nova/lolgopher/LICENSE.md
generated
vendored
Normal file
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2018 Kris Nova
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
22
vendor/github.com/kris-nova/lolgopher/README.md
generated
vendored
Normal file
22
vendor/github.com/kris-nova/lolgopher/README.md
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
# lolgopher
|
||||
|
||||
<p align="center"><img src="img/kubicorn.png" width="420"></p>
|
||||
|
||||
Rainbow Writer implementation for Golang
|
||||
|
||||
Based on https://github.com/busyloop/lolcat.
|
||||
|
||||
<img src="https://github.com/ashleymcnamara/gophers/blob/master/NERDY.png" width="60"> Proudly packaged with Golang [dep](https://github.com/golang/dep)
|
||||
|
||||
## Installing
|
||||
|
||||
```
|
||||
$ go get github.com/kris-nova/lolgopher
|
||||
```
|
||||
|
||||
##### From Source
|
||||
|
||||
```
|
||||
cd $GOPATH/src/github.com/kris-nova/lolgopher
|
||||
go install .
|
||||
```
|
17
vendor/github.com/kris-nova/lolgopher/color.go
generated
vendored
Normal file
17
vendor/github.com/kris-nova/lolgopher/color.go
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
package lol
|
||||
|
||||
// colorer is an interface that can be used to colorize an io.Writer. Each
|
||||
// colorer is designed to support a specific terminal color schema (256, 0, etc).
|
||||
type colorer interface {
|
||||
|
||||
// Rainbow will calculate the current color spectrum for RGB colors only.
|
||||
// Each implementation other than truecolor will need to implement rainbow
|
||||
// and handle it accordingly.
|
||||
rainbow(freq float64, i float64)
|
||||
|
||||
// Return the ASCII escape code for this color for this particular byte
|
||||
format() []byte
|
||||
|
||||
// Reset the most recent ASCII code opened
|
||||
reset() []byte
|
||||
}
|
21
vendor/github.com/kris-nova/lolgopher/color_0.go
generated
vendored
Normal file
21
vendor/github.com/kris-nova/lolgopher/color_0.go
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
package lol
|
||||
|
||||
type color0 struct {
|
||||
R, G, B uint8
|
||||
}
|
||||
|
||||
func (c *color0) rainbow(freq float64, i float64) {
|
||||
// No calculation for no color support
|
||||
}
|
||||
|
||||
func (c *color0) format() []byte {
|
||||
return []byte("")
|
||||
}
|
||||
|
||||
func (c *color0) reset() []byte {
|
||||
return []byte("")
|
||||
}
|
||||
|
||||
func New0Colorer() colorer {
|
||||
return &color0{}
|
||||
}
|
39
vendor/github.com/kris-nova/lolgopher/color_256.go
generated
vendored
Normal file
39
vendor/github.com/kris-nova/lolgopher/color_256.go
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
package lol
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
type color256 struct {
|
||||
R, G, B uint8
|
||||
}
|
||||
|
||||
func (c *color256) rainbow(freq float64, i float64) {
|
||||
c.R = uint8(math.Floor(math.Sin(freq*i+0)*127)) + 128
|
||||
c.G = uint8(math.Floor(math.Sin(freq*i+2.0*math.Pi/3.0)*127)) + 128
|
||||
c.B = uint8(math.Floor(math.Sin(freq*i+4.0*math.Pi/3.0)*127)) + 128
|
||||
}
|
||||
|
||||
func (c *color256) format() []byte {
|
||||
|
||||
// Support for grayscale colors
|
||||
if c.R == c.G && c.G == c.B && int(c.R) > 232 {
|
||||
return []byte(fmt.Sprintf("\x1b[38;5;%dm", int(c.R)))
|
||||
}
|
||||
|
||||
// Math for 256: We use the closest value possible
|
||||
r6 := (uint16(c.R) * 3) / 255
|
||||
g6 := (uint16(c.G) * 3) / 255
|
||||
b6 := (uint16(c.B) * 3) / 255
|
||||
i := 36*r6 + 6*g6 + b6
|
||||
return []byte(fmt.Sprintf("\x1b[38;5;%dm", i))
|
||||
}
|
||||
|
||||
func (c *color256) reset() []byte {
|
||||
return []byte("\x1b[0m")
|
||||
}
|
||||
|
||||
func New256Colorer() colorer {
|
||||
return &color256{}
|
||||
}
|
28
vendor/github.com/kris-nova/lolgopher/color_truecolor.go
generated
vendored
Normal file
28
vendor/github.com/kris-nova/lolgopher/color_truecolor.go
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
package lol
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
type truecolor struct {
|
||||
R, G, B uint8
|
||||
}
|
||||
|
||||
func (c *truecolor) rainbow(freq float64, i float64) {
|
||||
c.R = uint8(math.Floor(math.Sin(freq*i+0)*127)) + 128
|
||||
c.G = uint8(math.Floor(math.Sin(freq*i+2.0*math.Pi/3.0)*127)) + 128
|
||||
c.B = uint8(math.Floor(math.Sin(freq*i+4.0*math.Pi/3.0)*127)) + 128
|
||||
}
|
||||
|
||||
func (c *truecolor) format() []byte {
|
||||
return []byte(fmt.Sprintf("\x1b[38;2;%d;%d;%dm", c.R, c.G, c.B))
|
||||
}
|
||||
|
||||
func (c *truecolor) reset() []byte {
|
||||
return []byte("\x1b[0m")
|
||||
}
|
||||
|
||||
func newTruecolorColorer() colorer {
|
||||
return &truecolor{}
|
||||
}
|
7
vendor/github.com/kris-nova/lolgopher/output.go
generated
vendored
Normal file
7
vendor/github.com/kris-nova/lolgopher/output.go
generated
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
// +build !windows
|
||||
|
||||
package lol
|
||||
|
||||
import "os"
|
||||
|
||||
var stdout = os.Stdout
|
7
vendor/github.com/kris-nova/lolgopher/output_windows.go
generated
vendored
Normal file
7
vendor/github.com/kris-nova/lolgopher/output_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
// +build windows
|
||||
|
||||
package lol
|
||||
|
||||
import colorable "github.com/mattn/go-colorable"
|
||||
|
||||
var stdout = colorable.NewColorableStdout()
|
15
vendor/github.com/kris-nova/lolgopher/print.go
generated
vendored
Normal file
15
vendor/github.com/kris-nova/lolgopher/print.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
package lol
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var w = &Writer{Output: stdout, ColorMode: ColorMode256}
|
||||
|
||||
func Println(a ...interface{}) (n int, err error) {
|
||||
return fmt.Fprintln(w, a...)
|
||||
}
|
||||
|
||||
func Printf(format string, a ...interface{}) (n int, err error) {
|
||||
return fmt.Fprintf(w, format, a...)
|
||||
}
|
134
vendor/github.com/kris-nova/lolgopher/writer.go
generated
vendored
Normal file
134
vendor/github.com/kris-nova/lolgopher/writer.go
generated
vendored
Normal file
|
@ -0,0 +1,134 @@
|
|||
package lol
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
isatty "github.com/mattn/go-isatty"
|
||||
)
|
||||
|
||||
const (
|
||||
DEFAULT_SPREAD = float64(3.0)
|
||||
DEFAULT_FREQ = float64(0.1)
|
||||
DEFAULT_ORIGIN = 0
|
||||
)
|
||||
|
||||
const (
|
||||
ColorModeTrueColor = iota
|
||||
ColorMode256
|
||||
ColorMode0
|
||||
)
|
||||
|
||||
// LolWriter writes a little lol-er.
|
||||
type Writer struct {
|
||||
Output io.Writer
|
||||
ColorMode int
|
||||
Freq float64
|
||||
Spread float64
|
||||
lineIdx int
|
||||
Origin int
|
||||
}
|
||||
|
||||
var noColor = os.Getenv("TERM") == "dumb" || (!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()))
|
||||
|
||||
// writeRaw will write a lol'd s to the underlying writer. It does no line
|
||||
// detection.
|
||||
func (w *Writer) writeRaw(s string) (int, error) {
|
||||
c, err := w.getColorer()
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
nWritten := 0
|
||||
for _, r := range s {
|
||||
c.rainbow(w.Freq, float64(w.Origin)+float64(w.lineIdx)/w.Spread)
|
||||
_, err := w.Output.Write(c.format())
|
||||
if err != nil {
|
||||
return nWritten, err
|
||||
}
|
||||
n, err := w.Output.Write([]byte(string(r)))
|
||||
if err != nil {
|
||||
return nWritten, err
|
||||
}
|
||||
_, err = w.Output.Write(c.reset())
|
||||
if err != nil {
|
||||
return nWritten, err
|
||||
}
|
||||
nWritten += n
|
||||
w.lineIdx++
|
||||
}
|
||||
return nWritten, nil
|
||||
}
|
||||
|
||||
// getColorer will attempt to map the defined color mode, to a colorer{}
|
||||
func (w *Writer) getColorer() (colorer, error) {
|
||||
switch w.ColorMode {
|
||||
case ColorModeTrueColor:
|
||||
return newTruecolorColorer(), nil
|
||||
case ColorMode256:
|
||||
return New256Colorer(), nil
|
||||
case ColorMode0:
|
||||
return New0Colorer(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("Invalid colorer: [%d]", w.ColorMode)
|
||||
}
|
||||
}
|
||||
|
||||
// Write will write a byte slice to the Writer
|
||||
func (w *Writer) Write(p []byte) (int, error) {
|
||||
nWritten := 0
|
||||
ss := strings.Split(string(p), "\n")
|
||||
for i, s := range ss {
|
||||
// TODO: strip out pre-existing ANSI codes and expand tabs. Would be
|
||||
// great to expand tabs in a context aware way (line linux expand
|
||||
// command).
|
||||
|
||||
n, err := w.writeRaw(s)
|
||||
if err != nil {
|
||||
return nWritten, err
|
||||
}
|
||||
nWritten += n
|
||||
|
||||
// Increment the Origin (line count) for each newline. There is a
|
||||
// newline for every item in this array except the last one.
|
||||
if i != len(ss)-1 {
|
||||
n, err := w.Output.Write([]byte("\n"))
|
||||
if err != nil {
|
||||
return nWritten, err
|
||||
}
|
||||
nWritten += n
|
||||
w.Origin++
|
||||
w.lineIdx = 0
|
||||
}
|
||||
}
|
||||
return nWritten, nil
|
||||
}
|
||||
|
||||
// NewLolWriter will return a new io.Writer with a default ColorMode of 256
|
||||
func NewLolWriter() io.Writer {
|
||||
colorMode := ColorMode256
|
||||
if noColor {
|
||||
colorMode = ColorMode0
|
||||
}
|
||||
|
||||
return &Writer{
|
||||
Output: stdout,
|
||||
ColorMode: colorMode,
|
||||
Freq: DEFAULT_FREQ,
|
||||
Spread: DEFAULT_SPREAD,
|
||||
Origin: DEFAULT_ORIGIN,
|
||||
}
|
||||
}
|
||||
|
||||
// NewTruecolorLolWriter will return a new io.Writer with a default ColorMode of truecolor
|
||||
func NewTruecolorLolWriter() io.Writer {
|
||||
colorMode := ColorModeTrueColor
|
||||
if noColor {
|
||||
colorMode = ColorMode0
|
||||
}
|
||||
return &Writer{
|
||||
Output: stdout,
|
||||
ColorMode: colorMode,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue