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

Output Contains Control Characters #25

Open
celestialorb opened this issue Mar 26, 2019 · 7 comments
Open

Output Contains Control Characters #25

celestialorb opened this issue Mar 26, 2019 · 7 comments

Comments

@celestialorb
Copy link

celestialorb commented Mar 26, 2019

Output, regardless of format, contains unnecessary control characters.

Example:

whereami -f human | hexdump -Cv
00000000  1b 5b 3f 32 35 6c 5c 0a  1b 5b 31 30 30 30 44 1b  |.[?25l\..[1000D.|
00000010  5b 4b 1b 5b 31 41 1b 5b  31 30 30 30 44 1b 5b 4b  |[K.[1A.[1000D.[K|
00000020  52 65 79 6b 6a 61 76 69  6b 2c 20 43 61 70 69 74  |Reykjavik, Capit|
00000030  61 6c 20 52 65 67 69 6f  6e 2c 20 49 63 65 6c 61  |al Region, Icela|
00000040  6e 64 0a 1b 5b 3f 32 35  68                       |nd..[?25h|
00000049
@rafaelrinaldi
Copy link
Owner

rafaelrinaldi commented Mar 26, 2019

Thanks for reporting this. At glance it looks like a weird unicode issue. Perhaps with the loading state?

Feel free to send a PR if you're willing to. I will work on this whenever I have some time.

@celestialorb
Copy link
Author

celestialorb commented Mar 27, 2019

You're probably right, seems like unicode. I jumped the gun and assumed they were control characters. I can take a look at it when I have some time. 😄

@celestialorb
Copy link
Author

Just from a quick glance, could it be from the loading components? If so, perhaps removing that or adding the ability to disable it (via a flag) would be a good solution.

whereami/cli.js

Lines 63 to 68 in b4fab2f

const loading = Loading.start()
try {
const output = await whereami({ ...argv, ipOrHostname })
Loading.stop(loading)
exitWithSuccess(output)

@mwnDK1402
Copy link

I was trying to use jq with this:
whereami -f json | jq -r ., but this issue prevents that from working without specifically removing the extra characters.

mwnDK1402 added a commit to mwnDK1402/whereami that referenced this issue May 21, 2020
@tomashco
Copy link

Hi,
I'm using this library in a Nodejs project through childprocess exec() in order to retrieve latitude and longitude as json, here is the code:

const { promisify } = require('util');
const util = require('util');
const exec = util.promisify(require('child_process').exec);

async function getLocation() {
  const { stdout } = await exec('whereami -f json');
  return stdout
}

  const coord = await getLocation()
  const latitude = coord.latitude
  const longitude = coord.longitude

but when I receive coord has this format and I can't access json:
'�[?25l\ �[1000D�[K�[1A�[1000D�[K{"latitude":45.4707,"longitude":9.1889} �[?25h'
I think is the same issue here (ansi string?), but I couldnt find a solution. Do you have any advice?

I also tried to add noanim as "whereami -f json -n" but with no luck.

@mwnDK1402
Copy link

Hi,
I'm using this library in a Nodejs project through childprocess exec() in order to retrieve latitude and longitude as json, here is the code:

const { promisify } = require('util');
const util = require('util');
const exec = util.promisify(require('child_process').exec);

async function getLocation() {
  const { stdout } = await exec('whereami -f json');
  return stdout
}

  const coord = await getLocation()
  const latitude = coord.latitude
  const longitude = coord.longitude

but when I receive coord has this format and I can't access json:
'�[?25l\ �[1000D�[K�[1A�[1000D�[K{"latitude":45.4707,"longitude":9.1889} �[?25h'
I think is the same issue here (ansi string?), but I couldnt find a solution. Do you have any advice?

I also tried to add noanim as "whereami -f json -n" but with no luck.

I added -noanim on my own fork, so it's not part of this repository.

You can use this if you want: https://github.com/mwnDK1402/whereami

@tomashco
Copy link

Hi,
I'm using this library in a Nodejs project through childprocess exec() in order to retrieve latitude and longitude as json, here is the code:

const { promisify } = require('util');
const util = require('util');
const exec = util.promisify(require('child_process').exec);

async function getLocation() {
  const { stdout } = await exec('whereami -f json');
  return stdout
}

  const coord = await getLocation()
  const latitude = coord.latitude
  const longitude = coord.longitude

but when I receive coord has this format and I can't access json:
'�[?25l\ �[1000D�[K�[1A�[1000D�[K{"latitude":45.4707,"longitude":9.1889} �[?25h'
I think is the same issue here (ansi string?), but I couldnt find a solution. Do you have any advice?
I also tried to add noanim as "whereami -f json -n" but with no luck.

I added -noanim on my own fork, so it's not part of this repository.

You can use this if you want: https://github.com/mwnDK1402/whereami

That made the trick! I've been able to install your package through npm install -g mwnDK1402/whereami and parsing the response to json with JSON.parse().

I hope this fork will be integrated soon into repo.
thank you!

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

4 participants