[lxc-devel] [lxd/master] lxc/file: Dynamically shrinks output for long files
tomponline on Github
lxc-bot at linuxcontainers.org
Wed Apr 17 13:20:09 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 454 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190417/232fabe7/attachment.bin>
-------------- next part --------------
From 769139c0c8bd923934745e18cd7e683080df9845 Mon Sep 17 00:00:00 2001
From: tomponline <thomas.parrott at canonical.com>
Date: Wed, 17 Apr 2019 09:13:35 +0100
Subject: [PATCH] lxc/file: Dynamically shrinks output for long files when
using `lxc file pull`
Fixes #5668
Signed-off-by: tomponline <thomas.parrott at canonical.com>
---
lxc/file.go | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/lxc/file.go b/lxc/file.go
index b81869f482..4fb6b74b1f 100644
--- a/lxc/file.go
+++ b/lxc/file.go
@@ -330,8 +330,25 @@ func (c *cmdFilePull) Run(cmd *cobra.Command, args []string) error {
}
}
+ width, _, err := termios.GetSize(int(os.Stdout.Fd()))
+ if err != nil {
+ return err
+ }
+
+ width = width - 40 //Remove space used by fixed labels and status, e.g. "Pulling ? from ?: ???.??MB (???.??MB/s)"
+ targetPathFmt := targetPath
+ pathSpecFmt := pathSpec[1]
+ splitStr := "..."
+ if len(targetPathFmt) > (width / 2) {
+ targetPathFmt = targetPath[:(width/4)-len(splitStr)] + splitStr + targetPath[len(targetPath)-(width/4):]
+ }
+
+ if len(pathSpecFmt) > (width / 2) {
+ pathSpecFmt = pathSpecFmt[:(width/4)-len(splitStr)] + splitStr + pathSpecFmt[len(pathSpecFmt)-(width/4):]
+ }
+
progress := utils.ProgressRenderer{
- Format: fmt.Sprintf(i18n.G("Pulling %s from %s: %%s"), targetPath, pathSpec[1]),
+ Format: fmt.Sprintf(i18n.G("Pulling %s from %s: %%s"), targetPathFmt, pathSpecFmt),
Quiet: c.global.flagQuiet,
}
More information about the lxc-devel
mailing list