Skip to content

Conversation

bolotskydev
Copy link
Collaborator

@bolotskydev bolotskydev commented Nov 25, 2020

Describe changes
This commit makes sure terminal input signs are no more parts of copy btn content in code blocks.

Verbose

Unfortunately, I failed to set up attaching $ signs automatically as planned initially for two reasons:

  1. First try: attach to every single line of a bash code block

Quickly realised it was a bad idea since bash blocks may include not only bash commands, but output as well and $ signs would be redundant and look weird.

  1. Second try: use the only possible way to distinguish terminal input from terminal output programmatically.

Lines with input starts with function token type whereas output tokens have token type of plain. I set up to attach $ sign to a beginning of a code line if it starts with function, but It turned out this isn't an option as well: prism parser doesn't recognize such commands as brew, docker, k6 etc, so lines starting with those wouldn't have $ sign and we have no capabilities to extend the dictionary.

Given that, I came up with the following solution: we keep $ signs in bash terminals, add them manually where we need it, but copy button would be stripped of every $ that is a first character of a code line.

Side:

  • adjusted CodeGroup component similarly how it was done on blog to prevent buggy behavior
  • added $ signs to bash blocks on Installation page

Steps to test

  1. Open up preview, find any bash terminal with $ signs indicating the bash input
  2. Click on Copy button, paste the buffer content
  3. Assure $ chars were stripped from lines indeed

References
Closes #158

Side:
- adjusted CodeGroup component similarly how it was done on blog to prevent buggy behavior
- added $ signs to bash block on Installation page
@github-actions
Copy link
Contributor

There's a version of the docs published here:

https://mdr-ci.staging.k6.io/docs/refs/pull/161/merge

It will be deleted automatically in 30 days.

@simskij
Copy link
Contributor

simskij commented Nov 25, 2020

Ace! Good job!

@simskij simskij self-requested a review November 25, 2020 08:54
@bolotskydev bolotskydev merged commit 5a108c5 into master Nov 25, 2020
@bolotskydev bolotskydev deleted the feat/auto-bash-input-signs branch November 25, 2020 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strip prompts from copied shell scripts.
2 participants