Skip to main content

An interactive terminal question and answer module.

Project description

Interactive Terminal

interactive_terminal is a Python module that provides an easy-to-use interface for creating interactive command-line applications. With this module, developers can ask various types of questions, including text input, lists, confirmations, numeric inputs, ranges, and choices, all while validating user responses for a smooth user experience.

Features

  • Supports multiple question types:
    • Text Input: For open-ended questions.
    • List Selection: Allows users to choose from a list of options.
    • Confirmation: Simple yes/no questions.
    • Numeric Input: For getting numeric responses.
    • Range Selection: For selecting a range of values.
    • Choice Selection: For picking one option from multiple choices.
  • Input validation to ensure accurate and meaningful user responses.
  • Easy integration into Python applications.

Installation

You can install the interactive_terminal module using pip. Open your terminal or command prompt and run:

pip install interactive_terminal

Usage

To use the interactive_terminal module, follow these steps:

  1. Import the necessary classes from the module.
  2. Define the questions you want to ask using the Question class.
  3. Call the ask_questions function to prompt the user and collect their responses.

Example

Here's a simple example demonstrating how to use the interactive_terminal module:

from interactive_terminal import Question, QuestionType, ask_questions

def main():
    questions = [
        Question(QuestionType.TEXT, "name", "What is your name?"),
        Question(QuestionType.LIST, "favorite_color", "What is your favorite color?", 
                 options=["Red", "Blue", "Green", "Yellow"]),
        Question(QuestionType.CONFIRM, "like_programming", "Do you like programming?"),
        Question(QuestionType.NUMBER, "experience_years", "How many years have you been programming?"),
        Question(QuestionType.RANGE, "age_range", "What is your age range?", 
                 options=["0-18", "19-30", "31-45", "46+"]),
        Question(QuestionType.CHOICE, "os_choice", "Which operating system do you prefer?",
                 options=["Windows", "macOS", "Linux"])
    ]
    
    answers = ask_questions(questions)
    print("\nThank you for your answers! Here's what you provided:")
    for key, value in answers.items():
        print(f"{key.capitalize()}: {value}")

if __name__ == "__main__":
    main()

Output

When you run the example code, it will prompt the user with a series of questions, like so:

[?] What is your name?:

The user can respond with their name, and the program will continue asking the rest of the questions in sequence, validating their input as specified.

Contributing

Contributions are welcome! If you have suggestions for improvements or new features, please email me and I will think about your request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Release history Release notifications | RSS feed

This version

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

interactive_terminal-0.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

interactive_terminal-0.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file interactive_terminal-0.2.tar.gz.

File metadata

  • Download URL: interactive_terminal-0.2.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for interactive_terminal-0.2.tar.gz
Algorithm Hash digest
SHA256 7f269ddd313bba13a289252b243395800733d5c19e6746d0f523ddf5cfa5d724
MD5 db3c1135ffb67b550d7db6de0091d6d6
BLAKE2b-256 aa4d1d3ddfe8e834b9c1bceb8e9b12a8140d3f216b2e9514f23e6f762cd83ebc

See more details on using hashes here.

File details

Details for the file interactive_terminal-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for interactive_terminal-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 611f4b5e4e25574a4a9c47e775ceede633465fe1c4f3d5522baf94163b182db5
MD5 15098e02aff4457f8cd1050934ae6187
BLAKE2b-256 0cd5d98d6e3257b39f3e6fa4c20b72bd68101e3fb33cbdaf100915f53509f6d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page