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

CircuitPython 8.X title-set ansi code sometimes ends up in stdin #6892

Closed
bill88t opened this issue Sep 11, 2022 · 14 comments · Fixed by #6952 or #7041
Closed

CircuitPython 8.X title-set ansi code sometimes ends up in stdin #6892

bill88t opened this issue Sep 11, 2022 · 14 comments · Fixed by #6952 or #7041
Assignees
Labels
Milestone

Comments

@bill88t
Copy link

bill88t commented Sep 11, 2022

CircuitPython version

Adafruit CircuitPython 8.0.0-beta.0 on 2022-08-18; Raspberry Pi Pico with rp2040
Affects all boards, the chance of it occuring it higher on faster boards.

Code/REPL

Ljinux

Behavior

image

Description

Sometimes, when polling stdin, the console receives parts of the title-set ansi escape code sequence, circuitpython 8.x uses.
This means that at some point during the boot proccess, circuitpython decided to send the title-set, but sent it incompletely..

Additional information

  1. Ansi escape codes should be sent using stdout, NOT stdin..
  2. Should you need help with the ansi code part I can help, however my C / C++ is mediocre at best.
  3. Please provide a way to disable the constant title spam.
  4. It's ok to spam more \007 just to be sure, they will never appear.
@bill88t bill88t added the bug label Sep 11, 2022
@bill88t
Copy link
Author

bill88t commented Sep 11, 2022

An easy mitigation for me was to simply create a bufferclear command and add it to the boot scripts, right after the serial connection occurs.

Also, it IS in stdin, it's treated as text in the buffer, and I can move my cursor to it.

@dhalbert
Copy link
Collaborator

You can now disable the status bar: #6847. For example, in boot.py:

import supervisor
supervisor.status_bar.console = False

This means that at some point during the boot proccess, circuitpython decided to send the title-set, but sent it incompletely..

I don't think it is being sent incompletely, but the sending starts before the USB connection is fully up. This should be fixed.

@dhalbert dhalbert added this to the 8.0.0 milestone Sep 13, 2022
@dhalbert dhalbert self-assigned this Sep 21, 2022
@dhalbert
Copy link
Collaborator

#6952 should fix this, on boards that have native USB. The status bar is not written out at all if, when the write starts, the serial connection is not available.

On boards that have an on-board serial-to-USB converter chip, the USB status pins on that chip may not be connected to anything, which is often the case. In that case, there is no way to know if the host is connected via USB, so there may still be situations where the first part of the status-bar write is missed, and the rest appears in-line. We might consider disabling the status bar by default on such boards, or delaying its enabling by several seconds.

(Re stdin: the status bar is written to the serial output like anything else, such as REPL output. Normally the escape code at the beginning would cause the terminal program to remove it from the what is displayed, but when the first part of the escape code is missed, it looks like "normal" output, and appears in the terminal window.)

@bill88t
Copy link
Author

bill88t commented Sep 28, 2022

Ι do not have any boards that require serial-to-usb so I cannot test that, however I will test the pr artifacts on my beetle-c3 and pico and provide any findings (if any) on the pr thread.

(Re Re stdin:
image

n = runtime.serial_bytes_available
if n > 0 or self.stdin is not None:
   i = None
   if self.stdin is not None: # fake stdin
          i = self.stdin # fake stdin
          self.stdin = None # fake stdin
   else:
          i = stdin.read(n)

You can read more about my fully non-blocking input implementation here
)

Leaving the issue open till merge.

@bill88t
Copy link
Author

bill88t commented Sep 28, 2022

Using artifact https://github.com/adafruit/circuitpython/actions/runs/3138352211 on raspberry_pi_pico
image
The bug is still there. It took 20 tries before I got it to show up.
It occured on a late connection.

In repl:
image
In repl, it doesn't go in stdin

@bill88t
Copy link
Author

bill88t commented Sep 28, 2022

@dhalbert

@dhalbert
Copy link
Collaborator

I will re-test on RPi Pico now that it's merged.

@dhalbert dhalbert reopened this Sep 28, 2022
@bill88t
Copy link
Author

bill88t commented Oct 5, 2022

Btw this bug is still alive and kicking in daily builds
image

@dhalbert dhalbert closed this as completed Oct 5, 2022
@dhalbert
Copy link
Collaborator

dhalbert commented Oct 5, 2022

@bill88t what are you using as a terminal program?

@dhalbert dhalbert reopened this Oct 5, 2022
@bill88t
Copy link
Author

bill88t commented Oct 5, 2022

Kde Konsole.

@bill88t
Copy link
Author

bill88t commented Oct 5, 2022

If you are wondering, yes it does support ansi escape.
I can vouch for it, as I developed all of jcurses with it.
Jcurses uses most ansi escape sequences and I would have noticed if something was broken.

Also might I suggest a potential workaround?
Wouldn't it be possible to test if a terminal was present with a cursor query?
Like I mean asking (with ansi escape) the cursor position..
If it responds, it's connected. If it doesn't, it's not.
Only when it answers to size queries should the title begin to be set.
The logic could be hollow. Send the query bytes, if stdin: it's here.

If the terminal is at a goodnough state to reply to that, surely it's ready for a title set

@dhalbert
Copy link
Collaborator

dhalbert commented Oct 5, 2022

A query could also appear as junk, since it's in-band just like the title sequence. Right now I am testing whether the USB connection is up. I don't send the title bar sequence at all if, at the beginning, the serial connection is not yet up.

I am not sending the title sequence to stdin; I am just sending it to the serial connection as output. At the lower code level I am sending at, there is no stdin or stdout: it is below that. It should not be appearing as input at all, so some odd echoing back to the REPL is going on.

@dhalbert
Copy link
Collaborator

dhalbert commented Oct 5, 2022

Kde Konsole.

That's the terminal program you're using, but what are you using to connect to /dev/ttyACM0, or whatever? E.g., are you using tio, or picocom, or something else? What is the exact command line, and what settings (including an initialization file, if any) are you using?

E.g., I am using gnome-terminal and tio.

@bill88t
Copy link
Author

bill88t commented Oct 5, 2022

I am using GNU/screen for that screen /dev/ttyACM0 115200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants