From 9cf9bfb906999f40ad8798e33a5e4ad8ae45525c Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Thu, 5 Jun 2014 15:41:25 -0600 Subject: [PATCH] add ts package, needed for windows --- .../src/github.com/olekukonko/ts/.travis.yml | 6 ++ .vendor/src/github.com/olekukonko/ts/LICENCE | 19 ++++++ .../src/github.com/olekukonko/ts/README.md | 28 ++++++++ .vendor/src/github.com/olekukonko/ts/doc.go | 36 +++++++++++ .vendor/src/github.com/olekukonko/ts/ts.go | 36 +++++++++++ .../src/github.com/olekukonko/ts/ts_darwin.go | 14 ++++ .../src/github.com/olekukonko/ts/ts_linux.go | 13 ++++ .../src/github.com/olekukonko/ts/ts_other.go | 14 ++++ .../src/github.com/olekukonko/ts/ts_test.go | 32 ++++++++++ .../src/github.com/olekukonko/ts/ts_unix.go | 14 ++++ .../github.com/olekukonko/ts/ts_windows.go | 64 +++++++++++++++++++ .vendor/src/github.com/olekukonko/ts/ts_x.go | 46 +++++++++++++ Godeps | 1 + 13 files changed, 323 insertions(+) create mode 100644 .vendor/src/github.com/olekukonko/ts/.travis.yml create mode 100644 .vendor/src/github.com/olekukonko/ts/LICENCE create mode 100644 .vendor/src/github.com/olekukonko/ts/README.md create mode 100644 .vendor/src/github.com/olekukonko/ts/doc.go create mode 100644 .vendor/src/github.com/olekukonko/ts/ts.go create mode 100644 .vendor/src/github.com/olekukonko/ts/ts_darwin.go create mode 100644 .vendor/src/github.com/olekukonko/ts/ts_linux.go create mode 100644 .vendor/src/github.com/olekukonko/ts/ts_other.go create mode 100644 .vendor/src/github.com/olekukonko/ts/ts_test.go create mode 100644 .vendor/src/github.com/olekukonko/ts/ts_unix.go create mode 100644 .vendor/src/github.com/olekukonko/ts/ts_windows.go create mode 100644 .vendor/src/github.com/olekukonko/ts/ts_x.go diff --git a/.vendor/src/github.com/olekukonko/ts/.travis.yml b/.vendor/src/github.com/olekukonko/ts/.travis.yml new file mode 100644 index 00000000..e53b2de3 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/.travis.yml @@ -0,0 +1,6 @@ +language: go + +go: + - 1.1 + - 1.2 + - tip \ No newline at end of file diff --git a/.vendor/src/github.com/olekukonko/ts/LICENCE b/.vendor/src/github.com/olekukonko/ts/LICENCE new file mode 100644 index 00000000..1fd84842 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/LICENCE @@ -0,0 +1,19 @@ +Copyright (C) 2014 by Oleku Konko + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/.vendor/src/github.com/olekukonko/ts/README.md b/.vendor/src/github.com/olekukonko/ts/README.md new file mode 100644 index 00000000..4e1598b1 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/README.md @@ -0,0 +1,28 @@ +ts (Terminal Size) +== + +[![Build Status](https://travis-ci.org/olekukonko/ts.png?branch=master)](https://travis-ci.org/olekukonko/ts) [![Total views](https://sourcegraph.com/api/repos/github.com/olekukonko/ts/counters/views.png)](https://sourcegraph.com/github.com/olekukonko/ts) + +Simple go Application to get Terminal Size. So Many Implementations do not support windows but `ts` has full windows support. +Run `go get github.com/olekukonko/ts` to download and install + +#### Example + +```go +package main + +import ( + "fmt" + "github.com/olekukonko/ts" +) + +func main() { + size, _ := ts.GetSize() + fmt.Println(size.Col()) // Get Width + fmt.Println(size.Row()) // Get Height + fmt.Println(size.PosX()) // Get X position + fmt.Println(size.PosY()) // Get Y position +} +``` + +[See Documentation](http://godoc.org/github.com/olekukonko/ts) diff --git a/.vendor/src/github.com/olekukonko/ts/doc.go b/.vendor/src/github.com/olekukonko/ts/doc.go new file mode 100644 index 00000000..50c63cae --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/doc.go @@ -0,0 +1,36 @@ +// Copyright 2014 Oleku Konko All rights reserved. +// Use of this source code is governed by a MIT +// license that can be found in the LICENSE file. + +// This module is a Terminal API for the Go Programming Language. +// The protocols were written in pure Go and works on windows and unix systems + +/** + +Simple go Application to get Terminal Size. So Many Implementations do not support windows but `ts` has full windows support. +Run `go get github.com/olekukonko/ts` to download and install + +Installation + +Minimum requirements are Go 1.1+ with fill Windows support + +Example + + package main + + import ( + "fmt" + "github.com/olekukonko/ts" + ) + + func main() { + size, _ := ts.GetSize() + fmt.Println(size.Col()) // Get Width + fmt.Println(size.Row()) // Get Height + fmt.Println(size.PosX()) // Get X position + fmt.Println(size.PosY()) // Get Y position + } + +**/ + +package ts diff --git a/.vendor/src/github.com/olekukonko/ts/ts.go b/.vendor/src/github.com/olekukonko/ts/ts.go new file mode 100644 index 00000000..35fdf742 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/ts.go @@ -0,0 +1,36 @@ +// Copyright 2014 Oleku Konko All rights reserved. +// Use of this source code is governed by a MIT +// license that can be found in the LICENSE file. + +// This module is a Terminal API for the Go Programming Language. +// The protocols were written in pure Go and works on windows and unix systems + +package ts + +// Return System Size +type Size struct { + row uint16 + col uint16 + posX uint16 + posY uint16 +} + +// Get Terminal Width +func (w Size) Col() int { + return int(w.col) +} + +// Get Terminal Height +func (w Size) Row() int { + return int(w.row) +} + +// Get Position X +func (w Size) PosX() int { + return int(w.posX) +} + +// Get Position Y +func (w Size) PosY() int { + return int(w.posY) +} diff --git a/.vendor/src/github.com/olekukonko/ts/ts_darwin.go b/.vendor/src/github.com/olekukonko/ts/ts_darwin.go new file mode 100644 index 00000000..bdcf42b4 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/ts_darwin.go @@ -0,0 +1,14 @@ +// +build darwin + +// Copyright 2014 Oleku Konko All rights reserved. +// Use of this source code is governed by a MIT +// license that can be found in the LICENSE file. + +// This module is a Terminal API for the Go Programming Language. +// The protocols were written in pure Go and works on windows and unix systems + +package ts + +const ( + TIOCGWINSZ = 0x40087468 +) diff --git a/.vendor/src/github.com/olekukonko/ts/ts_linux.go b/.vendor/src/github.com/olekukonko/ts/ts_linux.go new file mode 100644 index 00000000..ee2db6d4 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/ts_linux.go @@ -0,0 +1,13 @@ +// +build linux + +// Copyright 2014 Oleku Konko All rights reserved. +// Use of this source code is governed by a MIT +// license that can be found in the LICENSE file. + +// This module is a Terminal API for the Go Programming Language. +// The protocols were written in pure Go and works on windows and unix systems +package ts + +const ( + TIOCGWINSZ = 0x5413 +) diff --git a/.vendor/src/github.com/olekukonko/ts/ts_other.go b/.vendor/src/github.com/olekukonko/ts/ts_other.go new file mode 100644 index 00000000..bf804819 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/ts_other.go @@ -0,0 +1,14 @@ +// +build !windows,!darwin,!freebsd,!netbsd,!openbsd,!linux + +// Copyright 2014 Oleku Konko All rights reserved. +// Use of this source code is governed by a MIT +// license that can be found in the LICENSE file. + +// This module is a Terminal API for the Go Programming Language. +// The protocols were written in pure Go and works on windows and unix systems + +package ts + +const ( + TIOCGWINSZ = 0 +) diff --git a/.vendor/src/github.com/olekukonko/ts/ts_test.go b/.vendor/src/github.com/olekukonko/ts/ts_test.go new file mode 100644 index 00000000..4998e7c0 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/ts_test.go @@ -0,0 +1,32 @@ +// Copyright 2014 Oleku Konko All rights reserved. +// Use of this source code is governed by a MIT +// license that can be found in the LICENSE file. + +// This module is a Terminal API for the Go Programming Language. +// The protocols were written in pure Go and works on windows and unix systems + +package ts + +import ( + "fmt" + "testing" +) + +func ExampleGetSize() { + size, _ := GetSize() + fmt.Println(size.Col()) // Get Width + fmt.Println(size.Row()) // Get Height + fmt.Println(size.PosX()) // Get X position + fmt.Println(size.PosY()) // Get Y position +} + +func TestSize(t *testing.T) { + size, err := GetSize() + + if err != nil { + t.Fatal(err) + } + if size.Col() == 0 || size.Row() == 0 { + t.Fatalf("Screen Size Failed") + } +} diff --git a/.vendor/src/github.com/olekukonko/ts/ts_unix.go b/.vendor/src/github.com/olekukonko/ts/ts_unix.go new file mode 100644 index 00000000..8728b614 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/ts_unix.go @@ -0,0 +1,14 @@ +// +build freebsd netbsd openbsd + +// Copyright 2014 Oleku Konko All rights reserved. +// Use of this source code is governed by a MIT +// license that can be found in the LICENSE file. + +// This module is a Terminal API for the Go Programming Language. +// The protocols were written in pure Go and works on windows and unix systems + +package ts + +const ( + TIOCGWINSZ = 0x40087468 +) diff --git a/.vendor/src/github.com/olekukonko/ts/ts_windows.go b/.vendor/src/github.com/olekukonko/ts/ts_windows.go new file mode 100644 index 00000000..2f34d569 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/ts_windows.go @@ -0,0 +1,64 @@ +// +build windows + +// Copyright 2014 Oleku Konko All rights reserved. +// Use of this source code is governed by a MIT +// license that can be found in the LICENSE file. + +// This module is a Terminal API for the Go Programming Language. +// The protocols were written in pure Go and works on windows and unix systems + +package ts + +import ( + "syscall" + "unsafe" +) + +var ( + kernel32 = syscall.NewLazyDLL("kernel32.dll") + + // Retrieves information about the specified console screen buffer. + // See http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx + screenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo") +) + +// Contains information about a console screen buffer. +// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682093(v=vs.85).aspx +type CONSOLE_SCREEN_BUFFER_INFO struct { + DwSize COORD + DwCursorPosition COORD + WAttributes uint16 + SrWindow SMALL_RECT + DwMaximumWindowSize COORD +} + +// Defines the coordinates of a character cell in a console screen buffer. +// The origin of the coordinate system (0,0) is at the top, left cell of the buffer. +// See http://msdn.microsoft.com/en-us/library/windows/desktop/ms682119(v=vs.85).aspx +type COORD struct { + X, Y uint16 +} + +// Defines the coordinates of the upper left and lower right corners of a rectangle. +// See http://msdn.microsoft.com/en-us/library/windows/desktop/ms686311(v=vs.85).aspx +type SMALL_RECT struct { + Left, Top, Right, Bottom uint16 +} + +func GetSize() (ws Size, err error) { + var info CONSOLE_SCREEN_BUFFER_INFO + rc, _, err := screenBufferInfo.Call( + uintptr(syscall.Stdout), + uintptr(unsafe.Pointer(&info))) + + if rc == 0 { + return ws, err + } + + ws = Size{info.SrWindow.Bottom, + info.SrWindow.Right, + info.DwCursorPosition.X, + info.DwCursorPosition.Y} + + return ws, nil +} diff --git a/.vendor/src/github.com/olekukonko/ts/ts_x.go b/.vendor/src/github.com/olekukonko/ts/ts_x.go new file mode 100644 index 00000000..1b260e38 --- /dev/null +++ b/.vendor/src/github.com/olekukonko/ts/ts_x.go @@ -0,0 +1,46 @@ +// +build !windows + +// Copyright 2014 Oleku Konko All rights reserved. +// Use of this source code is governed by a MIT +// license that can be found in the LICENSE file. + +// This module is a Terminal API for the Go Programming Language. +// The protocols were written in pure Go and works on windows and unix systems + +package ts + +import ( + "syscall" + "unsafe" +) + +// Get Windows Size +func GetSize() (ws Size, err error) { + _, _, ec := syscall.Syscall(syscall.SYS_IOCTL, + uintptr(syscall.Stdout), + uintptr(TIOCGWINSZ), + uintptr(unsafe.Pointer(&ws))) + + err = getError(ec) + + if TIOCGWINSZ == 0 && err != nil { + ws = Size{80, 25, 0, 0} + } + return ws, err +} + +func getError(ec interface{}) (err error) { + switch v := ec.(type) { + + case syscall.Errno: // Some implementation return syscall.Errno number + if v != 0 { + err = syscall.Errno(v) + } + + case error: // Some implementation return error + err = ec.(error) + default: + err = nil + } + return +} diff --git a/Godeps b/Godeps index a7145588..d41063a3 100644 --- a/Godeps +++ b/Godeps @@ -2,4 +2,5 @@ github.com/bmizerany/assert e17e99893cb6509f428e1728281c2ad60a6b31e3 github.com/cheggaaa/pb e31a080772d3b0a093038a1d8cb7741c2f4c7ed3 github.com/kr/pretty bc9499caa0f45ee5edb2f0209fbd61fbf3d9018f github.com/kr/text 6807e777504f54ad073ecef66747de158294b639 +github.com/olekukonko/ts ecf753e7c962639ab5a1fb46f7da627d4c0a04b8 github.com/streadway/simpleuuid 6617b501e485b77e61b98cd533aefff9e258b5a7