diff options
author | Michael Muré <batolettre@gmail.com> | 2023-01-17 22:05:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-17 22:05:29 +0100 |
commit | 0290091317deb9e6c0ff99f9217065168620d2f0 (patch) | |
tree | ef4b86e5b4ea357f43685f58a9d2f19bac5e8b3a /commands/execenv/env.go | |
parent | e689cc506775ec1daccaae9ec35c7a28b48b2f05 (diff) | |
parent | f23a7f07cc9d7e9b9407e0fcb99de6904f1b52a8 (diff) | |
download | git-bug-0290091317deb9e6c0ff99f9217065168620d2f0.tar.gz |
Merge pull request #993 from MichaelMure/cmd-adapt
command: adapt the output of the bug list to the terminal size
Diffstat (limited to 'commands/execenv/env.go')
-rw-r--r-- | commands/execenv/env.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/commands/execenv/env.go b/commands/execenv/env.go index 46de8401..e693807e 100644 --- a/commands/execenv/env.go +++ b/commands/execenv/env.go @@ -7,6 +7,7 @@ import ( "os" "github.com/mattn/go-isatty" + "golang.org/x/term" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/repository" @@ -57,6 +58,8 @@ type Out interface { // IsTerminal tells if the output is a user terminal (rather than a buffer, // a pipe ...), which tells if we can use colors and other interactive features. IsTerminal() bool + // Width return the width of the attached terminal, or a good enough value. + Width() int // Raw return the underlying io.Writer, or itself if not. // This is useful if something need to access the raw file descriptor. @@ -123,6 +126,16 @@ func (o out) IsTerminal() bool { return false } +func (o out) Width() int { + if f, ok := o.Raw().(*os.File); ok { + width, _, err := term.GetSize(int(f.Fd())) + if err == nil { + return width + } + } + return 80 +} + func (o out) Raw() io.Writer { return o.Writer } |