Skip to content

Commit

Permalink
Merge pull request #86 from scalabli/_quo
Browse files Browse the repository at this point in the history
#Bug fixes
  • Loading branch information
quantum-quirks committed May 8, 2022
2 parents 3462df4 + 0cda65b commit 906a7e4
Show file tree
Hide file tree
Showing 38 changed files with 434 additions and 223 deletions.
9 changes: 9 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ Changelog

.. image:: https://media.giphy.com/media/12oufCB0MyZ1Go/giphy.gif

``Version 2022.5.2``
---------------------

Released on 2022-05

**Added**
^^^^^^^^^^
- Added :func:`quo.color.Color`

``Version 2022.5.1``
---------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/printing_text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ It is possible to create a list of manually with FormattedText class. This is a
])
print(text, fmt=True)
Similar to theit is also possible to use class names, and separate the styling in a style sheet.
It is also possible to use class names, and separate the styling in a style sheet.

.. code:: python
Expand Down
47 changes: 23 additions & 24 deletions docs/prompt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ This can be accomplished with the :func:`prompt` function, which asks for
valid input according to a type, or the :class:`quo.prompt.Prompt` object, this makes it possible to create a Prompt instance followed by calling prompt() method for every input. This creates a kind of an input session and its packed with lots of features.
You can also use the :func:`quo.confirm` function, which asks for confirmation (yes/no).

The following snippet uses the :func:`quo.prompt` function to ask the user for input
and returns the text. Just like ``input``.
The following snippet uses the :func:`quo.prompt` function to ask the user for input just like ``input``.

.. code:: python
Expand Down Expand Up @@ -393,16 +392,16 @@ A simple way to add color to create a style, is by using the :meth:`~quo.style.S
Coloring the prompt itself
^^^^^^^^^^^^^^^^^^^^^^^^^^

It is possible to add some colors to the prompt itself. For this, we need to
build some :ref:`formatted text <formatted_text>`. One way of doing this is by
creating a list of style/text tuples. In the following example, the input will be in red
It is possible to add some colors to the prompt itself. For this, we need to import :func:`quo.color.Color` function.
In the following example, the input will be in red
*version changed 2022.5.2*

.. code:: python
from quo.color import Color
from quo.prompt import Prompt
from quo.style import Style
style = Style.add({' ':'fg:red'}) #User input (default text)
style = Color("fg:red") #User input (default text)
session = Prompt(style=style)
Expand All @@ -415,10 +414,11 @@ Here's an example upgrade:

.. code:: python
from quo.color import Color
from quo.prompt import Prompt
from quo.style import Style
style = Style.add({' ':'fg:blue'}) # User input (default text)
style = Color("fg:blue") # User input (default text)
session = Prompt(style=style)
message = [
Expand Down Expand Up @@ -553,37 +553,37 @@ otherwise. So, make sure to disable history search for this.

A :class:`~quo.history.History` object keeps track of all the previously entered strings, so that the up-arrow can reveal previously entered items.

InMemoryHistory
^^^^^^^^^^^^^^^^^^^^
The recommended way is to use a :class:`~quo.prompt.Prompt`, which uses an :class:`~quo.history.InMemoryHistory` which has `^` (up) arrow partial string matching enabled by default.
MemoryHistory
^^^^^^^^^^^^^^^^^
The recommended way is to use a :class:`~quo.prompt.Prompt`, which uses an :class:`~quo.history.MemoryHistory` which has `^` (up) arrow partial string matching enabled by default.

.. code:: python
from quo.history import MemoryHistory
from quo.prompt import Prompt
from quo.history import InMemoryHistory
history = InMemoryHistory()
history.append("import os")
history.append('print("hello")')
history.append('print("world")')
history.append("import path")
MemoryHistory.append("import os")
MemoryHistory.append('print("hello")')
MemoryHistory.append('print("world")')
MemoryHistory.append("import path")
session = Prompt(history=history)
session = Prompt(history=MemoryHistory)
while True:
session.prompt()
FileHistory
^^^^^^^^^^^^^^^^
To persist a history to disk, use a :class:`~quo.history.FileHistory` instead of the default :class:`~quo.history.InMemoryHistory`. This history object can be passed to a :class:`~quo.prompt.Prompt`.
To persist a history to disk, use a :class:`~quo.history.FileHistory` instead of the default :class:`~quo.history.MemoryHistory`. This history object can be passed to a :class:`~quo.prompt.Prompt`.
For instance:

.. code:: python
from quo.prompt import Prompt
from quo.history import FileHistory
from quo.prompt import Prompt
session = Prompt(history=FileHistory('~/.myhistory'))
history = FileHistory("~/.myhistory")
session = Prompt(history=history)
while True:
session.prompt()
Expand Down Expand Up @@ -699,5 +699,4 @@ Line wrapping is enabled by default. This is what most people are used to and th
session.prompt('What is your name: ')
禄 Check out more examples `here <https://github.com/scalabli/quo
/tree/master/examples/prompts/>`_
禄 Check out more examples `here <https://github.com/scalabli/quo/tree/master/examples/prompts/>`_
11 changes: 11 additions & 0 deletions examples/full-screen/exampl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from quo import container
from quo.widget import TextField


with open("/root/git/quo/examples/full-screen/full-screen-demo.py", "rb") as f:
text = f.read().decode("utf-8")


content = TextField(text, multiline=True)

container(content)
36 changes: 13 additions & 23 deletions examples/full-screen/pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"""


from quo.console import Console
from quo.keys import Bind
from quo import container
from quo.layout import HSplit, Window, Layout
from quo.layout.controls import FormattedTextControl
from quo.layout.dimension import LayoutDimension as D
Expand Down Expand Up @@ -51,7 +50,7 @@ def get_statusbar_text():
)


root_container = HSplit(
content = HSplit(
[
# The top toolbar.
Window(
Expand All @@ -66,17 +65,6 @@ def get_statusbar_text():
)


# Key bindings.
bindings = Bind()


@bindings.add("ctrl-c")
@bindings.add("q")
def _(event):
"Quit."
event.app.exit()


style = Style.add(
{
"status.position": "#aaaa00",
Expand All @@ -85,15 +73,17 @@ def _(event):
}
)

layout = Layout(root_container, focused_element=text_area)
#ayout = Layout(root_container, focused_element=text_area)

# create application.

Console(
layout=layout,
bind=bindings,
enable_page_navigation_bindings=True,
mouse_support=True,
style=style,
# full_screen=True,
).run()
#onsole(
# layout=layout,
# bind=bindings,
#enable_page_navigation_bindings=True,
# mouse_support=True,
# style=style,
# full_screen=True,
# ).run()

container(content, bind=True, focused_element=text_area, full_screen=True, mouse_support=True, style=style)
11 changes: 1 addition & 10 deletions examples/full-screen/simple-demos/margins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from quo import container
from quo.buffer import Buffer
from quo.keys import bind
from quo.layout import HSplit, Layout, Window
from quo.layout import BufferControl, FormattedTextControl
from quo.layout.margin import NumberedMargin, ScrollbarMargin
Expand All @@ -24,7 +23,7 @@
# 1. The layout
content = HSplit(
[
Window(FormattedTextControl('Press "q" to quit.'), height=1, style="fg:red bg:yellow bold"),
Window(FormattedTextControl('Press "ctrl-c" to quit.'), height=1, style="fg:red bg:yellow bold"),
Window(
BufferControl(buffer=buff),
# Add margins.
Expand All @@ -35,13 +34,5 @@
)


# 2. Key bindings
@bind.add("q")
@bind.add("ctrl-c")
def _(event):
"Quit application."
event.app.exit()


# 3. The `Application`
container(content, bind=True, full_screen=True)
4 changes: 2 additions & 2 deletions examples/full-screen/split-screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from quo.console import Console
from quo.buffer import Buffer
from quo.keys import Bind
from quo.layout import Layout, Window, BufferControl, FormattedTextControl, VSplit, HSplit, WindowAlign
from quo.layout import Layout, Window, BufferControl, FormattedTextControl, VSplit, HSplit

# 3. Create the buffers
# ------------------
Expand Down Expand Up @@ -56,7 +56,7 @@ def get_titlebar_text():
Window(
height=1,
content=FormattedTextControl(get_titlebar_text),
align=WindowAlign.CENTER,
align="center"
),
# Horizontal separator.
Window(height=1, char="-", style="class:line"),
Expand Down
107 changes: 107 additions & 0 deletions examples/pager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env python
"""
A simple application that shows a Pager application.
"""

from quo import container
from pygments.lexers.python import PythonLexer

#from prompt_toolkit.application import Application
from quo.layout.containers import HSplit, Window
from quo.layout.controls import FormattedTextControl
from quo.layout.dimension import LayoutDimension as D
from quo.layout.layout import Layout
from quo.highlight import PygmentsLexer
from quo.style import Style
from quo.widget import Label, SearchToolbar, TextArea

# Create one text buffer for the main content.

_pager_py_path = __file__

_file = "/root/git/quo/setup.py"
with open(_file, "rb") as f:
text = f.read().decode("utf-8")


def get_statusbar_text():
return [
("class:status", _pager_py_path + " - "),
(
"class:status.position",
"{}:{}".format(
text_area.document.cursor_position_row + 1,
text_area.document.cursor_position_col + 1,
),
),
("class:status", " - Press "),
("class:status.key", "Ctrl-C"),
("class:status", " to exit, "),
("class:status.key", "/"),
("class:status", " for searching."),
]


search_field = SearchToolbar(
text_if_not_searching=[("class:not-searching", "Press '/' to start searching.")]
)

text_ = Window(FormattedTextControl(f"{text}"))
text_area = TextArea(
text,
read_only=True,
scrollbar=False,
line_numbers=True,
multiline=True,
search_field=search_field,
highlighter=PygmentsLexer(PythonLexer),
)

content = HSplit(
[
# The top toolbar.
Window(
content=FormattedTextControl(get_statusbar_text),
height=D.exact(1),
style="class:status",
),
# The main content.
text_area,
# text_,
search_field,
]
)


style = Style.add(
{
"status": "reverse",
"status.position": "#aaaa00",
"status.key": "#ffaa00",
"not-searching": "#888888",
}
)


# create application.
#application = Application(
# layout=Layout(root_container, focused_element=text_area),
# key_bindings=bindings,
# enable_page_navigation_bindings=True,
# mouse_support=True,
# style=style,
# full_screen=True,


def run():
container(
content,
bind=True,
focused_element=text_area,
full_screen=True,
style=style
)


if __name__ == "__main__":
run()
15 changes: 13 additions & 2 deletions examples/prompts/auto-completion/nested-autocompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@

completer = NestedCompleter.add(
{
"show": {"version": None, "clock": None, "ip": {"interface": {"brief": None}}},
"show":
{
"version": None,
"clock": None,
"ip":
{
"interface":
{
"brief": None
}
}
},
"exit": None,
}
)

session = Prompt(completer=completer)

def main():
text = session.prompt("Type a command: ") #, completer=completer)
text = session.prompt("Type a command: ", completer=completer)
print("You said: %s" % text)


Expand Down

0 comments on commit 906a7e4

Please sign in to comment.