Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion pkg/cmd/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/oracle/coherence-cli/pkg/constants"
"github.com/oracle/coherence-cli/pkg/utils"
"github.com/oracle/coherence-go-client/coherence/discovery"
"golang.org/x/term"
"golang.org/x/text/language"
"golang.org/x/text/message"
"os"
Expand Down Expand Up @@ -2447,6 +2448,35 @@ func (t *formattedTable) String() string {
}
sb.WriteString("\n")
}

if limitOutput && watchClearEnabled {
// we limit the output to the size of the screen
if term.IsTerminal(0) {
_, height, err := term.GetSize(0)
if err == nil {
// find out the number of lines
s := strings.Split(sb.String(), "\n")
l := len(s)
if l > height-6 {
// truncate the output
var sb2 strings.Builder
maxLines := height - 6
if maxLines > l {
maxLines = l
}
for i := 0; i < maxLines; i++ {
sb2.WriteString(s[i])
sb2.WriteString("\n")
}
remainingLines := l - maxLines
if remainingLines > 0 {
sb2.WriteString(fmt.Sprintf("... output truncated, %v more line(s)", remainingLines))
}
return sb2.String()
}
}
}
}
return sb.String()
}

Expand Down Expand Up @@ -2517,7 +2547,7 @@ func expandValues(s string) string {

}

// prseSorting parses a sorting string. The sorting string should have a
// parseSorting parses a sorting string. The sorting string should have a
// column number, where the column will be sorted ascending numerically, if possible,
// or a column number and 'd' where it will be sorted descendingFlag.
// the column string could also be a name of a column.
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
watchClearEnabled bool
watchDelay int32
readPassStdin bool
limitOutput bool

bFormat bool
kbFormat bool
Expand Down Expand Up @@ -245,6 +246,7 @@ func SetRootCommandFlags(command *cobra.Command) {
command.PersistentFlags().BoolVarP(&watchEnabled, "watch", "w", false, "watch output (only available for get commands)")
command.PersistentFlags().BoolVarP(&watchClearEnabled, "watch-clear", "W", false, "watch output with clear")
command.PersistentFlags().BoolVarP(&readPassStdin, "stdin", "i", false, "read password from stdin")
command.PersistentFlags().BoolVarP(&limitOutput, "limit", "", false, "limit table output to screen size")
command.PersistentFlags().Int32VarP(&watchDelay, "delay", "d", 5, "delay for watching in seconds")
command.PersistentFlags().StringVarP(&Username, usernameOption, usernameShort, "", userNameDescription)
command.PersistentFlags().StringVarP(&clusterConnection, connectionNameOption, clusterNameOptionShort, "", clusterConnectionDescription)
Expand Down
Loading