[python] "input" now displays the provided prompt

This commit is contained in:
Romain Goyet
2018-01-30 14:12:54 +01:00
committed by EmilieNumworks
parent 314fde955a
commit fd7516f8ac
8 changed files with 40 additions and 26 deletions

View File

@@ -9,20 +9,23 @@ mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) {
// 1 - Retrieve the prompt if any
const char * prompt = NULL;
if (n_args == 1) {
prompt = mp_obj_str_get_str(args[0]);
}
// 2 - Perform the HAL input command
const char * result = mp_hal_input(prompt);
// 3 - Log the prompt, result and flush a new line
mp_obj_t resultStr = mp_obj_new_str(result, strlen(result), false);
if (n_args == 1) {
mp_obj_print(args[0], PRINT_STR);
}
/*vstr_t line;
vstr_init(&line, 16);
int ret = mp_hal_readline(&line, "");
if (ret == CHAR_CTRL_C) {
nlr_raise(mp_obj_new_exception(&mp_type_KeyboardInterrupt));
}
if (line.len == 0 && ret == CHAR_CTRL_D) {
nlr_raise(mp_obj_new_exception(&mp_type_EOFError));
}
*/
const char * input = mp_hal_input();
return mp_obj_new_str(input, strlen(input), false);
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);