Skip to content

Commit

Permalink
Add examples of terminal screens in README
Browse files Browse the repository at this point in the history
  • Loading branch information
fractaledmind committed Aug 20, 2024
1 parent bbeec71 commit 0768288
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ A `Text` prompt will prompt the user with the given question, accept their input
name = Prompts::TextPrompt.ask(label: "What is your name?")
```

which generates a terminal screen like this (this representation doesn't show color):
<pre>

<b>What is your name?</b> <em>(Press Enter to submit)</em>
<b>Type your response and press Enter ⏎</b>

<b>></b> |
</pre>

You may also include a default value and an informational hint:

```ruby
Expand All @@ -38,6 +47,15 @@ name = Prompts::TextPrompt.ask(
)
```

which generates a terminal screen like this (this representation doesn't show color):
<pre>

<b>What is your name?</b> <em>(Press Enter to submit)</em>
<b>This will be displayed on your profile.</b>

<b>></b> John Doe|
</pre>

#### Required values

If you require a value to be entered, you may pass the `required` argument:
Expand Down Expand Up @@ -88,6 +106,18 @@ role = Prompts::SelectPrompt.ask(
)
```

which generates a terminal screen like this (this representation doesn't show color):
<pre>

<b>What role should the user have?</b> <em>(Enter the number of your choice)</em>
<b>Type your response and press Enter ⏎</b>
<b>1.</b> Member
<b>2.</b> Contributor
<b>3.</b> Owner

<b>></b> |
</pre>

You may also include a default value and an informational hint:

```ruby
Expand All @@ -99,6 +129,18 @@ role = Prompts::SelectPrompt.ask(
)
```

which generates a terminal screen like this (this representation doesn't show color):
<pre>

<b>What role should the user have?</b> <em>(Enter the number of your choice)</em>
<b>The role may be changed at any time.</b>
<b>1.</b> Member
<b>2.</b> Contributor
<b>3.</b> Owner

<b>></b> 3|
</pre>

You may also pass a hash to the `options` argument to have the selected key returned instead of its value:

```ruby
Expand Down Expand Up @@ -143,6 +185,14 @@ If you need to ask the user for a "yes or no" confirmation, you may use the `Con
confirmed = Prompts::ConfirmPrompt.ask(label: "Do you accept the terms?")
```

which generates a terminal screen like this (this representation doesn't show color):
<pre>

<b>Do you accept the terms?</b> <em>(Press Enter to submit)</em>

<b>Choose [y/n]:</b> |
</pre>

You may also include a default value and an informational hint:

```ruby
Expand All @@ -153,6 +203,15 @@ confirmed = Prompts::ConfirmPrompt.ask(
)
```

which generates a terminal screen like this (this representation doesn't show color):
<pre>

<b>Do you accept the terms?</b> <em>(Press Enter to submit)</em>
<b>The terms must be accepted to continue.</b>

<b>Choose [y/N]:</b> |
</pre>

#### Requiring "Yes"

If necessary, you may require your users to select "Yes" by passing the `required` argument:
Expand Down Expand Up @@ -181,6 +240,12 @@ The `PausePrompt` may be used to display informational text to the user and wait
Prompts::PausePrompt.ask
```

which generates a terminal screen like this (this representation doesn't show color):
<pre>

<b>Press Enter ⏎ to continue...</b> |
</pre>

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down

0 comments on commit 0768288

Please sign in to comment.