Console
provide.foundation.console
¶
TODO: Add module docstring.
Functions¶
apin
async
¶
Async input from stdin with optional prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Prompt to display before input |
''
|
**kwargs
|
Any
|
Same as pin() |
{}
|
Returns:
| Type | Description |
|---|---|
str | Any
|
User input as string or converted type |
Examples:
name = await apin("Enter name: ") age = await apin("Age: ", type=int)
Note: This runs the blocking input in a thread pool to avoid blocking the event loop.
Source code in provide/foundation/console/input.py
apin_lines
async
¶
Async read multiple lines from stdin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int | None
|
Number of lines to read (None for all until EOF) |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of input lines |
Examples:
lines = await apin_lines(3) # Read exactly 3 lines all_lines = await apin_lines() # Read until EOF
Source code in provide/foundation/console/input.py
apin_stream
async
¶
Async stream input line by line from stdin.
Yields:
| Type | Description |
|---|---|
AsyncIterator[str]
|
Lines from stdin (without trailing newline) |
Examples:
async for line in apin_stream(): await process(line)
This provides non-blocking line-by-line input streaming.
Source code in provide/foundation/console/input.py
perr
¶
Output message to stderr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Any
|
Content to output (any type - will be stringified or JSON-encoded) |
required |
**kwargs
|
Any
|
Optional formatting arguments: color: Color name (red, green, yellow, blue, cyan, magenta, white) bold: Bold text dim: Dim text nl/newline: Add newline (default: True) json_key: Key for JSON output mode prefix: Optional prefix string ctx: Override context |
{}
|
Examples:
perr("Error occurred") perr("Warning", color="yellow") perr({"error": details}, json_key="error")
Source code in provide/foundation/console/output.py
pin
¶
Input from stdin with optional prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Prompt to display before input |
''
|
**kwargs
|
Any
|
Optional formatting arguments: type: Type to convert input to (int, float, bool, etc.) default: Default value if no input provided password: Hide input for passwords (default: False) confirmation_prompt: Ask for confirmation (for passwords) hide_input: Hide the input (same as password) show_default: Show default value in prompt value_proc: Callable to process the value json_key: Key for JSON output mode ctx: Override context color: Color for prompt (red, green, yellow, blue, cyan, magenta, white) bold: Bold prompt text |
{}
|
Returns:
| Type | Description |
|---|---|
str | Any
|
User input as string or converted type |
Examples:
name = pin("Enter name: ") age = pin("Age: ", type=int, default=0) password = pin("Password: ", password=True)
In JSON mode, returns structured input data.
Source code in provide/foundation/console/input.py
pin_lines
¶
Read multiple lines from stdin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int | None
|
Number of lines to read (None for all until EOF) |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of input lines |
Examples:
lines = pin_lines(3) # Read exactly 3 lines all_lines = pin_lines() # Read until EOF
Source code in provide/foundation/console/input.py
pin_stream
¶
Stream input line by line from stdin.
Yields:
| Type | Description |
|---|---|
str
|
Lines from stdin (without trailing newline) |
Examples:
for line in pin_stream(): process(line)
Note: This blocks on each line. For non-blocking, use apin_stream().
Source code in provide/foundation/console/input.py
pout
¶
Output message to stdout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Any
|
Content to output (any type - will be stringified or JSON-encoded) |
required |
**kwargs
|
Any
|
Optional formatting arguments: color: Color name (red, green, yellow, blue, cyan, magenta, white) bold: Bold text dim: Dim text nl/newline: Add newline (default: True) json_key: Key for JSON output mode prefix: Optional prefix string ctx: Override context |
{}
|
Examples:
pout("Hello world") pout({"data": "value"}) # Auto-JSON if dict/list pout("Success", color="green", bold=True) pout(results, json_key="results")