The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
0

Using colours in script 'could not parse JSON (lexical error)'

asked 2014-08-22 20:08:39 +0000

riks24 gravatar image

updated 2014-08-23 09:49:09 +0000

Hey,

I've just finished writing a script to get the temperatures of my CPU cores. I've noticed that if I use colours in the script like '\e[38;5;198m' the bar crashes and I get the following error:

'Error: Could not parse JSON (lexical error: invalid character inside string.)

But if I remove my colour codes from the script it works fine.

The script works fine from the terminal and only crashes on i3.

I'm also using the degree C symbol as Unicode and it works OK.

From my web development background I'd guess that it isn't being escaped properly but then again this is the first shell script I've written so I could have done something dumb.

Any help would be great.

Code causing the issue:

declare -A format format[none]="\033[38;5;7m" format[good]="\033[38;5;76m" format[bad]="\033[38;5;220m" format[ugly]="\033[38;5;196m"

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-08-24 12:41:27 +0000

ANOKNUSA gravatar image

The error occurs because the bracket '[' symbol is a delimeter in JSON syntax. You need to specify colors using hex values.

edit flag offensive delete link more

Comments

Thanks for the reply. Is it possible for me to set the colours in the script without having to add extra formatting in the i3 .conf file? I've just tried converting the script to a binary but I still get the same error.

riks24 gravatar imageriks24 ( 2014-08-25 17:35:43 +0000 )edit

Not sure what you mean by adding "extra formatting in the i3 .conf file." You'd just pass the hex color values to i3bar in your script instead of the terminal color code sequence. Also not sure what you mean by "converting the script into a binary"---what shell language allows for that?

ANOKNUSA gravatar imageANOKNUSA ( 2014-08-28 15:26:22 +0000 )edit

Question Tools

Stats

Asked: 2014-08-22 20:08:39 +0000

Seen: 501 times

Last updated: Aug 24 '14