Skip to content

Commit

Permalink
@scalabli🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
quantum-quirks committed May 8, 2022
1 parent 230b7e1 commit 0cda65b
Show file tree
Hide file tree
Showing 26 changed files with 221 additions and 155 deletions.
73 changes: 73 additions & 0 deletions examples/prompts/bottom-toolbar2.py
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()
5 changes: 5 additions & 0 deletions examples/prompts/encoding.py
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)
27 changes: 14 additions & 13 deletions examples/prompts/fancy-zsh-prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
- https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1111
"""
import datetime

from quo.console import get_app
from quo.prompt import Prompt
import quo
from quo.style import Style
from quo.text import Text

session = Prompt()

from quo.text import (
fragment_list_width,
merge_formatted_text,
to_formatted_text,
)
from quo.text.utils import fragment_list_width
from quo.text.core import merge_formatted_text, to_formatted_text

style = quo.style.Style.add(
style = Style.add(
{
"username": "#aaaaaa italic",
"path": "#ffffff bold",
Expand All @@ -34,21 +35,21 @@
)


def get_prompt() -> quo.text.Text:
def get_prompt() -> Text:
"""
Build the prompt dynamically every time its rendered.
"""
left_part = quo.text.Text(
left_part = Text(
"<left-part>"
" <username>root</username> "
" abc "
"<path>~/.oh-my-zsh/themes</path>"
"</left-part>"
)
right_part = quo.text.Text(
right_part = Text(
"<right-part> "
"<branch> master<exclamation-mark>!</exclamation-mark> </branch> "
" <env> py36 </env> "
" <env> py3.10</env> "
" <time>%s</time> "
"</right-part>"
) % (datetime.datetime.now().isoformat(),)
Expand All @@ -60,10 +61,10 @@ def get_prompt() -> quo.text.Text:
]
)

total_width = quo.console.get_app().output.get_size().columns
total_width = get_app().output.get_size().columns
padding_size = total_width - used_width

padding = quo.text.Text("<padding>%s</padding>") % (" " * padding_size,)
padding = Text("<padding>%s</padding>") % (" " * padding_size,)

return merge_formatted_text([left_part, padding, right_part, "\n", "# "])

Expand Down
2 changes: 1 addition & 1 deletion src/quo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ def print(*values, style=None, sep=" ", end="\n"):

from quo.shortcuts.utils import container

__version__ = "2022.5.1"
__version__ = "2022.5.2"
2 changes: 1 addition & 1 deletion src/quo/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from quo.console.run_in_terminal import run_in_terminal
from quo.completion.auto_suggest import AutoSuggest, Suggestion
from quo.cache.core import FastDictCache
from quo.clipboard import Data
from quo.clipboard.core import Data
from quo.completion.core import (
CompleteEvent,
Completer,
Expand Down
2 changes: 1 addition & 1 deletion src/quo/clipboard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .core import Clipboard, Data, DummyClipboard, DynamicClipboard
#from .core import Clipboard, Data, DummyClipboard, DynamicClipboard #Data DummyClipboard, Clipboard
from .momento import InMemoryClipboard

from .pyperclip import PyperClipboard
Expand Down
6 changes: 6 additions & 0 deletions src/quo/color/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
from quo.output.color import ColorDepth
from quo.style.webcolors import NAMED_COLORS
from .rgb import *

def Color(color:str = None):
#User input (default text color)
from quo.style.style import Style

return Style.add({' ':color})
27 changes: 10 additions & 17 deletions src/quo/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
from quo.i_o.termui import echo
from quo import errors
from quo.cache.core import SimpleCache
from quo.clipboard import Clipboard, InMemoryClipboard
from quo.clipboard.core import Clipboard
from quo.clipboard.momento import InMemoryClipboard
from quo.enums import EditingMode
from quo.eventloop import (
get_traceback_from_context,
Expand All @@ -71,30 +72,22 @@
)
from quo.keys.key_binding.key_processor import KeyPressEvent, KeyProcessor
from quo.keys.key_binding.vi_state import ViState
from quo.keys import Keys
from quo.layout import Container, Window, WindowAlign as WA
from quo.keys.list import Keys
from quo.layout.containers import Container, Window, WindowAlign as WA
from quo.layout.controls import BufferControl, FormattedTextControl, UIControl
from quo.layout.dummy import create_dummy_layout
from quo.layout.layout import Layout, walk
from quo.output import ColorDepth, Output
from quo.renderer import Renderer, print_formatted_text
from quo.search import SearchState
from quo.style import (
BaseStyle,
DummyStyle,
DummyStyleTransformation,
DynamicStyle,
StyleTransformation,
default_pygments_style,
default_ui_style,
merge_styles,
)
from quo.style.core import BaseStyle, DummyStyle, DynamicStyle
from quo.style.defaults import default_pygments_style, default_ui_style
from quo.style.style import merge_styles
from quo.style.transformation import DummyStyleTransformation, StyleTransformation
from quo.utils.utils import Event, in_main_thread

from .current import get_app_session, set_app
from .run_in_terminal import in_terminal, run_in_terminal
from quo.layout import Window, WindowAlign as WA

try:
import contextvars
except ImportError:
Expand Down Expand Up @@ -220,7 +213,7 @@ def __init__(
mouse_support: FilterOrBool = False,
enable_page_navigation_bindings: Optional[
FilterOrBool
] = True, # Can be None, True or False.
] = False, # Can be None, True or False.
paste_mode: FilterOrBool = False,
editing_mode: EditingMode = EditingMode.EMACS,
erase_when_done: bool = False,
Expand Down Expand Up @@ -905,7 +898,7 @@ def rule(
def bar(
self, message: Optional[str] = None, align="center", style="fg:black bg:aquamarine"
) -> "Console":
from quo.shortcuts import container
from quo.shortcuts.utils import container


return container(
Expand Down
2 changes: 1 addition & 1 deletion src/quo/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
cast,
)

from quo.clipboard import Data
from quo.clipboard.core import Data
from quo.filters.app import vi_mode
from .selection import PasteMode, SelectionState, SelectionType

Expand Down
7 changes: 3 additions & 4 deletions src/quo/input/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from .core import DummyInput
from .core import Input
#from .core import DummyInput
#from .core import Input

# from .vitals import prompt
from .defaults import create_input, create_pipe_input
#from .defaults import create_input, create_pipe_input

__all__ = [
# Base.
Expand Down
2 changes: 1 addition & 1 deletion src/quo/keys/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .list import Keys
from .key_binding.key_bindings import Bind
from quo.keys.key_binding.vi_state import InputMode
#from quo.keys.key_binding.vi_state import InputMode

KeyBinder = Bind

Expand Down
2 changes: 1 addition & 1 deletion src/quo/keys/key_binding/bindings/vi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from quo.console.current import get_app
from quo.buffer import Buffer, indent, reshape_text, unindent
from quo.clipboard import Data
from quo.clipboard.core import Data
from quo.document import Document
from quo.filters import (
Always,
Expand Down
2 changes: 1 addition & 1 deletion src/quo/keys/key_binding/vi_state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from typing import TYPE_CHECKING, Callable, Dict, Optional

from quo.clipboard import Data
from quo.clipboard.core import Data

if TYPE_CHECKING:
from .key_bindings.vi import TextObject
Expand Down
42 changes: 23 additions & 19 deletions src/quo/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@
"""
from .containers import (
AnyContainer,
# AnyContainer,
ColorColumn,
ConditionalContainer,
Container,
#Container,
DynamicContainer,
Float,
FloatContainer,
HorizontalAlign,
#HorizontalAlign,
HSplit,
ScrollOffsets,
VerticalAlign,
#ScrollOffsets,
#VerticalAlign,
VSplit,
Window,
WindowAlign,
WindowRenderInfo,
is_container,
to_container,
to_window,
#WindowAlign,
#WindowRenderInfo,
#is_container,
#to_container,
# to_window,
)

from .controls import (
Expand All @@ -74,19 +74,23 @@
UIControl,
)
from .dimension import (
AnyDimension,
# AnyDimension,
D,
Dimension,
is_dimension,
max_layout_dimensions,
sum_layout_dimensions,
to_dimension,
# is_dimension,
# max_layout_dimensions,
# sum_layout_dimensions,
# to_dimension,
)
from .layout import Layout, walk
#from .margin import (
# ConditionalMargin,
#from .layout import Layout, walk

from .margin import (
ConditionalMargin,
NumberedMargin,
ScrollbarMargin
)
# Margin,
# NumberedMargin,
# NumberedMargin,
# PromptMargin,
# ScrollbarMargin,
#)
Expand Down
2 changes: 1 addition & 1 deletion src/quo/output/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import typing as ty
from abc import ABCMeta, abstractmethod

from quo.style import Attrs
from quo.style.core import Attrs

from .color import ColorDepth

Expand Down
2 changes: 1 addition & 1 deletion src/quo/output/videoterminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)

from quo.output import Output
from quo.style import ANSI_COLOR_NAMES, Attrs
from quo.style.core import ANSI_COLOR_NAMES, Attrs
from quo.utils.utils import is_dumb_terminal

from .color import ColorDepth
Expand Down
2 changes: 1 addition & 1 deletion src/quo/output/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)

from quo.errors import NoConsoleScreenBufferError
from quo.style import ANSI_COLOR_NAMES, Attrs
from quo.style.core import ANSI_COLOR_NAMES, Attrs
from quo.utils.utils import get_width
from quo.win32_types import (
CONSOLE_SCREEN_BUFFER_INFO,
Expand Down
Loading

0 comments on commit 0cda65b

Please sign in to comment.