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

"edit" command polluted with ASCII color codes #13

Closed
jelder opened this issue Sep 14, 2012 · 12 comments
Closed

"edit" command polluted with ASCII color codes #13

jelder opened this issue Sep 14, 2012 · 12 comments
Assignees
Labels

Comments

@jelder
Copy link

jelder commented Sep 14, 2012

obj = db.mycollection.find().pretty()
edit obj

{
  ^[[33m"_mongo"^[[m: connection to 127.0.0.1,
  ^[[33m"_db"^[[m: ObjectId(^[[32;4m"blah.str"^[[m),
  ^[[33m"_collection"^[[m: ObjectId(^[[32;4m"blah.mycollection.str"^[[m),
  ^[[33m"_ns"^[[m: ^[[32;1m"blah.mycollection"^[[m,
  ^[[33m"_query"^[[m: {
@TylerBrock
Copy link
Owner

Good catch, thanks.

@TylerBrock
Copy link
Owner

Wonder if @tadmarshall would have any input on how to get that working. I would like to fix this as well because I use the edit command heavily.

@ghost ghost assigned TylerBrock Jan 12, 2014
@clwen
Copy link

clwen commented Apr 10, 2014

Hi, thanks for the great work. Any update on this issue? I really like the work but without edit it's not really practical for me, since I use edit a lot. Or any quick fix would also be good.

@TylerBrock
Copy link
Owner

It's harder than it looks.

Two ideas:

We can make a shim for the EDITOR command that cleans the color codes as they are passed to the editor by the code in src/mongo/shell/dbshell.cpp.

Or possibly make it so the invocation of tojson passes additional params that indicate it was invoked from edit:

// Convert "whatToEdit" to JavaScript (JSON) text
if ( !shellMainScope->exec( "__jsout__ = tojson(" + whatToEdit + ")", "tojs", false, false, false ) )
    return; // Error already printed

@stennie
Copy link
Collaborator

stennie commented Oct 16, 2014

@TylerBrock I have a hacky fix which seems to work (and doesn't require modifying the mongo shell): stennie@910abec.

With some experimentation it seems like tosjon.caller is set to null when invoked from C++ exec(), but always set to a JS function when invoked from the shell. Based on this context, I turned off the color codes and can now use edit while still having colors in the shell. I'm not sure what else to watch out for, but in my limited testing this seems to work.

NB: the changes in my commit are continuing from #107 (not current master).

@TylerBrock
Copy link
Owner

That could work. I like it. I'm going to merge #107 right now let me think about this one a bit more and see if there is anything else we could do. Will let you know this week.

@jamestyj
Copy link

+1. stennie/mongo-hacker@910abec works nicely for me too.

@TylerBrock
Copy link
Owner

@stennie lets put up a PR for those changes whenever you get a chance. I'd like to have that work for everyone even if it is hacky.

@candland
Copy link
Contributor

+1 would love to be able to use edit

@TylerBrock
Copy link
Owner

Sorry about this. I'd like to take a look at this but don't have the time at the moment.

I would, of course, be willing to accept a pull request if you wanted to take a stab at it.

@stennie
Copy link
Collaborator

stennie commented Nov 10, 2015

Ooh! Forgot about this as I've been happily using on my local. I'll rebase and make a PR :)

@TylerBrock
Copy link
Owner

You've got a patch @stennie?! Hooray!

kevinadi added a commit to kevinadi/mongo-hacker that referenced this issue Feb 18, 2016
kevinadi added a commit to kevinadi/mongo-hacker that referenced this issue May 2, 2016
TylerBrock added a commit that referenced this issue Jul 5, 2016
Reverted Fix #13 which interferes with ReplSetTest() command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants