Skip to content

Commit 906a7e4

Browse files
Merge pull request #86 from scalabli/_quo
#Bug fixes
2 parents 3462df4 + 0cda65b commit 906a7e4

38 files changed

+434
-223
lines changed

docs/changes.rst

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ Changelog
77

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

10+
``Version 2022.5.2``
11+
---------------------
12+
13+
Released on 2022-05
14+
15+
**Added**
16+
^^^^^^^^^^
17+
- Added :func:`quo.color.Color`
18+
1019
``Version 2022.5.1``
1120
---------------------
1221

docs/printing_text.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ It is possible to create a list of manually with FormattedText class. This is a
180180
])
181181
print(text, fmt=True)
182182
183-
Similar to theit is also possible to use class names, and separate the styling in a style sheet.
183+
It is also possible to use class names, and separate the styling in a style sheet.
184184

185185
.. code:: python
186186

docs/prompt.rst

+23-24
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ This can be accomplished with the :func:`prompt` function, which asks for
1111
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.
1212
You can also use the :func:`quo.confirm` function, which asks for confirmation (yes/no).
1313

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

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

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

400399
.. code:: python
401400
401+
from quo.color import Color
402402
from quo.prompt import Prompt
403-
from quo.style import Style
404403
405-
style = Style.add({' ':'fg:red'}) #User input (default text)
404+
style = Color("fg:red") #User input (default text)
406405
407406
session = Prompt(style=style)
408407
@@ -415,10 +414,11 @@ Here's an example upgrade:
415414

416415
.. code:: python
417416
417+
from quo.color import Color
418418
from quo.prompt import Prompt
419-
from quo.style import Style
420419
421-
style = Style.add({' ':'fg:blue'}) # User input (default text)
420+
style = Color("fg:blue") # User input (default text)
421+
422422
session = Prompt(style=style)
423423
424424
message = [
@@ -553,37 +553,37 @@ otherwise. So, make sure to disable history search for this.
553553

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

556-
InMemoryHistory
557-
^^^^^^^^^^^^^^^^^^^^
558-
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.
556+
MemoryHistory
557+
^^^^^^^^^^^^^^^^^
558+
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.
559559

560560
.. code:: python
561561
562+
from quo.history import MemoryHistory
562563
from quo.prompt import Prompt
563-
from quo.history import InMemoryHistory
564564
565-
history = InMemoryHistory()
566-
history.append("import os")
567-
history.append('print("hello")')
568-
history.append('print("world")')
569-
history.append("import path")
565+
MemoryHistory.append("import os")
566+
MemoryHistory.append('print("hello")')
567+
MemoryHistory.append('print("world")')
568+
MemoryHistory.append("import path")
570569
571-
session = Prompt(history=history)
570+
session = Prompt(history=MemoryHistory)
572571
573572
while True:
574573
session.prompt()
575574
576575
FileHistory
577576
^^^^^^^^^^^^^^^^
578-
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`.
577+
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`.
579578
For instance:
580579

581580
.. code:: python
582581
583-
from quo.prompt import Prompt
584582
from quo.history import FileHistory
583+
from quo.prompt import Prompt
585584
586-
session = Prompt(history=FileHistory('~/.myhistory'))
585+
history = FileHistory("~/.myhistory")
586+
session = Prompt(history=history)
587587
588588
while True:
589589
session.prompt()
@@ -699,5 +699,4 @@ Line wrapping is enabled by default. This is what most people are used to and th
699699
session.prompt('What is your name: ')
700700
701701
702-
» Check out more examples `here <https://github.com/scalabli/quo
703-
/tree/master/examples/prompts/>`_
702+
» Check out more examples `here <https://github.com/scalabli/quo/tree/master/examples/prompts/>`_

examples/full-screen/exampl.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from quo import container
2+
from quo.widget import TextField
3+
4+
5+
with open("/root/git/quo/examples/full-screen/full-screen-demo.py", "rb") as f:
6+
text = f.read().decode("utf-8")
7+
8+
9+
content = TextField(text, multiline=True)
10+
11+
container(content)

examples/full-screen/pager.py

+13-23
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"""
55

66

7-
from quo.console import Console
8-
from quo.keys import Bind
7+
from quo import container
98
from quo.layout import HSplit, Window, Layout
109
from quo.layout.controls import FormattedTextControl
1110
from quo.layout.dimension import LayoutDimension as D
@@ -51,7 +50,7 @@ def get_statusbar_text():
5150
)
5251

5352

54-
root_container = HSplit(
53+
content = HSplit(
5554
[
5655
# The top toolbar.
5756
Window(
@@ -66,17 +65,6 @@ def get_statusbar_text():
6665
)
6766

6867

69-
# Key bindings.
70-
bindings = Bind()
71-
72-
73-
@bindings.add("ctrl-c")
74-
@bindings.add("q")
75-
def _(event):
76-
"Quit."
77-
event.app.exit()
78-
79-
8068
style = Style.add(
8169
{
8270
"status.position": "#aaaa00",
@@ -85,15 +73,17 @@ def _(event):
8573
}
8674
)
8775

88-
layout = Layout(root_container, focused_element=text_area)
76+
#ayout = Layout(root_container, focused_element=text_area)
8977

9078
# create application.
9179

92-
Console(
93-
layout=layout,
94-
bind=bindings,
95-
enable_page_navigation_bindings=True,
96-
mouse_support=True,
97-
style=style,
98-
# full_screen=True,
99-
).run()
80+
#onsole(
81+
# layout=layout,
82+
# bind=bindings,
83+
#enable_page_navigation_bindings=True,
84+
# mouse_support=True,
85+
# style=style,
86+
# full_screen=True,
87+
# ).run()
88+
89+
container(content, bind=True, focused_element=text_area, full_screen=True, mouse_support=True, style=style)

examples/full-screen/simple-demos/margins.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from quo import container
1010
from quo.buffer import Buffer
11-
from quo.keys import bind
1211
from quo.layout import HSplit, Layout, Window
1312
from quo.layout import BufferControl, FormattedTextControl
1413
from quo.layout.margin import NumberedMargin, ScrollbarMargin
@@ -24,7 +23,7 @@
2423
# 1. The layout
2524
content = HSplit(
2625
[
27-
Window(FormattedTextControl('Press "q" to quit.'), height=1, style="fg:red bg:yellow bold"),
26+
Window(FormattedTextControl('Press "ctrl-c" to quit.'), height=1, style="fg:red bg:yellow bold"),
2827
Window(
2928
BufferControl(buffer=buff),
3029
# Add margins.
@@ -35,13 +34,5 @@
3534
)
3635

3736

38-
# 2. Key bindings
39-
@bind.add("q")
40-
@bind.add("ctrl-c")
41-
def _(event):
42-
"Quit application."
43-
event.app.exit()
44-
45-
4637
# 3. The `Application`
4738
container(content, bind=True, full_screen=True)

examples/full-screen/split-screen.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from quo.console import Console
99
from quo.buffer import Buffer
1010
from quo.keys import Bind
11-
from quo.layout import Layout, Window, BufferControl, FormattedTextControl, VSplit, HSplit, WindowAlign
11+
from quo.layout import Layout, Window, BufferControl, FormattedTextControl, VSplit, HSplit
1212

1313
# 3. Create the buffers
1414
# ------------------
@@ -56,7 +56,7 @@ def get_titlebar_text():
5656
Window(
5757
height=1,
5858
content=FormattedTextControl(get_titlebar_text),
59-
align=WindowAlign.CENTER,
59+
align="center"
6060
),
6161
# Horizontal separator.
6262
Window(height=1, char="-", style="class:line"),

examples/pager.py

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env python
2+
"""
3+
A simple application that shows a Pager application.
4+
"""
5+
6+
from quo import container
7+
from pygments.lexers.python import PythonLexer
8+
9+
#from prompt_toolkit.application import Application
10+
from quo.layout.containers import HSplit, Window
11+
from quo.layout.controls import FormattedTextControl
12+
from quo.layout.dimension import LayoutDimension as D
13+
from quo.layout.layout import Layout
14+
from quo.highlight import PygmentsLexer
15+
from quo.style import Style
16+
from quo.widget import Label, SearchToolbar, TextArea
17+
18+
# Create one text buffer for the main content.
19+
20+
_pager_py_path = __file__
21+
22+
_file = "/root/git/quo/setup.py"
23+
with open(_file, "rb") as f:
24+
text = f.read().decode("utf-8")
25+
26+
27+
def get_statusbar_text():
28+
return [
29+
("class:status", _pager_py_path + " - "),
30+
(
31+
"class:status.position",
32+
"{}:{}".format(
33+
text_area.document.cursor_position_row + 1,
34+
text_area.document.cursor_position_col + 1,
35+
),
36+
),
37+
("class:status", " - Press "),
38+
("class:status.key", "Ctrl-C"),
39+
("class:status", " to exit, "),
40+
("class:status.key", "/"),
41+
("class:status", " for searching."),
42+
]
43+
44+
45+
search_field = SearchToolbar(
46+
text_if_not_searching=[("class:not-searching", "Press '/' to start searching.")]
47+
)
48+
49+
text_ = Window(FormattedTextControl(f"{text}"))
50+
text_area = TextArea(
51+
text,
52+
read_only=True,
53+
scrollbar=False,
54+
line_numbers=True,
55+
multiline=True,
56+
search_field=search_field,
57+
highlighter=PygmentsLexer(PythonLexer),
58+
)
59+
60+
content = HSplit(
61+
[
62+
# The top toolbar.
63+
Window(
64+
content=FormattedTextControl(get_statusbar_text),
65+
height=D.exact(1),
66+
style="class:status",
67+
),
68+
# The main content.
69+
text_area,
70+
# text_,
71+
search_field,
72+
]
73+
)
74+
75+
76+
style = Style.add(
77+
{
78+
"status": "reverse",
79+
"status.position": "#aaaa00",
80+
"status.key": "#ffaa00",
81+
"not-searching": "#888888",
82+
}
83+
)
84+
85+
86+
# create application.
87+
#application = Application(
88+
# layout=Layout(root_container, focused_element=text_area),
89+
# key_bindings=bindings,
90+
# enable_page_navigation_bindings=True,
91+
# mouse_support=True,
92+
# style=style,
93+
# full_screen=True,
94+
95+
96+
def run():
97+
container(
98+
content,
99+
bind=True,
100+
focused_element=text_area,
101+
full_screen=True,
102+
style=style
103+
)
104+
105+
106+
if __name__ == "__main__":
107+
run()

examples/prompts/auto-completion/nested-autocompletion.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@
77

88
completer = NestedCompleter.add(
99
{
10-
"show": {"version": None, "clock": None, "ip": {"interface": {"brief": None}}},
10+
"show":
11+
{
12+
"version": None,
13+
"clock": None,
14+
"ip":
15+
{
16+
"interface":
17+
{
18+
"brief": None
19+
}
20+
}
21+
},
1122
"exit": None,
1223
}
1324
)
1425

1526
session = Prompt(completer=completer)
1627

1728
def main():
18-
text = session.prompt("Type a command: ") #, completer=completer)
29+
text = session.prompt("Type a command: ", completer=completer)
1930
print("You said: %s" % text)
2031

2132

0 commit comments

Comments
 (0)