diff --git a/src/renderer/editor/HighlightedCode.css b/src/renderer/editor/HighlightedCode.css new file mode 100644 index 0000000..f6b4242 --- /dev/null +++ b/src/renderer/editor/HighlightedCode.css @@ -0,0 +1,12 @@ +.HighlightedCode-editor .ace_scroller { + width: 100%; +} +.HighlightedCode-editor .ace_cursor { + opacity: 0; +} +.HighlightedCode-editor .ace_marker-layer { + display: none; +} +.HighlightedCode-editor .ace_print-margin { + display: none; +} diff --git a/src/renderer/editor/HighlightedCode.tsx b/src/renderer/editor/HighlightedCode.tsx new file mode 100644 index 0000000..2913bd3 --- /dev/null +++ b/src/renderer/editor/HighlightedCode.tsx @@ -0,0 +1,36 @@ +import AceEditor from 'react-ace'; +import 'ace-builds/src-noconflict/mode-python'; +import './HighlightedCode.css'; + +export default function HighlightedCode({ + children, + indent = 0, +}: { + children: string; + indent: number?; +}) { + const lines = children.split('\n'); + if (lines.length && !lines[0].trim()) { + lines.shift(); + } + if (lines.length && !lines[lines.length - 1].trim()) { + lines.pop(); + } + // Remove common indent + const minIndent = Math.min(...lines + .filter(line => line.trim().length) + .map(line => line.match(/^ */)[0].length) + ); + const formatted = lines.map(line => ' '.repeat(indent) + line.slice(minIndent)).join('\n'); + return ( + + ); +} diff --git a/src/renderer/editor/addEditorTooltips.tsx b/src/renderer/editor/addEditorTooltips.tsx index bdff74a..0a76f88 100644 --- a/src/renderer/editor/addEditorTooltips.tsx +++ b/src/renderer/editor/addEditorTooltips.tsx @@ -1,6 +1,7 @@ import { Ace, require as acequire } from 'ace-builds'; import { ReactNode } from 'react'; import { createRoot } from 'react-dom/client'; +import HighlightedCode from './HighlightedCode'; import readApiCall from './readApiCall'; const { HoverTooltip } = acequire('ace/tooltip'); @@ -8,7 +9,41 @@ const { HoverTooltip } = acequire('ace/tooltip'); const apiHelpComponents: { [matchText: string]: () => ReactNode; } = { - 'Robot.get_value': () =>
Documentation for Robot.get_value method.
, + 'Robot.get_value': () =>
+ The get_value function returns the current value of a + specified param on a device with the specified device_id. +
+ Parameters: + + The function is useful for checking the current state of devices. For example, getting the + current state of a limit switch using its device_id and + the param "switch0" will return True when pressed down and False if not. + {` + # First segment of code ran in the teleop process + limit_switch = "//INSERT SWITCH ID HERE//" + + def teleop_setup(): + print("Tele-operated mode has started!") + + def teleop_main(): + # Example code for getting the value of a limit switch + # First parameter is the limit switch's id + # Second parameter tells which switch to get the value from + # In this case the method will return True or False depending on if the switch is pressed down or not + + Robot.get_value(limit_switch, switch0) + `} +
, Robot: () =>
Documentation for Robot object.
, };