Skip to content

Commit

Permalink
Fix documentation mistakes
Browse files Browse the repository at this point in the history
This commit does two things: it fixes some bad documentation mistakes in the example sections of each cue and it swaps certain images for better ones.
  • Loading branch information
giosali committed Jun 6, 2021
1 parent d836458 commit 4d21d94
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 10 deletions.
Binary file modified docs/source/_static/confirm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/_static/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/password.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/password_endswith_alnum.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/_static/select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/_static/survey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/source/pages/cues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ List of cues
cues/checkbox
cues/confirm
cues/form
cues/password
cues/select
cues/survey
6 changes: 3 additions & 3 deletions docs/source/pages/cues/checkbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ In the previous example, we initialized separte variables for the ``__init__`` m


checkbox_dict = {
name = 'guitars'
message = 'Pick your favorite guitars:'
options = [
'name': 'guitars'
'message': 'Pick your favorite guitars:'
'options': [
'Les Paul',
'Stratocaster',
'Telecaster',
Expand Down
8 changes: 4 additions & 4 deletions docs/source/pages/cues/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ When you "send" the cue to the user, they will be presented with something that

*The Form cue*

The user will not be expected to answer these prompts by typing their responses. Once the user has finished, a ``dict`` containing another ``dict`` will be returned. The inner-``dict`` will consist of key-value pairs of your ``fields`` and the user's responses respectively. The result will resemble the following:
The user will then be able to answer these prompts by typing their responses. Once the user has finished, a ``dict`` containing another ``dict`` will be returned. The inner-``dict`` will consist of key-value pairs of your ``fields`` and the user's responses respectively. The result will resemble the following:
::

{
Expand Down Expand Up @@ -126,9 +126,9 @@ In the previous example, we initialized separte variables for the ``__init__`` m


form_dict = {
name = 'basic_info'
message = 'Please fill out the following form:'
fields = [
'name': 'basic_info'
'message': 'Please fill out the following form:'
'fields': [
{
'name': 'first_name',
'message': 'First name'
Expand Down
109 changes: 109 additions & 0 deletions docs/source/pages/cues/password.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
Password
========

This page will explain how to use the ``Password`` cue of the `Cues` library.

``Password`` objects are useful when you need input from the user but would prefer their input be hidden while they type as it may contain sensitive information. The expected input is a ``str`` object. The result is a ``dict`` containing a ``str``.

Before we start, make sure you have `Cues` `installed <../install.html>`_.

Setting up
----------

``Password`` objects have three required parameters:

+------------+------------+------------+------------+
| Parameters | Type | Optional | Default |
+============+============+============+============+
| name | str | No | |
+------------+------------+------------+------------+
| message | str | No | |
+------------+------------+------------+------------+

The signature for the ``__init__`` method of a ``Password`` object:
::

def __init__(self, name, message):
# ...

With that out of the way, we first need to start by importing ``Password`` from the `Cues` library:
::

from cues import Password

Now, we need to instantiate a ``Password`` object. We can do this with a little bit of setup by initializing some variables:
::

name = 'password'
message = 'Password:'

In the code above, we created the variables ``name`` and ``message``:

- ``name`` will be used to retrieve the results from a ``Password`` object
- ``message`` is the text that will be displayed to the user

That's it! Our setup is complete. We can now go ahead and initialize a ``Password`` object to ask the user to enter a password by invoking the object's ``send`` method:
::

cue = Password(name, message)
answer = cue.send()

When you "send" the cue to the user, they will be presented with something that looks like the following:

.. figure:: ../../_static/password.png
:width: 600px
:align: center
:alt: password snapshot
:figclass: align-center

*The Password cue*

As the user types, asterisks will appear where their input normally would if you were to use Python's built-in ``input`` function. The user can use the Backspace/Delete key to undo any mistakes or reset their input. Once they're done, they can hit the Enter key and a ``dict`` will be returned with a ``str`` object:
::

{'password': '1234'}

Two formats
-----------

There are two possible formats that can be used for displaying the `message` to the user: one that ends with a bullet point and one that doesn't.

If your message ends with an alphanumerical character (A-Z | 0-9), then a bullet point will separate the message you provide and the user's input:

.. figure:: ../../_static/password_endswith_alnum.png
:width: 600px
:align: center
:alt: password snapshot
:figclass: align-center

*The Password cue*

Otherwise, if your message ends with a colon or a question mark, the only thing separating your message and the user's input will be one whitespace character:

.. figure:: ../../_static/password.png
:width: 600px
:align: center
:alt: password snapshot
:figclass: align-center

*The Password cue*


Instantiating from a dict
-------------------------

In the previous example, we initialized separte variables for the ``__init__`` method of a ``Password`` object. *However*, we could also make use of the class's ``from_dict`` classmethod and instantiate by using a ``dict`` instead:
::

from cues import Password


password_dict = {
'name': 'password',
'message': 'Password:'
}

cue = Password.from_dict(password_dict)
answer = cue.send()

The names for the *values* in this ``dict`` must be the same as the names of the parameters in the ``__init__`` method.
6 changes: 3 additions & 3 deletions docs/source/pages/cues/select.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ In the previous example, we initialized separte variables for the ``__init__`` m


select_dict = {
name = 'programming_language'
message = 'Which one is your favorite programming language?'
options = [
'name': 'programming_language'
'message': 'Which one is your favorite programming language?'
'options': [
'Python',
'JavaScript',
'C++',
Expand Down
11 changes: 11 additions & 0 deletions docs/source/pages/gallery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ Form

*The Form cue*

Password
--------

.. figure:: ../_static/password.png
:width: 600px
:align: center
:alt: password snapshot
:figclass: align-center

*The Password cue*

Select
------

Expand Down

0 comments on commit 4d21d94

Please sign in to comment.