-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
230b7e1
commit 0cda65b
Showing
26 changed files
with
221 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python | ||
""" | ||
A few examples of displaying a bottom toolbar. | ||
The ``Prompt`` function takes a ``bottom_toolbar`` attribute. | ||
This can be any kind of formatted text (plain text, or HTML), or | ||
it can be a callable that takes an App and returns an of these. | ||
The bottom toolbar will always receive the style 'bottom-toolbar', and the text | ||
inside will get 'bottom-toolbar.text'. These can be used to change the default | ||
style. | ||
""" | ||
import time | ||
from quo import echo | ||
from quo.prompt import Prompt | ||
from quo.style import Style | ||
from quo.text import Text | ||
|
||
|
||
session = Prompt() | ||
|
||
def main(): | ||
# Example 1: fixed text. | ||
text = session.prompt("Say something: ", bottom_toolbar="This is quo toolbar") | ||
# echo(f"You said: {text}") | ||
|
||
# Example 2: fixed text from a callable: | ||
def get_toolbar(): | ||
return "Bottom toolbar: time=%r" % time.time() | ||
|
||
text = session.prompt("Say something: ", bottom_toolbar=get_toolbar, refresh_interval=0.5) | ||
# echo(f"You said: {text}") | ||
|
||
# Example 3: Using HTML: | ||
text = session.prompt( | ||
"Say something: ", | ||
bottom_toolbar=Text( '(html) <b>This</b> <u>is</u> a <style bg="red">toolbar</style>' | ||
), | ||
) | ||
# echo(f"You said: {text}") | ||
|
||
|
||
# Example 4: styling differently. | ||
style = Style.add( | ||
{ | ||
"bottom-toolbar": "#aaaa00 bg:#ff0000", | ||
"bottom-toolbar.text": "#aaaa44 bg:#aa4444", | ||
} | ||
) | ||
|
||
text = session.prompt("Say something: ", bottom_toolbar="This is a toolbar", style=style) | ||
print("You said: %s" % text) | ||
|
||
# Example 6: Using a list of tokens. | ||
def get_bottom_toolbar(): | ||
return [ | ||
("", " "), | ||
("bg:#ff0000 fg:#000000", "This"), | ||
("", " is a "), | ||
("bg:#ff0000 fg:#000000", "toolbar"), | ||
("", ". "), | ||
] | ||
|
||
text = session.prompt("Say something: ", bottom_toolbar=get_bottom_toolbar) | ||
print("You said: %s" % text) | ||
|
||
# Example 7: multiline fixed text. | ||
text = session.prompt("Say something: ", bottom_toolbar="This is\na multiline toolbar") | ||
print("You said: %s" % text) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from quo import prompt | ||
if __name__ == "__main__": | ||
answer = prompt("Give me some input: ") | ||
answer = answer.encode("utf-8",errors='surrogateescape').decode('utf-8') | ||
print("You said: %s" % answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.