Fix terminal corruption on capture