asciinema should do the job. It has GIF generation support via its 'agg' tool: https://docs.asciinema.org/manual/agg/