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

Remove extra line return on custom one-line formatting #496

Closed
Arteneko opened this issue Jul 9, 2020 · 13 comments
Closed

Remove extra line return on custom one-line formatting #496

Arteneko opened this issue Jul 9, 2020 · 13 comments

Comments

@Arteneko
Copy link

Arteneko commented Jul 9, 2020

Right now, by fetching output using a custom one-line formatting (e.g. http://wttr.in/Nice?format=%C+%t), it adds a new line character at end of output, which makes it pretty annoying to use in tools like Conky, as it'll always add an empty line, e.g. ${curl http://wttr.in/Nice?format=%C+%t}.

Wouldn't it be possible to avoid this newline, or make it opt-in/opt-out?

@chubin
Copy link
Owner

chubin commented Jul 9, 2020

I see several options here.

One of them is to add a symbol, that means that you don't want a new line,
something like:

curl http://wttr.in/Nice?format=%C+%t,

it is a trivial fix, and can be done in matter of minutes.

It would simulate Python 2 syntax for print.

There are several other options if this one is bad.
What do you think?

@Arteneko
Copy link
Author

Arteneko commented Jul 9, 2020

I don't really know how to feel with adding a character that would represent "not a newline", since It would add the need for escaping in case you want to use this given character (e.g. the , could be used).

Would adding \n as opt-in new line work?

@chubin
Copy link
Owner

chubin commented Jul 9, 2020

, would have magic meaning only at the end of the string, but I understand your concerns.
\n is another option, but it is not good, because it can have special meaning for some clients,
and it would cause new problems.

Other options that we have:

format="xxxx"&newline=yes   # python3-style
formatln="xxxx"             # golang-style

@Arteneko
Copy link
Author

Arteneko commented Jul 9, 2020

Makes sense.

I would be more favorable for the python-3-style added parameter, imho.

Since right now, newline's the default behaviour, maybe keep yes as default if none provided

@chubin
Copy link
Owner

chubin commented Jul 9, 2020

Or we can combine it with \n, i.e. one can try to use \n inline, and if it does not work for his client,
one can use add newline=yes

@Arteneko
Copy link
Author

Arteneko commented Jul 9, 2020

Hhm, having two options feel a bit clunky and ambigous, imho.

Better stay with one, I'd say

@chubin
Copy link
Owner

chubin commented Jul 9, 2020

Currently, just to test, I've enabled \n expansion in the format string.
Can you test it from your side? (not with curl of course, but with your client)

$ curl 'wttr.in/Nuremberg?format=a\nb'
a
b

@Arteneko
Copy link
Author

Arteneko commented Jul 9, 2020

» curl 'wttr.in/Nice?format=a\nb'      
a
b

Works as expected.

I did try using format=%C+%t\n, but it completely stripped the %t formatting flag.

curl 'wttr.in/Nice?format=%C+%t\n'
Partly cloudy 

@chubin
Copy link
Owner

chubin commented Jul 9, 2020

It seems to be a bug, I'll check it, but could you please test the a\nb query with conky or what you use on your side?

@Arteneko
Copy link
Author

Arteneko commented Jul 9, 2020

conky uses the curl command under the hood. However, I cannot test it before tomorrow, as I left work, where my conky setup is present.

@chubin
Copy link
Owner

chubin commented Jul 9, 2020

The problem is not with curl itself, but with the programs that call it, because it is possible, that these programs just interpret \n on their own. I will try to fix the bug that you've found, and tomorrow you can test it from conky

@chubin
Copy link
Owner

chubin commented Jul 9, 2020

I've fixed the bug + changed the default behavior.
It's without ending new line now, when the %-notation is used,
but with it, when preconfigured format (1,2,3 etc.) are used.
To specify newline in the output, one should use \n and single quotes when doing a query from the shell

@Arteneko
Copy link
Author

Arteneko commented Jul 9, 2020

thanks!

@chubin chubin closed this as completed Jul 9, 2020
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

2 participants