-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Truncate long messages #216
Conversation
61543eb
to
a1020a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments are minor, we could move ahead as is. It's up to you.
internal/txlib/utils.go
Outdated
@@ -210,3 +210,12 @@ func isValidResolutionPolicy(policy string) (IsValid bool) { | |||
return false | |||
|
|||
} | |||
|
|||
func truncateMessage(message string) string { | |||
const maxLength = 75 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we try to detect the terminal's length here? In Python this can be done with the termios
package. There must be a way to do this in Go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is this package https://pkg.go.dev/golang.org/x/crypto/ssh/terminal and it worked as expected locally, but I was getting some build errors with some other packages, so I'll check that later to be sure🙏
internal/txlib/utils.go
Outdated
const maxLength = 75 | ||
|
||
if len(message) > maxLength { | ||
return message[:maxLength] + ".." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: You could do
return message[:maxLength] + ".." | |
return message[:maxLength - 2] + ".." |
here. The reasoning is this: Assume max length is 5. Then:
abc -> abc
abcd -> abcd
abcde -> abcde
abcdef -> abc..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There could be extra complications:
Colors in terminal work with ANSI escape sequences. For example, to display something in cyan you need this: \x31[96m cyan text here \x31[0m
.
Or as an array with one-byte elements (because \xXX
is an escape sequence):
['\x31', '[', '9', '6', 'm', ' ', 'c', 'y', 'a', 'n', ' ', 't', 'e', 'x', 't', ' ', 'h', 'e', 'r', 'e', ' ', '\x31', '[', '0', 'm']
The last code, \x31[0m
, is a "reset" code. If we remove this reset code during truncation, all following text will be colored until the color is changed or another reset happens.
Generally in our messages, the coloring happens early so this is unlikely to happen. Based on this and based on the fact that it would be very hard to cover every ANSI code I suggest we ignore this.
2711872
to
6451f84
Compare
Truncate long messages
6451f84
to
de26dcc
Compare
We utilize uilive library to update the terminal output in real-time during task execution. Due to the nature of uilive, multi-line errors retuned by service calls aren't always displayed accurately within the tasks section, leading to confusion, particularly during multitasking scenarios.
We can truncate long messages in these cases and print the entire messages in --silent flag cases where the terminal output is not updated in real time.