[apps/code] Handle carriage returns in the input text

This commit is contained in:
Léa Saviot
2019-01-04 16:49:53 +01:00
parent 2d4d92090c
commit 177373c5af
2 changed files with 31 additions and 16 deletions

View File

@@ -15,17 +15,11 @@ mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) {
prompt = mp_obj_str_get_str(args[0]);
}
// 2 - Perform the HAL input command
// 2 - Perform the HAL input command. This logs the prompt and the result
const char * result = mp_hal_input(prompt);
// 3 - Log the prompt, result and flush a new line
// 3 - Return the input
mp_obj_t resultStr = mp_obj_new_str(result, strlen(result));
if (n_args == 1) {
mp_obj_print(args[0], PRINT_STR);
}
mp_obj_print(resultStr, PRINT_STR);
mp_print_str(MP_PYTHON_PRINTER, "\n");
return resultStr;
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input);