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

feature: Added raw terminal support in monitor command #2291

Merged
merged 5 commits into from
Sep 6, 2023

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Sep 1, 2023

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated if new parameters are added.

What kind of change does this PR introduce?

Adds the --raw flag to the monitor command to put the terminal in raw mode.
When the terminal is in raw mode:

  • Control chars are not processed
  • Terminal is not line-buffered anymore (each char is sent as soon as the key is pressed)
  • Sent chars are not echoed
  • CR are not automatically added after NL LF are not automatically added after CR

This may result in weird behavior but it may be the desired result, for example, see #2251

What is the current behavior?

What is the new behavior?

$ cat Term.ino 
void setup() {
	Serial.begin(9600);
}

void loop() {
	while (Serial.available() > 0) {
		char c = Serial.read(); 

		if (c < 0x10) Serial.print("0");
		Serial.print(c, HEX);
		Serial.print(" ");

		if (c=='\r') Serial.println();
	}
	delay(10);
}
$ arduino-cli monitor -p /dev/ttyACM0 --config baudrate=9600 --raw
Monitor port settings:
baudrate=9600
Connected to /dev/ttyACM0! Press CTRL-C to exit.
6A 77 69 65 71 77 68 75 64 69 73 61 73 64 71 77 65 0D <----- data is printed as soon as keys are pressed
0D                                                    <----- key presses are not echoed back
0D 
73 6A 64 68 6A 73 64 68 71 6A 77 65 0D 
$ 

Does this PR introduce a breaking change, and is titled accordingly?

No

Other information

I've tested it on Linux only. More testing is needed especially on Windows.

Fix #2251

@cmaglie cmaglie changed the title feature: Added raw terminal support in montior command feature: Added raw terminal support in monitor command Sep 1, 2023
@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

Patch coverage: 18.75% and project coverage change: -0.14% ⚠️

Comparison is base (3f9373a) 63.40% compared to head (b7e4a39) 63.26%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2291      +/-   ##
==========================================
- Coverage   63.40%   63.26%   -0.14%     
==========================================
  Files         219      218       -1     
  Lines       19536    19555      +19     
==========================================
- Hits        12386    12371      -15     
- Misses       6069     6099      +30     
- Partials     1081     1085       +4     
Flag Coverage Δ
unit 63.26% <18.75%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
internal/cli/feedback/terminal.go 9.09% <0.00%> (-2.68%) ⬇️
internal/cli/monitor/monitor.go 15.68% <23.68%> (+2.60%) ⬆️

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself topic: CLI Related to the command line interface labels Sep 1, 2023
Copy link
Contributor

@alessio-perugini alessio-perugini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested on:
Linux - ubuntu: ✔️
Windows 11: ✔️

internal/cli/feedback/terminal.go Outdated Show resolved Hide resolved
@cmaglie cmaglie merged commit d5c83ad into arduino:master Sep 6, 2023
93 checks passed
@cmaglie cmaglie deleted the raw_terminal branch September 6, 2023 08:53
@oscherler
Copy link

You mention that in raw mode, “CR are not automatically added after NL.” This confuses me on two levels:

  1. Usually, CR appears before LF;
  2. This sentence seems to imply that in normal mode, CR is added to new lines, but on my Mac, only LF is sent on new line (causing my old projects to break with arduino-cli.)

@cmaglie
Copy link
Member Author

cmaglie commented Feb 2, 2024

Usually, CR appears before LF;

You're right, the sequence is CR+LF, I've edited the post.

This sentence seems to imply that in normal mode, CR is added to new lines, but on my Mac, only LF is sent on new line (causing my old projects to break with arduino-cli.)

In raw mode, the OS terminal emulation is bypassed, and when you press the "Enter" key, the CLI gets directly the 0x0D char code and sends it to the serial port without further processing.

In non-raw mode, the terminal emulator does some processing before the character reaches arduino-cli, on my Linux box "Enter" is translated into a CR+LF sequence (my Linux terminal emulation is xterm-256color it may be different on other OS).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: CLI Related to the command line interface topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arduino-cli monitor does not flush characters until \n is typed
4 participants