[SERVER-3771] custom prompt usability issues Created: 06/Sep/11 Updated: 11/Jul/16 Resolved: 16/Nov/11 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | 2.1.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Aaron Staple | Assignee: | Tad Marshall |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Description |
|
1) If there is an error evaluating a prompt function, prompt becomes undefined. Might want to set to a default prompt instead. > function () { return c; } Tue Sep 6 13:45:42 ReferenceError: c is not defined (shell):1 undefined Tue Sep 6 13:45:47 ReferenceError: c is not defined (shell):1 undefined Tue Sep 6 13:45:48 ReferenceError: c is not defined (shell):1 undefined 2) setting prompt to a regex has strange results > prompt = /a/ /a/ Tue Sep 6 15:22:44 SyntaxError: no input for /a/ :1 undefined 3) new lines in prompt mess up shell handling of current line and use of history. Other unusual characters (eg \b) and long lines seem to cause problems too. If the prompt line is wider than my terminal window, I never see anything other than the prompt and every time I type a character I get a new line with the prompt on it. Aaron-Staples-MacBook-Pro:mongo aaron$ ./mongo MongoDB shell version: 2.0.0-rc2-pre- connecting to: test > prompt = "you are special!\n> " you are special! > you are special! > db.c.count() 1 you are special! you are special!> you are special!> db.c.count() <<<----- pressing backspace repeatedly you are special!> db.c.count( you are special!> db.c.count you are special!> db.c.coun you are special!> db.c.cou you are special!> db.c.co you are special!> db.c.c > db.c. find() { "_id" : ObjectId("4e66a1acc98ce70998274933") }you are special! connecting to: test 4) Don't know if we want to allow them, but shell helpers aren't available in the prompt function: > prompt = function() { use foo; return db.c.count(); }Tue Sep 6 15:47:12 SyntaxError: missing ; before statement (shell):1 > prompt = function() { exit; }function () { |
| Comments |
| Comment by Tad Marshall [ 16/Nov/11 ] |
|
The problems described in this bug report are now fixed. |
| Comment by auto [ 15/Nov/11 ] |
|
Author: {u'login': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@tadmarshall.com'}Message: Remove the all-on-one-line command line editing in the shell and replace it |
| Comment by auto [ 01/Nov/11 ] |
|
Author: {u'login': u'erh', u'name': u'Eliot', u'email': u'eliot@10gen.com'}Message: Merge pull request #122 from tadmarshall/
|
| Comment by auto [ 01/Nov/11 ] |
|
Author: {u'login': u'erh', u'name': u'Eliot', u'email': u'eliot@10gen.com'}Message: Merge pull request #122 from tadmarshall/
|
| Comment by Tad Marshall [ 27/Oct/11 ] |
|
I closed pull request 96 and reissued the code changes as separate pull requests, but forgot to update the bug report. Don't let the prompt be displayed as "undefined": https://github.com/mongodb/mongo/pull/122 Sorry for the delayed update to the bug report. |
| Comment by Tad Marshall [ 06/Oct/11 ] |
|
Part 3 was added to pull request 96. The commits are https://github.com/tadmarshall/mongo/commit/95ce1bdede0cf49aad8dd432f995aa0a4964c9e1 and https://github.com/tadmarshall/mongo/commit/9d7b05cbc8fa5f280b5fdeb3082ee7101e25872b . |
| Comment by Tad Marshall [ 06/Oct/11 ] |
|
Pull request https://github.com/mongodb/mongo/pull/96 addresses parts 1 and 2 of this bug: the undefined value being displayed for the prompt. |
| Comment by Tad Marshall [ 30/Sep/11 ] |
|
Testing 2.1.0-pre- (my build) on Windows 7 and Ubuntu 11.04's standard Gnome Terminal program prior to working on the reported bugs. Item 1 behavior on Windows and Ubuntu is identical to the Mac behavior. From code inspection, I could also see that we are leaving a _prompt_ variable lying around after successfully executing a prompt function. This leftover _prompt_ will return as a surprise if prompt is later redefined to a failing function. MongoDB shell version: 2.1.0-pre- // set prompt to a function that will fail // set prompt to a function that returns a string // set prompt to a function that will fail Item 2 behaves the same Windows and Ubuntu as on the Mac. "typeof /a/" displays "function" so the reported error is different but otherwise the behavior is the same as item 1. Item 3 (regarding newline in the prompt and prompts that are wider than the terminal width) is a bit worse in Windows. With a \n in the prompt text, things are OK until a redraw happens. Redraws occur on backspace and up-arrow, but also when the shift key is pressed. When we redraw, we display the newline as a Windows/DOS OEM character, so the prompt gets longer by one character and the newline doesn't happen. When the prompt text length exceeds the terminal width, the redraw happens on the first keystroke and the prompt is truncated with the last position displaying a space. It is impossible to see anything that you type because it is drawn and then overwritten with a space. In Ubuntu it is perhaps even worse. The newline is interpreted literally as a linefeed, so the cursor is left hanging in space below the text and just to its right. You need to use \r\n to make the prompt display as a "normal" two-line prompt. Redraws are not triggered by the shift key (as on Windows) but when triggered with backspace (for example) the redraw is botched and even with \r\n the cursor is left hanging out in space. We may want to mention item 4 in the documentation (or not), but the code executing the prompt is just the eval() function and the behavior is no different. eval() doesn't support the shell's extensions and prompt=function(){} doesn't either. |