Skip to content

Commit

Permalink
release: version 1.0.0 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Jan 21, 2024
1 parent c9c761d commit bd740df
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 61 deletions.
13 changes: 0 additions & 13 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,13 +0,0 @@
Changelog
=========


0.1.2 (2021-08-14)
------------------
- Fix release, README and windows CI. [Bruno Rocha]
- Release: version 0.1.0. [Bruno Rocha]


0.1.0 (2021-08-14)
------------------
- Add release command. [Bruno Rocha]
62 changes: 62 additions & 0 deletions cli_progress/ANSIWidget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python

from __future__ import annotations
from typing import Tuple, List, Optional, Any, Iterable
import urwid
import re

class ANSICanvas(urwid.canvas.Canvas):
def __init__(self, size: Tuple[int, int], text_lines: List[str]) -> None:
super().__init__()

self.maxcols, self.maxrows = size

self.text_lines = text_lines

def cols(self) -> int:
return self.maxcols

def rows(self) -> int:
return self.maxrows

def content(
self,
trim_left: int = 0,
trim_top: int = 0,
cols: Optional[int] = None,
rows: Optional[int] = None,
attr_map: Optional[Any] = None,
) -> Iterable[List[Tuple[None, str, bytes]]]:
assert cols is not None
assert rows is not None

for i in range(rows):
if i < len(self.text_lines):
text = self.text_lines[i]
else:
text = b""

padding = bytes().rjust(max(0, cols - len(escape_ansi(text))))
line = [(None, "U", text.encode("utf-8") + padding)]

yield line


class ANSIWidget(urwid.Widget):
_sizing = frozenset([urwid.widget.BOX])

def __init__(self, text: str = "") -> None:
self.lines = text.split("\n")

def set_content(self, lines: List[str]) -> None:
self.lines = lines
self._invalidate()

def render(self, size: Tuple[int, int], focus: bool = False) -> urwid.canvas.Canvas:
canvas = ANSICanvas(size, self.lines)

return canvas

def escape_ansi(line):
ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]')
return ansi_escape.sub('', line)
32 changes: 32 additions & 0 deletions cli_progress/BackgroundWidget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import urwid
class BackgroundView(urwid.WidgetWrap):
def __init__(self,forground,header,footer):
self.forground=forground
self.header_widget=header
self.footer_widget=footer
super().__init__(self.main_window())

def main_shadow(self, w):
"""Wrap a shadow and background around widget w."""
bg = urwid.AttrMap(urwid.SolidFill("\u2592"), "screen edge")
shadow = urwid.AttrMap(urwid.SolidFill(" "), "main shadow")

bg = urwid.Overlay(shadow, bg, ("fixed left", 2), ("fixed right", 1), ("fixed top", 2), ("fixed bottom", 1))
w = urwid.Overlay(w, bg, ("fixed left", 1), ("fixed right", 2), ("fixed top", 1), ("fixed bottom", 2))
# bg = urwid.Overlay(shadow, bg, ("fixed left", 0), ("fixed right", 0), ("fixed top", 0), ("fixed bottom", 0))
# w = urwid.Overlay(w, bg, ("fixed left", 0), ("fixed right", 0), ("fixed top", 0), ("fixed bottom", 0))
return w
def main_window(self):

self.forground_wrap = urwid.WidgetWrap(self.forground)
vline = urwid.AttrMap(urwid.SolidFill("\u2502"), "line")

w = urwid.Padding(self.forground_wrap, ("fixed left", 1), ("fixed right", 0))
w = urwid.AttrMap(w, "body")
w = urwid.LineBox(w)
w = urwid.AttrMap(w, "line")
w = self.main_shadow(w)
return urwid.Frame(
body=w, header=self.header_widget,footer=self.footer_widget
)

24 changes: 24 additions & 0 deletions cli_progress/LogListWidget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import urwid
from .ANSIWidget import ANSIWidget


class LogListBox(urwid.ListBox):
def __init__(self):
body = urwid.SimpleFocusListWalker([get_line("")])
super().__init__(body)

def add_log_line(self, data, err, replace=False):
txt = f"\033[91m{data}\033[0m" if err else data
if replace:
self.body[-1].set_content(txt)
else:
self.body.append(get_line(txt))
if self.is_focus_end():
self.focus_position = len(self.body) - 1

def is_focus_end(self):
return self.focus_position >= len(self.body) - 2


def get_line(text):
return urwid.BoxAdapter(ANSIWidget(text), 1)
2 changes: 1 addition & 1 deletion cli_progress/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
1.0.0
40 changes: 38 additions & 2 deletions cli_progress/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
"""Entry point for cli_progress."""

from cli_progress.cli import main # pragma: no cover

if __name__ == "__main__": # pragma: no cover
import argparse
from .progress_ui import ProgressUI

def parse_arguments():
parser = argparse.ArgumentParser(description="Process log file with a command")

# Add a title to the command-line arguments
title_group = parser.add_argument_group("Arguments")
title_group.add_argument("--log", help="Path to the log file", required=False)
title_group.add_argument(
"--title", default="Title", help="Title for the script", required=False
)
title_group.add_argument(
"--subtitle",
default="SubTitle",
help="SubTitle for the script. e.x. version",
required=False,
)
title_group.add_argument(
"--regex",
default=r"####(?P<progress>\d+)####(?P<title>.*?)####(?P<subtitle>.*?)####",
help="Regex for capturing the progress",
required=False,
)
title_group.add_argument("command", nargs="+", help="Command and its arguments")

return parser.parse_args()


def main():
args = parse_arguments()


ui = ProgressUI(args.log, args.command, args.title, args.subtitle, args.regex)
ui.start()


if __name__ == "__main__":
main()
17 changes: 0 additions & 17 deletions cli_progress/base.py

This file was deleted.

28 changes: 0 additions & 28 deletions cli_progress/cli.py

This file was deleted.

Loading

0 comments on commit bd740df

Please sign in to comment.