rust-lang / rustlings

:crab: Small exercises to get you used to reading and writing Rust code!
https://rustlings.cool
MIT License
53.88k stars 10.13k forks source link

Accessibility: Limit line lengths for messages #2094

Closed jsejcksn closed 2 months ago

jsejcksn commented 2 months ago

It would be helpful to format messages with a fixed line length limit instead of printing pre-formatted strings as-is — in order to avoid undesirable line-breaks/malformed indentation for users who are not using wider terminals.

Toward a solution: rustlings could read the number of columns reported by the terminal and then transform message texts to break and re-indent as appropriate… falling back to a standardized lowest-common-denominator (I think the most common standard is 80^1). Without such a feature (or until it can be implemented), the existing messages could simply be re-formatted to break at that LCD length.

Here's an example to illustrate the problem I described: when using a terminal with a width of 80 columns, I see the welcome message printed this way:

Is this your first time? Don't worry, Rustlings is made for beginners!
We are going to teach you a lot of things about Rust, but before we can
get started, here are some notes about how Rustlings operates:

1. The central concept behind Rustlings is that you solve exercises. These
   exercises usually contain some compiler or logic errors which cause the
   exercise to fail compilation or testing. It's your job to find all errors
   and fix them!
2. Make sure to have your editor open in the `rustlings/` directory. Rustlings
   will show you the path of the current exercise under the progress bar. Open
   the exercise file in your editor, fix errors and save the file. Rustlings wil
l
   automatically detect the file change and rerun the exercise. If all errors ar
e
   fixed, Rustlings will ask you to move on to the next exercise.
3. If you're stuck on an exercise, enter `h` to show a hint.
4. If an exercise doesn't make sense to you, feel free to open an issue on GitHu
b!
   (https://github.com/rust-lang/rustlings). We look at every issue, and sometim
es,
   other learners do too so you can help each other out!
mo8it commented 2 months ago

Thanks for pointing this out! I will just remove these newlines and let the terminal handle line wrapping.

jsejcksn commented 2 months ago

Thanks for pointing this out! I will just remove these newlines and let the terminal handle line wrapping.

@mo8it That would fix the described issue, but… hanging indentation improves readability — and list items are harder to scan and differentiate from other block content without it. I think that the crate unicode-segmentation can help with generating lines to fit terminals. It might require a different (more complex) kind of structure for the existing messages, but I think readability is important in terminal UX.


Edit: I haven't looked at all of the sources for these pre-formatted messages, but perhaps they can be parsed as markdown in order to be formatted as appropriate for different destinations — e.g. formatting long list items with hanging indentation in a terminal. This might also open up the possibility to generate a content index on the website in the future if desired…

mo8it commented 2 months ago

After merging your PR, I think the best way to solve this is to manually break after the length of 80. But I don't want to enforce it, especially not for third-party exercises. Because the compiler messages shown by Rustlings don't limit their output at 80 and require wrapping anyway. So I will leave it to the user if they want to wrap manually or let the terminal wrap.

jsejcksn commented 2 months ago

@mo8it Understood. If you change your mind about this in the future, feel free to let me know: I might like to work on the kind of feature that I described.