It's in the environment variable COLUMNS, read that out with whatever your language provides for that.