gum icon indicating copy to clipboard operation
gum copied to clipboard

434 Add Command to Tail -n Lines

Open CodeZea1ot opened this issue 10 months ago • 4 comments

Closes #434

Changes

  • Adds a new gum tail subcommand
  • Allows user to stream stdin for -n number of lines
  • Keeps logs from piped running processes from cluttering up the terminal

Example

{ 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

CodeZea1ot avatar Apr 22 '24 21:04 CodeZea1ot

Hey @CodeZea1ot, thanks so much for the contribution!

What benefit do you get with gum tail vs simply using tail?

maaslalani avatar Apr 22 '24 21:04 maaslalani

Hey there @maaslalani

The idea behind a gum tail is to be able to stream output from a long running process that produces a lot of output with a configurable amount of visible max lines.

For example, say you have a script that runs an install or download process that you don't want to hide with gum spin, you could instead show the last -n lines of the output to the user, with it refreshing until the process ends.

In other words, you would get up to -n lines of output at all times and those lines that are displayed would always show the latest lines from the piped command coming into stdin.

https://github.com/charmbracelet/gum/assets/54991101/f6030259-a3df-42ec-a750-2232bff30589

CodeZea1ot avatar Apr 22 '24 22:04 CodeZea1ot

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.

newcron avatar Apr 26 '24 14:04 newcron

I built a BASH CLI called spyglass for this use case. You can check it out over at https://github.com/CodeZea1ot/spyglass

This is the functionality I'd like to bring to a gum tail command.

main_demo

CodeZea1ot avatar Apr 26 '24 17:04 CodeZea1ot