mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Conver to regular Go vendor + dep tool
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
example/example
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
Copyright (c) 2013 Meng Zhang. 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.
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
## Terminal ##
|
||||
Terminal is a simple golang package that provides basic terminal handling.
|
||||
|
||||
Terminal wraps color/format functions provided by [ANSI escape code](http://en.wikipedia.org/wiki/ANSI_escape_code)
|
||||
|
||||
## Usage ##
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/wsxiaoys/terminal"
|
||||
"github.com/wsxiaoys/terminal/color"
|
||||
)
|
||||
|
||||
func main() {
|
||||
terminal.Stdout.Color("y").
|
||||
Print("Hello world").Nl().
|
||||
Reset().
|
||||
Colorf("@{kW}Hello world\n")
|
||||
|
||||
color.Print("@rHello world")
|
||||
}
|
||||
```
|
||||
Check the [godoc result](https://godoc.org/github.com/wsxiaoys/terminal) for more details.
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
// The colors package provide a simple way to bring colorful characters to terminal interface.
|
||||
//
|
||||
// This example will output the text with a Blue foreground and a Black background
|
||||
// color.Println("@{bK}Example Text")
|
||||
//
|
||||
// This one will output the text with a red foreground
|
||||
// color.Println("@rExample Text")
|
||||
//
|
||||
// This one will escape the @
|
||||
// color.Println("@@")
|
||||
//
|
||||
// Full color syntax code
|
||||
// @{rgbcmykwRGBCMYKW} foreground/background color
|
||||
// r/R: Red
|
||||
// g/G: Green
|
||||
// b/B: Blue
|
||||
// c/C: Cyan
|
||||
// m/M: Magenta
|
||||
// y/Y: Yellow
|
||||
// k/K: Black
|
||||
// w/W: White
|
||||
// @{|} Reset format style
|
||||
// @{!./_} Bold / Dim / Italic / Underline
|
||||
// @{^&} Blink / Fast blink
|
||||
// @{*} High intensity foreground color
|
||||
// @{?} Reverse the foreground and background color
|
||||
// @{-} Hide the text
|
||||
// Note some of the functions are not widely supported, like "Fast blink" and "Italic".
|
||||
package color
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
)
|
||||
|
||||
const (
|
||||
EscapeChar = '@' // Escape character for color syntax
|
||||
ResetCode = "\033[0m" // Short for reset to default style
|
||||
)
|
||||
|
||||
// Mapping from character to concrete escape code.
|
||||
var codeMap = map[int]int{
|
||||
'|': 0,
|
||||
'!': 1,
|
||||
'.': 2,
|
||||
'/': 3,
|
||||
'_': 4,
|
||||
'^': 5,
|
||||
'&': 6,
|
||||
'?': 7,
|
||||
'-': 8,
|
||||
'*': 60,
|
||||
|
||||
'k': 30,
|
||||
'r': 31,
|
||||
'g': 32,
|
||||
'y': 33,
|
||||
'b': 34,
|
||||
'm': 35,
|
||||
'c': 36,
|
||||
'w': 37,
|
||||
'd': 39,
|
||||
|
||||
'K': 40,
|
||||
'R': 41,
|
||||
'G': 42,
|
||||
'Y': 43,
|
||||
'B': 44,
|
||||
'M': 45,
|
||||
'C': 46,
|
||||
'W': 47,
|
||||
'D': 49,
|
||||
}
|
||||
|
||||
// Compile color syntax string like "rG" to escape code.
|
||||
func Colorize(x string) string {
|
||||
attr := 0
|
||||
fg := 39
|
||||
bg := 49
|
||||
|
||||
for _, key := range x {
|
||||
c, ok := codeMap[int(key)]
|
||||
switch {
|
||||
case !ok:
|
||||
log.Printf("Wrong color syntax: %c", key)
|
||||
case 0 <= c && c <= 8:
|
||||
attr = c
|
||||
case 30 <= c && c <= 37:
|
||||
fg = c
|
||||
case 40 <= c && c <= 47:
|
||||
bg = c
|
||||
case c == 60:
|
||||
fg += c
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("\033[%d;%d;%dm", attr, fg, bg)
|
||||
}
|
||||
|
||||
// Handle state after meeting one '@'
|
||||
func compileColorSyntax(input, output *bytes.Buffer) {
|
||||
i, _, err := input.ReadRune()
|
||||
if err != nil {
|
||||
// EOF got
|
||||
log.Print("Parse failed on color syntax")
|
||||
return
|
||||
}
|
||||
|
||||
switch i {
|
||||
default:
|
||||
output.WriteString(Colorize(string(i)))
|
||||
case '{':
|
||||
color := bytes.NewBufferString("")
|
||||
for {
|
||||
i, _, err := input.ReadRune()
|
||||
if err != nil {
|
||||
log.Print("Parse failed on color syntax")
|
||||
break
|
||||
}
|
||||
if i == '}' {
|
||||
break
|
||||
}
|
||||
color.WriteRune(i)
|
||||
}
|
||||
output.WriteString(Colorize(color.String()))
|
||||
case EscapeChar:
|
||||
output.WriteRune(EscapeChar)
|
||||
}
|
||||
}
|
||||
|
||||
// Compile the string and replace color syntax with concrete escape code.
|
||||
func compile(x string) string {
|
||||
if x == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
input := bytes.NewBufferString(x)
|
||||
output := bytes.NewBufferString("")
|
||||
|
||||
for {
|
||||
i, _, err := input.ReadRune()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
switch i {
|
||||
default:
|
||||
output.WriteRune(i)
|
||||
case EscapeChar:
|
||||
compileColorSyntax(input, output)
|
||||
}
|
||||
}
|
||||
return output.String()
|
||||
}
|
||||
|
||||
// Compile multiple values, only do compiling on string type.
|
||||
func compileValues(a *[]interface{}) {
|
||||
for i, x := range *a {
|
||||
if str, ok := x.(string); ok {
|
||||
(*a)[i] = compile(str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Similar to fmt.Print, will reset the color at the end.
|
||||
func Print(a ...interface{}) (int, error) {
|
||||
a = append(a, ResetCode)
|
||||
compileValues(&a)
|
||||
return fmt.Print(a...)
|
||||
}
|
||||
|
||||
// Similar to fmt.Println, will reset the color at the end.
|
||||
func Println(a ...interface{}) (int, error) {
|
||||
a = append(a, ResetCode)
|
||||
compileValues(&a)
|
||||
return fmt.Println(a...)
|
||||
}
|
||||
|
||||
// Similar to fmt.Printf, will reset the color at the end.
|
||||
func Printf(format string, a ...interface{}) (int, error) {
|
||||
format += ResetCode
|
||||
format = compile(format)
|
||||
return fmt.Printf(format, a...)
|
||||
}
|
||||
|
||||
// Similar to fmt.Fprint, will reset the color at the end.
|
||||
func Fprint(w io.Writer, a ...interface{}) (int, error) {
|
||||
a = append(a, ResetCode)
|
||||
compileValues(&a)
|
||||
return fmt.Fprint(w, a...)
|
||||
}
|
||||
|
||||
// Similar to fmt.Fprintln, will reset the color at the end.
|
||||
func Fprintln(w io.Writer, a ...interface{}) (int, error) {
|
||||
a = append(a, ResetCode)
|
||||
compileValues(&a)
|
||||
return fmt.Fprintln(w, a...)
|
||||
}
|
||||
|
||||
// Similar to fmt.Fprintf, will reset the color at the end.
|
||||
func Fprintf(w io.Writer, format string, a ...interface{}) (int, error) {
|
||||
format += ResetCode
|
||||
format = compile(format)
|
||||
return fmt.Fprintf(w, format, a...)
|
||||
}
|
||||
|
||||
// Similar to fmt.Sprint, will reset the color at the end.
|
||||
func Sprint(a ...interface{}) string {
|
||||
a = append(a, ResetCode)
|
||||
compileValues(&a)
|
||||
return fmt.Sprint(a...)
|
||||
}
|
||||
|
||||
// Similar to fmt.Sprintf, will reset the color at the end.
|
||||
func Sprintf(format string, a ...interface{}) string {
|
||||
format += ResetCode
|
||||
format = compile(format)
|
||||
return fmt.Sprintf(format, a...)
|
||||
}
|
||||
|
||||
// Similar to fmt.Errorf, will reset the color at the end.
|
||||
func Errorf(format string, a ...interface{}) error {
|
||||
return errors.New(Sprintf(format, a...))
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/wsxiaoys/terminal"
|
||||
"github.com/wsxiaoys/terminal/color"
|
||||
)
|
||||
|
||||
func main() {
|
||||
terminal.Stdout.Color("y").
|
||||
Print("Hello world").Nl().
|
||||
Reset().
|
||||
Colorf("@{kW}Hello world\n")
|
||||
|
||||
color.Print("@rHello world")
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/wsxiaoys/terminal/color"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type TerminalWriter struct {
|
||||
io.Writer
|
||||
}
|
||||
|
||||
var (
|
||||
Stdout = &TerminalWriter{os.Stdout}
|
||||
Stderr = &TerminalWriter{os.Stderr}
|
||||
)
|
||||
|
||||
func (w *TerminalWriter) checkOutput(s string) {
|
||||
if _, err := io.WriteString(w, s); err != nil {
|
||||
log.Fatal("Write to %v failed.", w)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Color(syntax string) *TerminalWriter {
|
||||
escapeCode := color.Colorize(syntax)
|
||||
w.checkOutput(escapeCode)
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Reset() *TerminalWriter {
|
||||
w.checkOutput(color.ResetCode)
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Print(a ...interface{}) *TerminalWriter {
|
||||
fmt.Fprint(w, a...)
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Nl(a ...interface{}) *TerminalWriter {
|
||||
length := 1
|
||||
if len(a) > 0 {
|
||||
length = a[0].(int)
|
||||
}
|
||||
for i := 0; i < length; i++ {
|
||||
w.checkOutput("\n")
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Colorf(format string, a ...interface{}) *TerminalWriter {
|
||||
w.checkOutput(color.Sprintf(format, a...))
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Clear() *TerminalWriter {
|
||||
w.checkOutput("\033[2J")
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) ClearLine() *TerminalWriter {
|
||||
w.checkOutput("\033[2K")
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Move(x, y int) *TerminalWriter {
|
||||
w.checkOutput(fmt.Sprintf("\033[%d;%dH", x, y))
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Up(x int) *TerminalWriter {
|
||||
w.checkOutput(fmt.Sprintf("\033[%dA", x))
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Down(x int) *TerminalWriter {
|
||||
w.checkOutput(fmt.Sprintf("\033[%dB", x))
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Right(x int) *TerminalWriter {
|
||||
w.checkOutput(fmt.Sprintf("\033[%dC", x))
|
||||
return w
|
||||
}
|
||||
|
||||
func (w *TerminalWriter) Left(x int) *TerminalWriter {
|
||||
w.checkOutput(fmt.Sprintf("\033[%dD", x))
|
||||
return w
|
||||
}
|
||||
Reference in New Issue
Block a user