mmmorris1975 / ssm-session-client

A golang implementation of the protocol used with AWS SSM sessions
MIT License
40 stars 21 forks source link

Fix terminal resizing bug #4

Closed toothbrush closed 2 years ago

toothbrush commented 2 years ago

Hello! I use the ssm-session-client code as a library to my own CLI tool.

I've noticed that compared to the AWS official SSM client, ssm-session-client doesn't deal well with terminal resizing (this is using Terminal.app on macOS). I went digging a bit, and it seems AWS's client doesn't rely on getting a SIGWINCH, but simply sends terminal size every 500ms: https://github.com/aws/session-manager-plugin/blob/65933d1adf368d1efde7380380a19a7a691340c1/src/sessionmanagerplugin/session/shellsession/shellsession.go#L98-L134

I've adopted their trick here (along with some other minor changes), and it solves my issue. I verified it by connecting to a remote EC2 shell and running:

tput lines
tput cols

These report updated values as expected when resizing the Terminal.app window. Also, running a TUI app such as vim and then resizing the window doesn't cause garbled output whereas without this patch it does.

mmmorris1975 commented 2 years ago

I like this! Thank you for making this project better