Skip to content

Commit cc3a159

Browse files
committed
target: mbedos5: Add carriage return in jerry_port_console
Serial monitors (like screen on macOS / Linux) expect both CR and LF characters for new lines. Due to jerryscript only printing a line feed after calls to `print()` this makes log messages look wrong. This patch adds a CR when it encounters a LF character in jerry_port_console or jerry_port_log for the mbedos5 target. JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom jan.jongboom@arm.com
1 parent dc5ae46 commit cc3a159

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

targets/mbedos5/source/jerry_port_mbed.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jerry_port_console (const char *format, /**< format string */
3333
va_start (args, format);
3434
vfprintf (stdout, format, args);
3535
va_end (args);
36+
37+
if (strlen(format) == 1 && format[0] == 0x0a) { /* line feed (\n) */
38+
printf("\r"); /* add CR for proper display in serial monitors */
39+
}
3640
} /* jerry_port_console */
3741

3842
/**
@@ -49,6 +53,10 @@ jerry_port_log (jerry_log_level_t level, /**< log level */
4953
va_start (args, format);
5054
vfprintf (stderr, format, args);
5155
va_end (args);
56+
57+
if (strlen(format) == 1 && format[0] == 0x0a) { /* line feed (\n) */
58+
printf("\r"); /* add CR for proper display in serial monitors */
59+
}
5260
} /* jerry_port_log */
5361

5462
/**
@@ -62,7 +70,7 @@ jerry_port_fatal (jerry_fatal_code_t code) /**< fatal code enum item */
6270

6371
/**
6472
* Implementation of jerry_port_get_time_zone.
65-
*
73+
*
6674
* @return true - if success
6775
*/
6876
bool
@@ -76,7 +84,7 @@ jerry_port_get_time_zone (jerry_time_zone_t *tz_p) /**< timezone pointer */
7684
/**
7785
* Implementation of jerry_port_get_current_time.
7886
*
79-
* @return current timer's counter value in microseconds
87+
* @return current timer's counter value in microseconds
8088
*/
8189
double
8290
jerry_port_get_current_time ()

0 commit comments

Comments
 (0)