question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possibly useful mod for the command-line plugin

See original GitHub issue

Hi folks,

I needed to hack in support for multiple different prompts in a single command-line block to the command-line plugin. It’s pretty straightforward (see code snippet below).

It adds an option to specify prompts on a per-line basis by setting the prompt attribute to something like this:

1|myPromptText;2-3|myOtherPrompt;4,8|myThirdPrompt

Of course, if you don’t use the augmented prompt syntax, then the prompt syntax works the standard way.

You may or may not want to add support for this to the command-line module, but I thought since I found it useful, others may, too.

Cheers, –Orion


        if (promptText !== '') {
            if (promptText.includes('|')) {
                // promptText format : 1|myPromptText;2-3|myOtherPrompt;4,8|myThirdPrompt
                // promptChunks: an array of
                var promptChunks = promptText.split(';');
                // prompts: an array of line number => prompt text
                var prompts = [];
                for (var i = 0; i < promptChunks.length; i++) {
                    // promptSections: 0 - line range; 1 - prompt value
                    var promptSections = promptChunks[i].split('|');
                    var promptValue = promptSections[1];
                    var promptRanges = promptSections[0].split(',');
                    for (var p = 0; p < promptRanges.length; p++) {
                        var promptRange = promptRanges[p].split('-');
                        var promptStart = parseInt(promptRange[0]);
                        var promptEnd = promptStart;
                        if (promptRange.length === 2) {
                            promptEnd = parseInt(promptRange[1]);
                        }
                        if (!isNaN(promptStart) && !isNaN(promptEnd)) {
                            for (var j = promptStart; j <= promptEnd; j++) {
                                var index = j-1;
                                prompts[index] = promptValue;
                            }
                        }
                    }
                }
                for (var i = 0; i < lines.length; i++) {
                    var thePrompt = typeof prompts[i] === "undefined" ? ": >" : prompts[i];
                    lines[i] = '<span data-prompt="' + thePrompt + '"></span>';
                }
                lines = lines.join('');
            } else {
                lines = lines.join('<span data-prompt="' + promptText + '"></span>');
            }
        } else {
            var user = pre.getAttribute('data-user') || 'user';
            var host = pre.getAttribute('data-host') || 'localhost';
            lines = lines.join('<span data-user="' + user + '" data-host="' + host + '"></span>');
        }

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
derek-shnoshcommented, Sep 5, 2020

@VoIP-Dude - the code snippet I posted above works if you’re comfortable modifying your local version yourself.

I have an example of what you’re talking about on my site.

Given, it is a but cumbersome to manage with the data-prompt attribute; here’s the source for the changing prompt table.

<pre class="command-line language-cisco-nxos" data-prompt="1|NX-OSv(config)#;2|NX-OSv#">
<code>end
copy run start</code></pre>
1reaction
VoIP-Dudecommented, Sep 5, 2020

This would be a great enhancement as some routers / switches have several different command modes with their corresponding prompts.

Cisco IOS Example: Router> | - User EXEC mode Router# | - Privileged EXEC mode Router(config)# | - Configuration mode (notice the # sign indicates this is accessible only at privileged EXEC mode) Router(config-if)# | - Interface level within configuration mode Router(config-router)# | - Routing engine level within configuration mode Router(config-line)# | - Line level (vty, tty, async) within configuration mode

Read more comments on GitHub >

github_iconTop Results From Across the Web

plugins pattern + sub command - python - Stack Overflow
I will do a command line application with plugin capability, each new plugin will be invoked by a sub command from a __main__.py...
Read more >
Your terminal can be much, MUCH more productive - Medium
A terminal that can pratically predict what you want to type, save a lot of repetitive commands, give you a really powerful autocomplete,...
Read more >
xEdit Overview | Tome of xEdit
2.6.1 Master/Plugin Selection View ... 2.8.1 Command Line Switches ... These functions are very important to mod authors in the Fallout3 environment, ...
Read more >
Installing plugins - MoodleDocs
4.1 Installing directly from the Moodle plugins directory; 4.2 Installing via ... It would probably be a good idea to consider them first....
Read more >
Command Line Options - Valve Developer Community
Useful Console Variables. Console Variable, Description. +_setgamedir <game>, Specifies which game/mod to run. +_ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found