grass icon indicating copy to clipboard operation
grass copied to clipboard

[Feat] d.text: Support printing a multiline strings provided as parameter

Open jphuart opened this issue 4 years ago • 1 comments

I want to print a text on multiple lines. Here is what I'm trying to do, but the text remain printed in one line.

from grass_session import Session
from grass.script import run_command

with Session(gisdb="path to mygisdb", location="myLocation") as sess:

    cptxt = "- first line \n"
    cptxt += "- second line \n"

    run_command('d.text',
                text=cptxt
                )

But the result is printed on one line - first line - second line.

I found a workaround saving my string in a file an importing the file in d.text, and it works

cptxt = "- first line \n"
cptxt += "- second line \n"

myfile = 'input_text.txt'

with open(myfile, "w") as ftxt:
    ftxt.write(cptxt)

run_command('d.text',
            input=myfile
            )

Now the result is

- first line
- second line

But I would prefer to use directly a string. Thank you

jphuart avatar Jan 07 '21 09:01 jphuart

Looking into this more: This would be a good improvement. It is actually d.text which does not support it, so I'm changing the title to reflect that.

In Python, I think the workaround is using feed_command instead of run command. This may just fix it for the OP case, but the grass.jupyter.Map does not have that flexibility now and using the parameter is just simpler anyway. The only limitation there is that the command parameters have system dependent character length limit, so a more complex solution may need to be documented and/or supported.

wenzeslaus avatar Feb 15 '23 15:02 wenzeslaus