mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Display banner and pretty terminal output in GUI mode too
This commit is contained in:
parent
38ea24393a
commit
429d1e3f08
7 changed files with 211 additions and 189 deletions
|
@ -1,8 +1,5 @@
|
|||
import os
|
||||
import sys
|
||||
import colorama
|
||||
|
||||
colorama.init(autoreset=True)
|
||||
|
||||
# Depending on the filename, decide if we want to run:
|
||||
# dangerzone, dangerzone-cli, or dangerzone-container
|
||||
|
|
|
@ -1,187 +1,10 @@
|
|||
import os
|
||||
import shutil
|
||||
import click
|
||||
import colorama
|
||||
from colorama import Fore, Back, Style
|
||||
|
||||
from .global_common import GlobalCommon
|
||||
from .common import Common
|
||||
from dangerzone import global_common
|
||||
|
||||
|
||||
def display_banner(global_common):
|
||||
"""
|
||||
Raw ASCII art example:
|
||||
╭──────────────────────────╮
|
||||
│ ▄██▄ │
|
||||
│ ██████ │
|
||||
│ ███▀▀▀██ │
|
||||
│ ███ ████ │
|
||||
│ ███ ██████ │
|
||||
│ ███ ▀▀▀▀████ │
|
||||
│ ███████ ▄██████ │
|
||||
│ ███████ ▄█████████ │
|
||||
│ ████████████████████ │
|
||||
│ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ │
|
||||
│ │
|
||||
│ Dangerzone v0.1.5 │
|
||||
│ https://dangerzone.rocks │
|
||||
╰──────────────────────────╯
|
||||
"""
|
||||
print(Back.BLACK + Fore.YELLOW + Style.DIM + "╭──────────────────────────╮")
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ▄██▄ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ██████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███▀▀▀██ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███ ████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███ ██████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███ ▀▀▀▀████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███████ ▄██████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███████ ▄█████████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ████████████████████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(Back.BLACK + Fore.YELLOW + Style.DIM + "│ │")
|
||||
left_spaces = (15 - len(global_common.version) - 1) // 2
|
||||
right_spaces = left_spaces
|
||||
if left_spaces + len(global_common.version) + 1 + right_spaces < 15:
|
||||
right_spaces += 1
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Style.RESET_ALL
|
||||
+ Back.BLACK
|
||||
+ Fore.LIGHTWHITE_EX
|
||||
+ Style.BRIGHT
|
||||
+ f"{' '*left_spaces}Dangerzone v{global_common.version}{' '*right_spaces}"
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Style.RESET_ALL
|
||||
+ Back.BLACK
|
||||
+ Fore.LIGHTWHITE_EX
|
||||
+ " https://dangerzone.rocks "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(Back.BLACK + Fore.YELLOW + Style.DIM + "╰──────────────────────────╯")
|
||||
|
||||
|
||||
def print_header(s):
|
||||
|
@ -233,7 +56,7 @@ def cli_main(custom_container, safe_pdf_filename, ocr_lang, skip_update, filenam
|
|||
global_common = GlobalCommon()
|
||||
common = Common()
|
||||
|
||||
display_banner(global_common)
|
||||
global_common.display_banner()
|
||||
|
||||
# Validate filename
|
||||
valid = True
|
||||
|
|
|
@ -26,6 +26,7 @@ def exec_container(args):
|
|||
|
||||
args_str = " ".join(pipes.quote(s) for s in args)
|
||||
print("\u2023 " + args_str) # ‣
|
||||
sys.stdout.flush()
|
||||
|
||||
with subprocess.Popen(
|
||||
args,
|
||||
|
|
|
@ -5,7 +5,8 @@ import appdirs
|
|||
import platform
|
||||
import subprocess
|
||||
import pipes
|
||||
from colorama import Fore, Style
|
||||
import colorama
|
||||
from colorama import Fore, Back, Style
|
||||
|
||||
from .settings import Settings
|
||||
|
||||
|
@ -20,6 +21,9 @@ class GlobalCommon(object):
|
|||
with open(self.get_resource_path("version.txt")) as f:
|
||||
self.version = f.read().strip()
|
||||
|
||||
# Initialize terminal colors
|
||||
colorama.init(autoreset=True)
|
||||
|
||||
# App data folder
|
||||
self.appdata_path = appdirs.user_config_dir("dangerzone")
|
||||
|
||||
|
@ -196,6 +200,181 @@ class GlobalCommon(object):
|
|||
# Load settings
|
||||
self.settings = Settings(self)
|
||||
|
||||
def display_banner(self):
|
||||
"""
|
||||
Raw ASCII art example:
|
||||
╭──────────────────────────╮
|
||||
│ ▄██▄ │
|
||||
│ ██████ │
|
||||
│ ███▀▀▀██ │
|
||||
│ ███ ████ │
|
||||
│ ███ ██████ │
|
||||
│ ███ ▀▀▀▀████ │
|
||||
│ ███████ ▄██████ │
|
||||
│ ███████ ▄█████████ │
|
||||
│ ████████████████████ │
|
||||
│ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ │
|
||||
│ │
|
||||
│ Dangerzone v0.1.5 │
|
||||
│ https://dangerzone.rocks │
|
||||
╰──────────────────────────╯
|
||||
"""
|
||||
|
||||
print(Back.BLACK + Fore.YELLOW + Style.DIM + "╭──────────────────────────╮")
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ▄██▄ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ██████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███▀▀▀██ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███ ████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███ ██████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███ ▀▀▀▀████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███████ ▄██████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ███████ ▄█████████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ████████████████████ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Fore.LIGHTYELLOW_EX
|
||||
+ Style.NORMAL
|
||||
+ " ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(Back.BLACK + Fore.YELLOW + Style.DIM + "│ │")
|
||||
left_spaces = (15 - len(self.version) - 1) // 2
|
||||
right_spaces = left_spaces
|
||||
if left_spaces + len(self.version) + 1 + right_spaces < 15:
|
||||
right_spaces += 1
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Style.RESET_ALL
|
||||
+ Back.BLACK
|
||||
+ Fore.LIGHTWHITE_EX
|
||||
+ Style.BRIGHT
|
||||
+ f"{' '*left_spaces}Dangerzone v{self.version}{' '*right_spaces}"
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(
|
||||
Back.BLACK
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
+ Style.RESET_ALL
|
||||
+ Back.BLACK
|
||||
+ Fore.LIGHTWHITE_EX
|
||||
+ " https://dangerzone.rocks "
|
||||
+ Fore.YELLOW
|
||||
+ Style.DIM
|
||||
+ "│"
|
||||
)
|
||||
print(Back.BLACK + Fore.YELLOW + Style.DIM + "╰──────────────────────────╯")
|
||||
|
||||
def get_container_name(self):
|
||||
if self.custom_container:
|
||||
return self.custom_container
|
||||
|
|
|
@ -60,6 +60,8 @@ def gui_main(custom_container, filename):
|
|||
global_common = GlobalCommon()
|
||||
gui_common = GuiCommon(app, global_common)
|
||||
|
||||
global_common.display_banner()
|
||||
|
||||
if custom_container:
|
||||
success, error_message = global_common.container_exists(custom_container)
|
||||
if not success:
|
||||
|
|
|
@ -2,7 +2,9 @@ import os
|
|||
import platform
|
||||
import subprocess
|
||||
import shlex
|
||||
import pipes
|
||||
from PySide2 import QtCore, QtGui, QtWidgets
|
||||
from colorama import Fore
|
||||
|
||||
if platform.system() == "Darwin":
|
||||
import CoreServices
|
||||
|
@ -47,16 +49,21 @@ class GuiCommon(object):
|
|||
if self.global_common.settings.get("open_app") in self.pdf_viewers:
|
||||
if platform.system() == "Darwin":
|
||||
# Get the PDF reader bundle command
|
||||
bundle_identifier = self.pdf_viewers[self.global_common.settings.get("open_app")]
|
||||
bundle_identifier = self.pdf_viewers[
|
||||
self.global_common.settings.get("open_app")
|
||||
]
|
||||
args = ["open", "-b", bundle_identifier, filename]
|
||||
|
||||
# Run
|
||||
print(f"Executing: {' '.join(args)}")
|
||||
args_str = " ".join(pipes.quote(s) for s in args)
|
||||
print(Fore.YELLOW + "\u2023 " + Fore.CYAN + args_str) # ‣
|
||||
subprocess.run(args)
|
||||
|
||||
elif platform.system() == "Linux":
|
||||
# Get the PDF reader command
|
||||
args = shlex.split(self.pdf_viewers[self.global_common.settings.get("open_app")])
|
||||
args = shlex.split(
|
||||
self.pdf_viewers[self.global_common.settings.get("open_app")]
|
||||
)
|
||||
# %f, %F, %u, and %U are filenames or URLS -- so replace with the file to open
|
||||
for i in range(len(args)):
|
||||
if (
|
||||
|
@ -68,7 +75,8 @@ class GuiCommon(object):
|
|||
args[i] = filename
|
||||
|
||||
# Open as a background process
|
||||
print(f"Executing: {' '.join(args)}")
|
||||
args_str = " ".join(pipes.quote(s) for s in args)
|
||||
print(Fore.YELLOW + "\u2023 " + Fore.CYAN + args_str) # ‣
|
||||
subprocess.Popen(args)
|
||||
|
||||
def _find_pdf_viewers(self):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from PySide2 import QtCore, QtWidgets, QtGui
|
||||
from colorama import Style
|
||||
from colorama import Style, Fore
|
||||
|
||||
|
||||
class TaskBase(QtCore.QThread):
|
||||
|
@ -18,11 +18,23 @@ class TaskBase(QtCore.QThread):
|
|||
with self.global_common.exec_dangerzone_container(args) as p:
|
||||
for line in p.stdout:
|
||||
output += line.decode()
|
||||
print(line.decode(), end="")
|
||||
|
||||
if line.startswith(b"\xe2\x80\xa3 "):
|
||||
print(
|
||||
Fore.WHITE + "\u2023 " + Fore.LIGHTCYAN_EX + line.decode()[2:],
|
||||
end="",
|
||||
)
|
||||
else:
|
||||
print(" " + line.decode(), end="")
|
||||
|
||||
self.update_details.emit(output)
|
||||
|
||||
stderr = p.stderr.read().decode()
|
||||
print(Style.DIM + stderr + Style.RESET_ALL)
|
||||
if len(stderr) > 0:
|
||||
print("")
|
||||
for line in stderr.strip().split("\n"):
|
||||
print(" " + Style.DIM + line)
|
||||
|
||||
self.update_details.emit(output)
|
||||
|
||||
if p.returncode == 126 or p.returncode == 127:
|
||||
|
|
Loading…
Reference in a new issue