mirror of https://github.com/docker/compose.git
Get the real width of the terminal
github.com/buger/goterm always returns 80 on windows...
This commit is contained in:
parent
78cb0a87c7
commit
e6c115dc17
11
azure/aci.go
11
azure/aci.go
|
@ -27,7 +27,6 @@ import (
|
||||||
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance"
|
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance"
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/to"
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
"github.com/buger/goterm"
|
|
||||||
tm "github.com/buger/goterm"
|
tm "github.com/buger/goterm"
|
||||||
"github.com/gobwas/ws"
|
"github.com/gobwas/ws"
|
||||||
"github.com/gobwas/ws/wsutil"
|
"github.com/gobwas/ws/wsutil"
|
||||||
|
@ -36,6 +35,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/api/azure/convert"
|
"github.com/docker/api/azure/convert"
|
||||||
"github.com/docker/api/azure/login"
|
"github.com/docker/api/azure/login"
|
||||||
|
"github.com/docker/api/containers"
|
||||||
"github.com/docker/api/context/store"
|
"github.com/docker/api/context/store"
|
||||||
"github.com/docker/api/progress"
|
"github.com/docker/api/progress"
|
||||||
)
|
)
|
||||||
|
@ -242,8 +242,7 @@ func getACIContainerLogs(ctx context.Context, aciContext store.AciContext, conta
|
||||||
return *logs.Content, err
|
return *logs.Content, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func streamLogs(ctx context.Context, aciContext store.AciContext, containerGroupName, containerName string, out io.Writer) error {
|
func streamLogs(ctx context.Context, aciContext store.AciContext, containerGroupName, containerName string, req containers.LogsRequest) error {
|
||||||
terminalWidth := goterm.Width()
|
|
||||||
numLines := 0
|
numLines := 0
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -263,12 +262,12 @@ func streamLogs(ctx context.Context, aciContext store.AciContext, containerGroup
|
||||||
// a real logs streaming api soon.
|
// a real logs streaming api soon.
|
||||||
b := aec.EmptyBuilder
|
b := aec.EmptyBuilder
|
||||||
b = b.Up(uint(numLines))
|
b = b.Up(uint(numLines))
|
||||||
fmt.Fprint(out, b.Column(0).ANSI)
|
fmt.Fprint(req.Writer, b.Column(0).ANSI)
|
||||||
|
|
||||||
numLines = getBacktrackLines(logLines, terminalWidth)
|
numLines = getBacktrackLines(logLines, req.Width)
|
||||||
|
|
||||||
for i := 0; i < currentOutput-1; i++ {
|
for i := 0; i < currentOutput-1; i++ {
|
||||||
fmt.Fprintln(out, logLines[i])
|
fmt.Fprintln(req.Writer, logLines[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|
|
@ -226,7 +226,7 @@ func (cs *aciContainerService) Logs(ctx context.Context, containerName string, r
|
||||||
var tail *int32
|
var tail *int32
|
||||||
|
|
||||||
if req.Follow {
|
if req.Follow {
|
||||||
return streamLogs(ctx, cs.ctx, groupName, containerAciName, req.Writer)
|
return streamLogs(ctx, cs.ctx, groupName, containerAciName, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Tail != "all" {
|
if req.Tail != "all" {
|
||||||
|
|
|
@ -57,16 +57,23 @@ func runLogs(ctx context.Context, containerName string, opts logsOpts) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "cannot connect to backend")
|
return errors.Wrap(err, "cannot connect to backend")
|
||||||
}
|
}
|
||||||
var con io.Writer = os.Stdout
|
|
||||||
if c, err := console.ConsoleFromFile(os.Stdout); err == nil {
|
|
||||||
con = c
|
|
||||||
}
|
|
||||||
|
|
||||||
req := containers.LogsRequest{
|
req := containers.LogsRequest{
|
||||||
Follow: opts.Follow,
|
Follow: opts.Follow,
|
||||||
Tail: opts.Tail,
|
Tail: opts.Tail,
|
||||||
Writer: con,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var con io.Writer = os.Stdout
|
||||||
|
if c, err := console.ConsoleFromFile(os.Stdout); err == nil {
|
||||||
|
size, err := c.Size()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req.Width = int(size.Width)
|
||||||
|
con = c
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Writer = con
|
||||||
|
|
||||||
return c.ContainerService().Logs(ctx, containerName, req)
|
return c.ContainerService().Logs(ctx, containerName, req)
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,19 +73,27 @@ func runRun(ctx context.Context, image string, opts run.Opts) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !opts.Detach {
|
if !opts.Detach {
|
||||||
var con io.Writer = os.Stdout
|
var con io.Writer = os.Stdout
|
||||||
|
req := containers.LogsRequest{
|
||||||
|
Follow: true,
|
||||||
|
}
|
||||||
if c, err := console.ConsoleFromFile(os.Stdout); err == nil {
|
if c, err := console.ConsoleFromFile(os.Stdout); err == nil {
|
||||||
|
size, err := c.Size()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req.Width = int(size.Width)
|
||||||
con = c
|
con = c
|
||||||
}
|
}
|
||||||
|
|
||||||
req := containers.LogsRequest{
|
req.Writer = con
|
||||||
Follow: true,
|
|
||||||
Writer: con,
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.ContainerService().Logs(ctx, opts.Name, req)
|
return c.ContainerService().Logs(ctx, opts.Name, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(opts.Name)
|
fmt.Println(opts.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ type ContainerConfig struct {
|
||||||
type LogsRequest struct {
|
type LogsRequest struct {
|
||||||
Follow bool
|
Follow bool
|
||||||
Tail string
|
Tail string
|
||||||
|
Width int
|
||||||
Writer io.Writer
|
Writer io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue