-
Notifications
You must be signed in to change notification settings - Fork 438
434 Add Command to Tail -n Lines #544
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
base: main
Are you sure you want to change the base?
434 Add Command to Tail -n Lines #544
Conversation
|
Hey @CodeZea1ot, thanks so much for the contribution! What benefit do you get with |
|
Hey there @maaslalani The idea behind a For example, say you have a script that runs an install or download process that you don't want to hide with In other words, you would get up to Recording.2024-04-22.181848.mp4 |
|
I have to say, that's one of the features I'm waiting for so that I can start to use it. My usecase is a local dev environment in which several automated steps are performed to simplify the dev process. in my case, I would love exactly that for my build script, which should: build the code, create a test environment (databases with fixtures,...), then start the application and then run the end to end tests. Each of these steps produces output, which I don't want the whole screen to pollute. at the same time, it would be very useful for the developers to get a glimpse on what's going on (e.g. if there is an error in the build, or the application crashes at startup). Filling the whole screen with that just feels too verbose, yet not showing at all leaves the user without any sense of real progress. |
|
I built a BASH CLI called This is the functionality I'd like to bring to a |
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.
made some suggestions
also would be good to run goimports/gofmt
gum.go
Outdated
| // Tail | ||
| // Provides a means of streaming -n of lines from stdin |
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.
| // Tail | |
| // Provides a means of streaming -n of lines from stdin | |
| // Tail provides a means of streaming a number of lines from stdin. |
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.
Suggested change applied in 0087173
gum.go
Outdated
|
|
||
| // Tail | ||
| // Provides a means of streaming -n of lines from stdin | ||
| // Useful for showing a subset of output from a process without clogging up the terminal |
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.
| // Useful for showing a subset of output from a process without clogging up the terminal | |
| // It is useful for showing a subset of output from a process without clogging up the terminal. |
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.
Suggested change applied in 0087173
| // Provides a means of streaming -n of lines from stdin | ||
| // Useful for showing a subset of output from a process without clogging up the terminal | ||
| // | ||
| // $ { sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y; } | gum tail -n 3 |
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.
| // $ { sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y; } | gum tail -n 3 | |
| // Let's watch apt update: | |
| // | |
| // $ { sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y; } | gum tail -n 3 |
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.
Suggested change applied in 0087173
tail/command.go
Outdated
| "os" | ||
| ) | ||
|
|
||
| // Run executes the tail command |
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.
| // Run executes the tail command | |
| // Run executes the tail command. |
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.
Suggested change applied in 0087173
tail/command.go
Outdated
| } | ||
|
|
||
| func clearScreen() { | ||
| fmt.Print("\033[H\033[2J") |
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.
| fmt.Print("\033[H\033[2J") | |
| fmt.Print(ansi.EraseDisplay(2)) |
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.
tail/command.go
Outdated
| start := len(lines) - n | ||
| if start < 0 { | ||
| start = 0 | ||
| } | ||
| for i := start; i < len(lines); i++ { | ||
| fmt.Println(lines[i]) | ||
| } |
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.
| start := len(lines) - n | |
| if start < 0 { | |
| start = 0 | |
| } | |
| for i := start; i < len(lines); i++ { | |
| fmt.Println(lines[i]) | |
| } | |
| fmt.Println(strings.Join(lines, "\n")) |
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.
Refactored in 45e1406
See following comment #544 (comment)
tail/command.go
Outdated
| // Continuously read lines from stdin and update the last n lines | ||
| for line := range lines { | ||
| lastLines = appendLine(lastLines, line, o.NumLines) | ||
| clearScreen() |
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 put clearScreen() behind an option?
I'd prefer the behaviour shown in #434.1967362421, i.e. gum tail would leave the screen content "above" alone, and only update its "own" N lines.
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.
I think this refactor solves the clear screen problem and improves the functionality of the tail command.
Screencast.from.09-11-2025.10.36.47.AM.webm
|
Is there anything beyond above comments by @caarlos0 preventing this from being merged? |

Closes #434
Changes
gum tailsubcommandExample
{ sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y; } | gum tail -n 3 // Stream the last 3 lines of info generated by this process until complete