Skip to content
Snippets Groups Projects
Commit 8433cb6a authored by Michele Alberti's avatar Michele Alberti
Browse files

[Dome][Ivette] Add function to print text with tags, and use in Ivette components.

parent 778180da
No related branches found
No related tags found
No related merge requests found
...@@ -540,6 +540,37 @@ is blocked. ...@@ -540,6 +540,37 @@ is blocked.
.finally(endOperation); .finally(endOperation);
} }
// --------------------------------------------------------------------------
// --- Print Utilities
// --------------------------------------------------------------------------
/**
@summary Print text containing tags into buffer (bound to `this`).
@param {string|string[]} text - Text to print.
@param {object} options - CodeMirror
[text marker](https://codemirror.net/doc/manual.html#api_marker) options.
*/
printTextWithTags(text, options = {}) {
if (Array.isArray(text)) {
const tag = text.shift();
if (tag !== '') {
const markerOptions = { id: tag, ...options };
this.openTextMarker(markerOptions);
}
text.forEach((txt) => this.printTextWithTags(txt, options));
if (tag !== '') {
this.closeTextMarker();
}
} else if (typeof (text) === 'string') {
this.append(text);
} else { // This case should be useless when using TS.
console.error(
`Function 'printTextWithTags' accepts a parameter of `
+ `type string or string array: got '${typeof text}'.`
);
}
}
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -14,21 +14,6 @@ import { Component } from 'frama-c/LabViews'; ...@@ -14,21 +14,6 @@ import { Component } from 'frama-c/LabViews';
// --- Information Panel // --- Information Panel
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
const printInfo = (buffer: RichTextBuffer, text: string | string[]) => {
if (Array.isArray(text)) {
const tag = text.shift();
if (tag !== '') {
buffer.openTextMarker({ id: tag, css: 'color: blue' });
}
text.forEach((txt) => printInfo(buffer, txt));
if (tag !== '') {
buffer.closeTextMarker();
}
} else {
buffer.append(text);
}
};
const ASTinfo = () => { const ASTinfo = () => {
const buffer = React.useMemo(() => new RichTextBuffer(), []); const buffer = React.useMemo(() => new RichTextBuffer(), []);
...@@ -39,7 +24,7 @@ const ASTinfo = () => { ...@@ -39,7 +24,7 @@ const ASTinfo = () => {
React.useEffect(() => { React.useEffect(() => {
buffer.clear(); buffer.clear();
if (data) { if (data) {
printInfo(buffer, data); buffer.printTextWithTags(data, { css: 'color: blue' });
} }
}, [buffer, data]); }, [buffer, data]);
......
...@@ -33,21 +33,6 @@ const PP = new Dome.PP('AST View'); ...@@ -33,21 +33,6 @@ const PP = new Dome.PP('AST View');
// --- Rich Text Printer // --- Rich Text Printer
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
const printAST = (buffer: RichTextBuffer, text: string) => {
if (Array.isArray(text)) {
const tag = text.shift();
if (tag !== '') {
buffer.openTextMarker({ id: tag });
}
text.forEach((txt) => printAST(buffer, txt));
if (tag !== '') {
buffer.closeTextMarker();
}
} else if (typeof (text) === 'string') {
buffer.append(text);
}
};
async function loadAST( async function loadAST(
buffer: RichTextBuffer, theFunction?: string, theMarker?: string, buffer: RichTextBuffer, theFunction?: string, theMarker?: string,
) { ) {
...@@ -62,9 +47,10 @@ async function loadAST( ...@@ -62,9 +47,10 @@ async function loadAST(
}); });
buffer.operation(() => { buffer.operation(() => {
buffer.clear(); buffer.clear();
if (!data) if (!data) {
buffer.log('// No code for function ', theFunction); buffer.log('// No code for function ', theFunction);
printAST(buffer, data); }
buffer.printTextWithTags(data);
if (theMarker) if (theMarker)
buffer.scroll(theMarker, undefined); buffer.scroll(theMarker, undefined);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment