whereami icon indicating copy to clipboard operation
whereami copied to clipboard

Output Contains Control Characters

Open celestialorb opened this issue 5 years ago • 7 comments

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

celestialorb avatar Mar 26 '19 16:03 celestialorb

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.

rafaelrinaldi avatar Mar 26 '19 17:03 rafaelrinaldi

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. :smile:

celestialorb avatar Mar 27 '19 11:03 celestialorb

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. https://github.com/rafaelrinaldi/whereami/blob/b4fab2f4089c3c0a046e76aa522332bec43606e8/cli.js#L63-L68

celestialorb avatar Mar 27 '19 11:03 celestialorb

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 avatar May 21 '20 15:05 mwnDK1402

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.

tomashco avatar Nov 26 '20 08:11 tomashco

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

mwnDK1402 avatar Nov 26 '20 10:11 mwnDK1402

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!

tomashco avatar Nov 26 '20 14:11 tomashco