Fix serial console terminal issue and extract logic to be helper function

1. Fix:Render not work normally when using terminal through serial port …
2. Extract same logic in Prompt.render to utils.