Go Tidbit: Detect When the Terminal Is Resized
September 20, 2023
#100DaysToOffload
#Go
#Tidbit
I have been meaning to do a few short-form blog posts lately. This blog post is going to be one of them.
In Go, on Linux, if you want to know when the terminal window is resized, you can listen for the SIGWINCH
signal using the signal.Notify
(or the signal.NotifyContext
) function.
The code will look something like this:
|
|
For a bit more complete example, you can try out this Go code:
|
|
It will print the size of the terminal every time it is resized.
That’s it.
As I said in the beginning, I have been meaning to do some short-form blog posts. And, this post is as short as it can get.
This post is 48th of my #100DaysToOffload challenge. Want to get involved? Find out more at 100daystooffload.com.
comments powered by Disqus
Similar Blog Posts
September 20, 2023
#100DaysToOffload
#Go
#Tidbit
September 17, 2023
#100DaysToOffload
#Go
#Tidbit