Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

piping ct in GNU screen is not working #80

Closed
amigthea opened this issue Feb 5, 2020 · 13 comments
Closed

piping ct in GNU screen is not working #80

amigthea opened this issue Feb 5, 2020 · 13 comments
Labels
bug Something isn't working

Comments

@amigthea
Copy link

amigthea commented Feb 5, 2020

or i can't make it working:

screen /dev/ttyUSB0 | ct

will result in the classic shell color scheme (white on black in my case)

@hSaria
Copy link
Owner

hSaria commented Feb 5, 2020

It seems screen is a bit more special with how it writes its output. I'm taking a look at this.

@hSaria hSaria added the bug Something isn't working label Feb 5, 2020
@hSaria
Copy link
Owner

hSaria commented Feb 5, 2020

I've spent quite a while looking at this but it seems it's something that can't be resolved with the current implementation. Even if you let CT spawn the program (i.e. ct screen /dev/ttyUSB0), it still wouldn't work because screen specifically uses stdin to then derive stdout and stderr, and CT keeps stdin as that one for the controlling terminal.

I don't know why, but openpty has some weird behavior where writing to the master would be read back at master, instead of slave. As far as I know, writing to the master should be read at slave. Writing to the slave is correctly read on the master, but the other way around isn't working. This is an example of what I'm referring to:

>>> import os
>>> master, slave = os.openpty()
>>> os.write(slave, b'message to master')
17
>>> os.read(master, 17)
b'message to master'
>>> os.write(master, b'message to slave')
16
>>> os.read(slave, 16)
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyboardInterrupt
>>> os.read(master, 16)
b'message to slave'
>>> 

Had this not been the case, I would be able to change stdin when CT spawns the program, thus allowing screen to work. This seems to be a special case with Python as writing similar code in C works as expected (w:master -> r:slave and w:slave -> r:master)

I'll leave this issue open for a bit in the hope that I, or anyone really, can find an alternate solution.

@hSaria hSaria added the help wanted Extra attention is needed label Feb 5, 2020
@amigthea
Copy link
Author

amigthea commented Feb 6, 2020

thank you for the detailed explanation and the effort mate. I tried with cu command too but without success, are there some other way you know to display the output of a serial port through chromaterm?

@hSaria
Copy link
Owner

hSaria commented Feb 6, 2020

You could use ct script /dev/null screen /dev/ttyUSB0. To avoid this lengthy command, you could use set up an alias in your .bash_profile like

alias console="ct script /dev/null screen /dev/ttyUSB0"

script, which should be available in your OS, acts as an intermediate that creates a pseudo-terminal which screen then forwards its stdout (derived from the pseudo-termainal's stdin of script) to the stdin of the pseudo-terminal that CT created internally for script.

@amigthea
Copy link
Author

amigthea commented Feb 6, 2020

thank you, I'll try that out!

@hSaria hSaria closed this as completed in 5f1b10d Feb 7, 2020
@hSaria hSaria removed the help wanted Extra attention is needed label Feb 7, 2020
@hSaria
Copy link
Owner

hSaria commented Feb 7, 2020

After lots of fiddling, I was finally able to correctly fix this issue. This will be published in v0.5.8 (soon).

@amigthea
Copy link
Author

I updated to 0.5.8 but ct is still not piped in screen

@hSaria
Copy link
Owner

hSaria commented Feb 11, 2020

Piping doesn't work for instances like these. Help (i.e. ct -h) has the following note regarding piping.

ChromaTerm reads from standard input; just pipe data to it. As this exposes
the existance of a pipe to the piping process, ChromaTerm can run your program
in order to hide the pipe. This is normally only needed for programs that want
to be on a controlling terminal, like `less`.

For your case, you need to do ct screen /dev/ttyUSB0

@amigthea
Copy link
Author

my bad, thanks for the head up and for the amazing work!

@amigthea
Copy link
Author

sorry to bother you again but now i'm trying to load this config:

https://gist.github.com/vista-/88c90110dd320be4c78da4f55783b41a

source: https://notx.ml/Own_projects/Highlighting_Cisco_keywords_or_output_on_Linux/

i've seen you've been on it a year ago but i think you switched to a yaml format since then right? there's a way i can convert that to be read from chromaterm--? or maybe it's me that can't grasp again how to make it works?

@hSaria
Copy link
Owner

hSaria commented Feb 11, 2020

sorry to bother you again

Not at all. I'm happy to help any way I can.

i've seen you've been on it a year ago but i think you switched to a yaml format since then

That is correct. Unfortunately, the RegEx engine changed meaning I couldn't auto-convert them to the new format consistently. Fortunately, however, @Enf0 recently converted most of those rules in #79 and they are now available in contrib/rules, so you can copy the ones you want into your ~/.chromaterm.yml.

If there are more rules that you'd like included in contrib/rules, feel free to let me know or submit a PR if you're feeling like it – it's alright if you don't :)

@amigthea
Copy link
Author

what an astounding help you gave me mate, thank you for all the guidelines
ps: as soon as i can i will gladly contribute!

@hSaria
Copy link
Owner

hSaria commented Feb 11, 2020

You're absolutely welcome.

ps: as soon as i can i will gladly contribute!

Don't feel that you have to; you feedback alone is plenty of contribution.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants