From 6bb37500ec2757a8a01bd2db1e755b453e9953e6 Mon Sep 17 00:00:00 2001 From: Gerrishon Sirere Date: Thu, 25 Aug 2022 13:47:18 +0300 Subject: [PATCH 1/2] Update 2022-02-25-build-clis-with-quo.md Updated the documentation to be in alignment with the new version --- .../posts/2022-02-25-build-clis-with-quo.md | 280 ++++++++++++++---- 1 file changed, 215 insertions(+), 65 deletions(-) diff --git a/Content/posts/2022-02-25-build-clis-with-quo.md b/Content/posts/2022-02-25-build-clis-with-quo.md index 968fb2a..325bffc 100644 --- a/Content/posts/2022-02-25-build-clis-with-quo.md +++ b/Content/posts/2022-02-25-build-clis-with-quo.md @@ -32,6 +32,9 @@ Quo requires Python `3.8` or later. - [x] Key Binders ## Getting Started +## Quo Library +Quo contains a number of builtin features you c +an use to create elegant output in your CLI. ### Installation @@ -91,9 +94,7 @@ print('This is red') print('!') + + # Returns a callable + session = Prompt(bottom_toolbar=toolbar) + session.prompt('> ') + ``` -Read more on [Console](https://quo.readthedocs.io/en/latest/console.html). +![validate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/bottom-toolbar.png) + +Read more on [Prompt](https://quo.readthedocs.io/en/latest/prompt.html). ## Completions @@ -195,7 +205,65 @@ python example.py --help ![Help Text](https://raw.githubusercontent.com/secretum-inc/quo/master/docs/images/help-text.png) -## Progress +## Quo Dialogs + +This is a high level API for displaying dialog boxes to the user for informational purposes, or get input from the user. + +**Example 1** + +A MessageBox dialog. + +```python +from quo.dialog import MessageBox + +MessageBox( + title="Message pop up window", + text="Do you want to continue?\nPress ENTER to quit.") +``` + +![Message Box](https://github.com/secretum-inc/quo/raw/master/docs/images/messagebox.png) + +**Example 2** + +A InputBox dialog + +```python +from quo.dialog import InputBox + +InputBox( + title="InputBox shenanigans", + text="What Country are you from?:") +``` + +![Prompt Box](https://github.com/secretum-inc/quo/raw/master/docs/images/promptbox.png) + +Read more on [Dialogs](https://quo.readthedocs.io/en/latest/dialogs.html). + + +## Quo Key Binding🔐 + +A key binding is an association between a physical key on akeyboard and a parameter. + +```python + + from quo import echo + from quo.keys import bind + from quo.prompt import Prompt + + session = Prompt() + + # Print "Hello world" when ctrl-h is pressed + @bind.add("ctrl-h") + def _(event): + echo("Hello, World!") + + session.prompt("") + +``` + +Read more on [Key bindings](https://quo.readthedocs.io/en/latest/kb.html) + +## Quo Progress📈 Creating a new progress bar can be done by calling the class **ProgressBar** The progress can be displayed for any iterable. This works by wrapping the iterable (like ``range``) with the class **ProgressBar** @@ -212,96 +280,178 @@ with ProgressBar() as pb: Read more on [Progress](https://quo.readthedocs.io/en/latest/progress.html). -## Key Binding -A key binding is an association between a physical key on a keyboard and a parameter. + +## Quo Tables + +This offers a number of configuration options to set the look and feel of the table, including how borders are rendered and the style and alignment of the columns. + +**Example 1** ```python -from quo import echo -from quo.keys import bind -from quo.prompt import Prompt - -session = Prompt() -# Print "Hello world" when ctrl-h is pressed -@bind.add("ctrl-h") -def _(event): - echo("Hello, World!") -session.prompt(">> ") -``` -Read more on [Key bindings](https://quo.readthedocs.io/en/latest/kb.html). + from quo.table import Table -## Dialogs + data = [ + ["Name", "Gender", "Age"], + ["Alice", "F", 24], + ["Bob", "M", 19], + ["Dave", "M", 24] + ] -This is a high level API for displaying dialog boxes to the user for informational purposes, or get input from the user. + Table(data) -1) Example of a message box dialog. +``` +![tabulate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/tables/table.png) + +**Example 2** + +Right aligned table ```python -from quo.dialog import MessageBox -MessageBox( - title="Message pop up window", - text="Do you want to continue?\nPress ENTER to quit.") + from quo.table import Table + + data = [ + ["Name", "Gender", "Age"], + ["Alice", "F", 24], + ["Bob", "M", 19], + ["Dave", "M", 24] + ] + Table(data, align="right") + ``` -The above code produces the following output -![Message Box](https://github.com/secretum-inc/quo/raw/master/docs/images/messagebox.png) +![tabulate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/tables/right-table.png) + +**Example 3** -2) Example of a prompt box dialog +Colored table ```python -from quo.dialog import InputBox -InputBox( - title="InputBox shenanigans", - text="What Country are you from?:") -``` + from quo.table import Table -![Prompt Box](https://github.com/secretum-inc/quo/raw/master/docs/images/promptbox.png) + data = [ + ["Name", "Gender", "Age"], + ["Alice", "F", 24], + ["Bob", "M", 19], + ["Dave", "M", 24] + ] + + Table(data, style="fg:green") -Read more on [Dialogs](https://quo.readthedocs.io/en/latest/dialogs.html). +``` -## Tables -Function [Table](https://quo.readthedocs.io/en/latest/table.html) offers a number of configuration options to set the look and feel of the table, including how borders are rendered and the style and alignment of the columns. +![tabulate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/tables/colored-table.png) -Example +**Example 4** + +Grid table ```python -from quo.table import Table -data = [ - ["Name", "Gender", "Age"], - ["Alice", "F", 24], - ["Bob", "M", 19], - ["Dave", "M", 24] -] + from quo.table import Table + + data = [ + ["Name", "Gender", "Age"], + ["Alice", "F", 24], + ["Bob", "M", 19], + ["Dave", "M", 24] + ] + + Table(data, theme="grid") -Table(data) ``` -![tabulate](https://raw.githubusercontent.com/secretum-inc/quo/master/docs/images/table.png) -## Widgets +![tabulate](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/tables/grid-table.png) + + + +Read more on [Table](https://quo.readthedocs.io/en/latest/table.html) + + +## Quo Widgets A collection of reusable components for building full screen applications. -### Label +``Frame`` 🎞️ + +Draw a border around any container, optionally with a title. + +```python + + from quo import container + from quo.widget import Frame, Label + + content = Frame( + Label("Hello, World!"), + title="Quo: python") + + #Press Ctrl-C to exit + container(content, bind=True, full_screen=True) + +``` +![Frame](https://raw.githubusercontent.com/scalabli/quo/master/docs/images/widgets/frame.png) + +``Label`` Widget that displays the given text. It is not editable or focusable. +**Example 1** + +This will occupy a minimum space in your terminal + ```python -from quo import container -from quo.widget import Label -content = Label("Hello, World", style="fg:black bg:red") - -# Press `ctrl-c` to exit -container(content, bind=True, full_screen=True) + from quo import container + from quo.widget import Label + + content = Label("Hello, World", style="fg:black bg:red") + + container(content) ``` +**Example 2** + +This will be a fullscreen application + +```python + + from quo import container + from quo.widget import Label + + content = Label("Hello, World", style="fg:black bg:red") + + # Press Ctrl-C to exit + container(content, bind=True, full_screen=True) + +``` + +**Example 3** + +Full screen application using a custom binding key. + +```python + + from quo import container + from quo.keys import bind + from quo.widget import Label + + content = Label("Hello, World", style="fg:black bg:red") + + #Press Ctrl-Z to exit + @bind.add("ctrl-z") + def _(event): + event.app.exit() + + container(content, bind=True, full_screen=True) + +``` + +Read more on [Widgets](https://quo.readthedocs.io/en/latest/widgets.html) -Read more on [Widgets](https://quo.readthedocs.io/en/latest/widgets.html). Quo is _simple_. If you know Python you can easily use quo and it can integrate with just about anything. From b6bc727021c7ecbcfe5ebbde1c704645f49ad1cf Mon Sep 17 00:00:00 2001 From: Gerrishon Sirere Date: Thu, 25 Aug 2022 14:23:13 +0300 Subject: [PATCH 2/2] Update 2022-02-25-build-clis-with-quo.md --- .../posts/2022-02-25-build-clis-with-quo.md | 96 ++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) diff --git a/Content/posts/2022-02-25-build-clis-with-quo.md b/Content/posts/2022-02-25-build-clis-with-quo.md index 325bffc..dbf41ec 100644 --- a/Content/posts/2022-02-25-build-clis-with-quo.md +++ b/Content/posts/2022-02-25-build-clis-with-quo.md @@ -139,7 +139,7 @@ A prompt with a bottom toolbar Read more on [Prompt](https://quo.readthedocs.io/en/latest/prompt.html). -## Completions +## Quo Completions ### Autocompletion @@ -175,6 +175,100 @@ while True: Read more on [Completions](https://quo.readthedocs.io/en/latest/prompt.html#completion). +## Quo Console + +For more control over quo terminal content, import and construct a `Console` object. + + +``Bar`` + +Draw a horizontal bar with an optional title, which is a good way of dividing your terminal output in to sections. + +```python + + from quo.console import Console + + console = Console() + console.bar("I am a bar", style="fg:red bg:yellow") + +``` + +``Launching Applications`` + +Quo supports launching applications through `Console.launch` + +**Example 1** + +```python + + from quo.console import Console + + console = Console() + console.launch("https://quo.rtfd.io/") + +``` + +**Example 2** + +```python + + from quo.console import Console + + console = Console() + console.launch("/home/path/README.md", locate=True) + +``` + +``Rule`` + +Used for drawing a horizontal line. + +**Example 1** + +```python + + from quo.console import Console + + console = Console() + console.rule( + +``` + +**Example 2** + +A multicolored line. + +```python + + from quo.console import Console + + console = Console() + console.rule(multicolored=True) + +``` +![Multicolored](https://quo.readthedocs.io/en/latest/_images/rulemulticolored.jpg) + + +``Spin``🔁 + +Quo can create a context manager that is used to display a spinner on stdout as long as the context has not exited + +```python + + import time + from quo.console import Console + + console = Console() + + with console.spin(): + time.sleep(3) + print("Hello, World") + +``` +Read more on [Console](https://quo.readthedocs.io/en/latest/console.html) + + + ## Documenting Scripts Quo automatically generates help pages for your command-line tools.