diff --git a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/FormatValueBase.js b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/FormatValueBase.js index 35bc4c2664..d819808695 100644 --- a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/FormatValueBase.js +++ b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/FormatValueBase.js @@ -37,7 +37,14 @@ export default { if (value === null || value === undefined) { return 'null' } - return String(value) + const str = String(value) + // Escape special whitespace so they display visibly in single-line widgets. + // Widgets that support multi-line display (e.g. TextboxWidget) set + // escapeSpecialCharacters: false in their data() to opt out. + if (this.escapeSpecialCharacters !== false) { + return str.replace(/\r\n/g, '\\r\\n').replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/\t/g, '\\t') + } + return str }, // sprintf-js doesn't support BigInt values so we handle common // integer format specifiers manually to preserve full precision diff --git a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/TextboxWidget.vue b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/TextboxWidget.vue index a9d02a3153..caa0ff8a56 100644 --- a/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/TextboxWidget.vue +++ b/openc3-cosmos-init/plugins/packages/openc3-vue-common/src/widgets/TextboxWidget.vue @@ -66,6 +66,8 @@ export default { return { width: 200, height: 200, + // Allow actual newlines to render as line breaks in v-textarea + escapeSpecialCharacters: false, } }, computed: {