Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor in the same line as echo output #428

Closed
divyareddy12 opened this issue Aug 28, 2018 · 8 comments
Closed

Cursor in the same line as echo output #428

divyareddy12 opened this issue Aug 28, 2018 · 8 comments

Comments

@divyareddy12
Copy link

Is it possible for the cursor to be positioned in the same line as the data printed from echo
(Prompt is set to empty)

Expected behavior

line 1
line 2$ <cursor position here>

Actual behavior

line 1
line 2$ 
<cursor position here>
@jcubic
Copy link
Owner

jcubic commented Aug 28, 2018

No it's not possible, it will require lot of work with current architecture, but maybe I go about and try to make it work, since I had few questions about this.

@divyareddy12
Copy link
Author

As a workaround I am setting the last line of echo data as the prompt. But there are special characters in prompt. So would it be possible to apply the formatting that is done for echo to prompt as well?

@jcubic
Copy link
Owner

jcubic commented Aug 31, 2018

I completely missed formatters in prompt, will add.

jcubic added a commit that referenced this issue Sep 1, 2018
@jcubic
Copy link
Owner

jcubic commented Sep 1, 2018

You can now have the same text in prompt as in command. The code is in devel branch.

@jcubic
Copy link
Owner

jcubic commented Sep 1, 2018

I kind of broken, devel branch right now but you can use version from commit.

jcubic added a commit that referenced this issue Sep 1, 2018
@jcubic
Copy link
Owner

jcubic commented Sep 1, 2018

works again, need testing.

@jcubic
Copy link
Owner

jcubic commented Sep 9, 2018

Here is example of using prompt to not echo newline, it works with string prompt:

     var last;
     var term = $('body').terminal($.noop, {
         echoCommand: false,
         keymap: {
             'ENTER': function(e, original) {
                 var str;
                 if (!last) {
                     str = this.get_prompt() + this.get_command();
                 } else {
                     var str = last + prompt + this.get_command();
                     last = '';
                 }
                 this.echo(str);
                 original(e);
             }
         },
         prompt: '>>> '
     });
     var prompt = term.get_prompt();
     (function(echo) {
         term.echo = function(arg, options) {
             var settings = $.extend({
                 newline: true
             }, options);
             if (!prompt) {
                 prompt = this.get_prompt();
             }
             if (settings.newline === false) {
                 last += arg;
                 arg += this.get_prompt();
                 var arr = arg.split('\n');
                 var last_line;
                 if (arr.length === 1) {
                     last_line = arg;
                 } else {
                     echo(arr.slice(0, -1).join('\n'), options);
                     last_line = arr[arr.length - 1];
                 }
                 this.set_prompt(last_line);
             } else {
                 if (prompt) {
                     this.set_prompt(prompt);
                 }
                 if (last) {
                     echo(last + arg, options);
                 } else {
                     echo(arg, options);
                 }
                 last = '';
                 prompt = '';
             }
         };
     })(term.echo);

I don't think I will add this hack to the library. It will be more complex if prompt is a function. The prompt function will need to be executed multiple times and I just fixed issue with counter in prompt function.

@jcubic
Copy link
Owner

jcubic commented Sep 13, 2018

Added this to list of examples on the site.

@jcubic jcubic closed this as completed Oct 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants