8go / matrix-commander-rs

simple but convenient CLI-based Matrix client app for sending and receiving (in Rust)
GNU General Public License v3.0
85 stars 3 forks source link

Extra newline at the end #113

Closed schorschfunke closed 2 weeks ago

schorschfunke commented 2 weeks ago

Hi, from version 0.4 or 0.4.1 there is a extra newline at the end of my messages send with matrix-conmander. This happens with messages send from my Python scripts. With messages send from Rust it doesn't

8go commented 2 weeks ago

Explain better please. You are piping something into matrix-commander-rs and depending where it comes from it has or does not have a newline? I do not understand. Are you referring to Python matrix-commander ?

schorschfunke commented 2 weeks ago

No im not piping. Im using matrix-commander-rs. Im using one Python script and start matrix-commander-rs from there with the message as argument with subprocess.run. Now i get an extra newline at the end oft the message. I have written a Rust program from where i start matrix-commander-rs as command . Form here i get no extra newline at the end.

8go commented 2 weeks ago

Ok, I understand now.

In your Py and Rust programs you use arguments -m followed by some local value (text). Correct?

Using --code --notice --emote or --markdown or something?

- and _ are treated differently. Using any of these special chars?

Run both your programs with -d to see all debug info. Then compare the 2 sets of debug info, where do they start to differ from each other?

I can see that if something is piped in then the program removes a trailing newline. This is on purpose. And that code is new, v04 or v0.4.1.

schorschfunke commented 2 weeks ago

https://photos.app.goo.gl/QZQisx9BMbuXFCQp6

Some screenshots. Tomorrow i will try with debug enabled

8go commented 2 weeks ago

I see, it is adding a newline to EVERY SINGLE LINE not just one at the end. Correct?

That message with some statistics is 1 single message, right. So, every line has its newline duplicated.

8go commented 2 weeks ago

Are you using --code or backticks like ```text``` or like `text` ?

What does the actual String look like that you are passing in?

8go commented 2 weeks ago

Are you using something like HTML because the first line seems to be in bold?

8go commented 2 weeks ago

Ah, I see that different clients (web browser, phone app) display text and messages differently. They insert space between different messages. Try looking at the messages on different clients if you can, e.g. in a web browser.

8go commented 2 weeks ago

What is your client? Does not look like Element?

8go commented 2 weeks ago

Start testing with something simple: like echo -e "123\n456" | cargo run -- -m - -d or echo -e "123\n456" | matrix-commander-rs -m - -d

For this example you should get a debug message like this:

2024-09-04... DEBUG matrix_commander_rs::mclient: In message(): roomnames are ["!...:..."], msgs are ["123\n456"]

How does this line differ between Py and Rust invocation? Is the same text showing up in msgs are [...]?

schorschfunke commented 2 weeks ago

No the Client is fluffychat. I will test it later today.

schorschfunke commented 2 weeks ago

I modify my Rust program and the debug output is the same. [0m message option is ["Tageswerte für 04 .09.2024:
\n Erzeugt (gesamt) : 3.10 kWh\n ` Erzeugt (vorne) : 1.97 kWh\n Erzeugt (hinten) : 1.13 kWh```\n


h```\n                ```Last             :
 3.41 kWh```\n                ```Netz
       : 0.58 kWh```\n                ```Ak
ku (ø)         : 48.53 %```\n
  ```Akku (max)       : 79 %```<br>\n
          ```Selbstversorgung : 2.83 kWh```
<br>\n                ```Selbstversorgung :
 82.99 %```"].
With MC 0.3.1 and 0.6
schorschfunke commented 2 weeks ago

Maybe its an matrix-sdk problem

schorschfunke commented 2 weeks ago

Its not an problem for me. I can change my programs and scripts easyly. I use it as status info for some vm

8go commented 2 weeks ago

I just ran this command

echo -e 'Tageswerte für 04.09.2024:\n Erzeugt (gesamt) : 3.10 kWh\n ```Erzeugt (vorne) : 1.97 kWh\n Erzeugt (hinten) : 1.13 kWh```\n```Einspeisung : 0.46 kWh```\n ```Last :3.41 kWh```\n ```Netz: 0.58 kWh```\n ```Akku (ø) : 48.53 %```\n```Akku (max) : 79 %```\n```Selbstversorgung : 2.83 kWh```\n ```Selbstversorgung :82.99 %```' | ./matrix-commander-rs -m -

Which gets me this debug line, same as yours I think.

DEBUG matrix_commander_rs::mclient: In message(): roomnames are ["!...:..."], msgs are ["Tageswerte für 04.09.2024:\n Erzeugt (gesamt) : 3.10 kWh\n ```Erzeugt (vorne) : 1.97 kWh\n Erzeugt (hinten) : 1.13 kWh```\n```Einspeisung : 0.46 kWh```\n ```Last :3.41 kWh```\n ```Netz: 0.58 kWh```\n ```Akku (ø) : 48.53 %```\n```Akku (max) : 79 %```\n```Selbstversorgung : 2.83 kWh```\n ```Selbstversorgung :82.99 %```"]

And on Element webpage it looks ugly because Element shows all the backticks. Same on Element cell phone app, it shows all the backticks. Style code in Element it has to be specified in another way.

My conclusion is, that the client (Element, Fluffychat, etc) interpret the text quite differently. FluffyChat converts the backticks into style code but it seems it also inserts new lines.

I think the "problem" is in the client.

Try this anyway, better:

'Tageswerte für 04.09.2024:\n Erzeugt (gesamt) : 3.10 kWh\n ```Erzeugt (vorne) : 1.97 kWh\nErzeugt (hinten) : 1.13 kWh\nEinspeisung : 0.46 kWh\nLast :3.41 kWh\nNetz: 0.58 kWh\nAkku (ø) : 48.53 %\nAkku (max) : 79 %\nSelbstversorgung : 2.83 kWh\nSelbstversorgung :82.99 %```'

Block as much as possible together into the backticked portion. You can test the looks with

echo -e 'Tageswerte für 04.09.2024:\n Erzeugt (gesamt) : 3.10 kWh\n ```Erzeugt (vorne) : 1.97 kWh\nErzeugt (hinten) : 1.13 kWh\nEinspeisung : 0.46 kWh\nLast :3.41 kWh\nNetz: 0.58 kWh\nAkku (ø) : 48.53 %\nAkku (max) : 79 %\nSelbstversorgung : 2.83 kWh\nSelbstversorgung :82.99 %```'  | ./matrix-commander-rs -m -
8go commented 2 weeks ago

On Element clients this looks the best:

echo -e 'Tageswerte für 04.09.2024:\nErzeugt (gesamt) : 3.10 kWh\nErzeugt (vorne) : 1.97 kWh\nErzeugt (hinten) : 1.13 kWh\nEinspeisung : 0.46 kWh\nLast :3.41 kWh\nNetz: 0.58 kWh\nAkku (ø) : 48.53 %\nAkku (max) : 79 %\nSelbstversorgung : 2.83 kWh\nSelbstversorgung :82.99 %'  | ./matrix-commander-rs -m - --code 

Note the use of --code

8go commented 2 weeks ago

If you are satisfied, close the issue. I think there is little I can do.

schorschfunke commented 2 weeks ago

Thank you for your help! I close the issue