diff --git a/bshell.runtime/format/value-writer.c b/bshell.runtime/format/value-writer.c index b626779..69b1444 100644 --- a/bshell.runtime/format/value-writer.c +++ b/bshell.runtime/format/value-writer.c @@ -28,12 +28,25 @@ static void write_iterable(struct bshell_value_writer *w, const fx_value *value) fx_iterator_unref(it); } +static bool string_has_trailing_newline(const char *s) +{ + long len = strlen(s); + if (len == 0) { + return false; + } + + return s[len - 1] == '\n'; +} + static void write_string(struct bshell_value_writer *w, const fx_value *value) { const char *str = NULL; fx_value_get_cstr(value, &str); fx_stream_write_cstr(w->w_dest, str, NULL); - fx_stream_write_char(w->w_dest, '\n'); + + if (!string_has_trailing_newline(str)) { + fx_stream_write_char(w->w_dest, '\n'); + } } static void write_value(struct bshell_value_writer *w, const fx_value *value)