I mention asciinema in my other comment[0], but there are a number of tools. The one to use depends on your system and the archwiki has a good list[1]. Assuming you're not using Wayland, ffmpeg is probably going to work[2]. Gimp and ImageMagick also provide tools to help.
[0] https://asciinema.org/ | https://news.ycombinator.com/item?id=41010530
[1] https://wiki.archlinux.org/title/Screen_capture
[2] https://trac.ffmpeg.org/wiki/Capture/Desktop