Faf du Plessis put South Africa in a commanding position on day three of their Test against Sri Lanka.