From 0027d5de3eb4fc280f871e7998867564e1e6fc60 Mon Sep 17 00:00:00 2001 From: Eliran Wong Date: Tue, 24 Oct 2023 14:54:53 +0100 Subject: [PATCH] v35.16; support less and vlc commands on Windows --- UniqueBibleAppVersion.txt | 2 +- latest_changes.txt | 3 +++ patches.txt | 10 ++++---- util/LocalCliHandler.py | 48 +++++++++++++-------------------------- util/VlcUtil.py | 19 ++++++++++++++-- 5 files changed, 42 insertions(+), 40 deletions(-) diff --git a/UniqueBibleAppVersion.txt b/UniqueBibleAppVersion.txt index 6bc5d552e8..64fa8ea7a0 100755 --- a/UniqueBibleAppVersion.txt +++ b/UniqueBibleAppVersion.txt @@ -1 +1 @@ -35.15 +35.16 diff --git a/latest_changes.txt b/latest_changes.txt index e93acdbf38..ffdebe7dce 100755 --- a/latest_changes.txt +++ b/latest_changes.txt @@ -1,3 +1,6 @@ +Changes in 35.16: +* support Windows users to use "less" & "vlc" command with terminal mode. + Changes in 35.15: * Added support wrap words in terminal mode pager is enabled. diff --git a/patches.txt b/patches.txt index 19200bad53..243221883f 100755 --- a/patches.txt +++ b/patches.txt @@ -1349,7 +1349,6 @@ (34.79, "file", "llama_index/NET_md_index/vector_store.json") (34.81, "file", "gui/SearchLauncher.py") (34.82, "file", "gui/MaterialMainWindow.py") -(34.82, "file", "util/VlcUtil.py") (34.85, "file", "db/AGBTSData.py") (34.87, "file", "util/AGBsubheadings.py") (34.88, "file", "util/RemoteHttpHandler.py") @@ -1389,7 +1388,8 @@ (35.13, "file", "util/TextCommandParser.py") (35.13, "file", "util/TextEditorUtility.py") (35.14, "file", "util/ConfigUtil.py") -(35.15, "file", "util/LocalCliHandler.py") -(35.15, "file", "patches.txt") -(35.15, "file", "UniqueBibleAppVersion.txt") -(35.15, "file", "latest_changes.txt") +(35.16, "file", "util/VlcUtil.py") +(35.16, "file", "util/LocalCliHandler.py") +(35.16, "file", "patches.txt") +(35.16, "file", "UniqueBibleAppVersion.txt") +(35.16, "file", "latest_changes.txt") diff --git a/util/LocalCliHandler.py b/util/LocalCliHandler.py index 60ef93b2e1..1d048e95a3 100644 --- a/util/LocalCliHandler.py +++ b/util/LocalCliHandler.py @@ -894,40 +894,24 @@ def displayOutputOnTerminal(self, content): html = self.fineTuneTextForWebBrowserDisplay() self.cliTool("w3m -T text/html -o confirm_qq=false", html) else: - if config.terminalEnablePager: - if config.terminalWrapWords: - content = self.getWrappedHTMLText(content) - content = TextUtil.convertHtmlTagToColorama(content) - #print(content) divider = self.divider if config.terminalEnablePager and not content in ("Command processed!", "INVALID_COMMAND_ENTERED") and not content.endswith("not supported in terminal mode.") and not content.startswith("[MESSAGE]"): - if platform.system() == "Windows": - try: - pydoc.pager(content) - except: - config.terminalEnablePager = False - self.print(divider) - self.print(content) - # When you use remote powershell and want to pipe a command on the remote windows server through a pager, piping through out-host -paging works as desired. Piping through more when running the remote command is of no use: the entire text is displayed at once. - # try: - # pydoc.pipepager(content, cmd='out-host -paging') - # except: - # try: - # pydoc.pipepager(content, cmd='more') - # except: - # config.terminalEnablePager = False - # self.print(divider) - # self.print(content) - else: - try: - # paging without colours - #pydoc.pager(content) - # paging with colours - pydoc.pipepager(content, cmd='less -R') - except: - config.terminalEnablePager = False - self.print(divider) - self.print(content) + try: + if config.terminalWrapWords: + content = self.getWrappedHTMLText(content) + pagerContent = TextUtil.convertHtmlTagToColorama(content) + pydoc.pipepager(pagerContent, cmd='less -R') if WebtopUtil.isPackageInstalled("less") else pydoc.pager(pagerContent) + # Windows users can install less command with scoop + # read: https://github.com/ScoopInstaller/Scoop + # instll scoop + # > iwr -useb get.scoop.sh | iex + # > scoop install aria2 + # instll less + # > scoop install less + except: + config.terminalEnablePager = False + self.print(divider) + self.print(content) else: if content.startswith("[MESSAGE]"): content = content[9:] diff --git a/util/VlcUtil.py b/util/VlcUtil.py index daab699d26..fddd96d07f 100644 --- a/util/VlcUtil.py +++ b/util/VlcUtil.py @@ -48,7 +48,22 @@ def playMediaFile(filePath, vlcSpeed, audioGui=False): # on Windows if not hasattr(config, "windowsVlc"): windowsVlc = r'C:\Program Files\VideoLAN\VLC\vlc.exe' - config.windowsVlc = windowsVlc if platform.system() == "Windows" and os.path.isfile(windowsVlc) else "" + + if platform.system() == "Windows": + if os.path.isfile(windowsVlc): + config.windowsVlc = windowsVlc + elif VlcUtil.isPackageInstalled("vlc"): + # Windows users can install vlc command with scoop + # read: https://github.com/ScoopInstaller/Scoop + # instll scoop + # > iwr -useb get.scoop.sh | iex + # > scoop install aria2 + # install vlc + # > scoop bucket add extras + # > scoop install vlc + config.windowsVlc = "vlc" + else: + config.windowsVlc = "" # get full path and escape double quote if isinstance(filePath, str): filePath = os.path.abspath(filePath).replace('"', '\\"') @@ -67,7 +82,7 @@ def playMediaFileVlcNoGui(filePath, vlcSpeed): command = f'''{config.macVlc} --intf rc --play-and-exit --rate {vlcSpeed} "{filePath}" &> /dev/null''' # vlc on windows elif config.windowsVlc: - command = f'''"{config.windowsVlc}" --play-and-exit --rate {vlcSpeed} "{filePath}"''' + command = f'''"{config.windowsVlc}" --intf dummy --play-and-exit --rate {vlcSpeed} "{filePath}"''' # vlc on other platforms elif VlcUtil.isPackageInstalled("cvlc"): command = f'''cvlc --play-and-exit --rate {vlcSpeed} "{filePath}" &> /dev/null'''