8
8
from base64 import b64decode
9
9
#import urllib.request
10
10
from ast import literal_eval
11
+ from haversine import haversine
12
+
11
13
from uniquebible .db .BiblesSqlite import Bible
12
14
from uniquebible .db .JournalSqlite import JournalSqlite
13
15
from uniquebible .db .ToolsSqlite import Book
31
33
from uniquebible .util .HBN import HBN
32
34
from uniquebible .util .terminal_text_editor import TextEditor
33
35
from uniquebible .util .terminal_system_command_prompt import SystemCommandPrompt
34
- from uniquebible .util .terminal_mode_dialogs import TerminalModeDialogs
35
- from uniquebible .util .get_path_prompt import GetPath
36
+ if not config .runMode == "stream" :
37
+ from uniquebible .util .terminal_mode_dialogs import TerminalModeDialogs
38
+ from uniquebible .util .get_path_prompt import GetPath
36
39
from uniquebible .util .PromptValidator import NumberValidator , NoAlphaValidator
37
40
from uniquebible .util .prompt_shared_key_bindings import prompt_shared_key_bindings
38
41
from uniquebible .util .prompt_multiline_shared_key_bindings import prompt_multiline_shared_key_bindings
39
42
from uniquebible .util .ConfigUtil import ConfigUtil
40
43
from uniquebible .util .exlbl import allLocations
41
- from prompt_toolkit import PromptSession , prompt , print_formatted_text , HTML
42
- from prompt_toolkit .shortcuts import clear , confirm
43
- from prompt_toolkit .filters import Condition
44
- #from prompt_toolkit.application import run_in_terminal
45
- from prompt_toolkit .key_binding import KeyBindings , merge_key_bindings
46
- from prompt_toolkit .completion import WordCompleter , NestedCompleter , ThreadedCompleter , FuzzyCompleter
47
- from prompt_toolkit .history import FileHistory
48
- from prompt_toolkit .styles import Style
49
- #from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
50
- from haversine import haversine
44
+
45
+ if not config .runMode == "stream" :
46
+ from prompt_toolkit import PromptSession , prompt , print_formatted_text , HTML
47
+ from prompt_toolkit .shortcuts import clear , confirm
48
+ from prompt_toolkit .filters import Condition
49
+ #from prompt_toolkit.application import run_in_terminal
50
+ from prompt_toolkit .key_binding import KeyBindings , merge_key_bindings
51
+ from prompt_toolkit .completion import WordCompleter , NestedCompleter , ThreadedCompleter , FuzzyCompleter
52
+ from prompt_toolkit .history import FileHistory
53
+ from prompt_toolkit .styles import Style
54
+ #from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
51
55
52
56
53
57
class LocalCliHandler :
@@ -61,12 +65,14 @@ def __init__(self, command="John 3:16"):
61
65
self .crossPlatform .setupResourceLists ()
62
66
self .html = "<ref >Unique Bible App</ref>"
63
67
self .plainText = "Unique Bible App"
64
- self .setupDialogs ()
68
+ if not config .runMode == "stream" :
69
+ self .setupDialogs ()
65
70
self .audioPlayer = None
66
71
self .command = command
67
- self .dotCommands = self .getDotCommands ()
72
+ self .dotCommands = {} if config . runMode == "stream" else self .getDotCommands ()
68
73
self .addShortcuts ()
69
- self .initPromptElements ()
74
+ if not config .runMode == "stream" :
75
+ self .initPromptElements ()
70
76
self .setOsOpenCmd ()
71
77
self .ttsLanguages = self .getTtsLanguages ()
72
78
self .ttsLanguageCodes = list (self .ttsLanguages .keys ())
@@ -85,14 +91,15 @@ def __init__(self, command="John 3:16"):
85
91
self .startupException2 = "^(_setconfig:::|\.edit|\.change|\.toggle|\.stop|\.exec|mp3:::|mp4:::|cmd:::|\.backup|\.restore|gtts:::|speak:::|download:::|read:::|readsync:::|semantic:::)"
86
92
#config.cliTtsProcess = None
87
93
config .audio_playing_file = os .path .join ("temp" , "000_audio_playing.txt" )
88
- self .getPath = GetPath (
89
- cancel_entry = config .terminal_cancel_action ,
90
- promptIndicatorColor = config .terminalPromptIndicatorColor2 ,
91
- promptEntryColor = config .terminalCommandEntryColor2 ,
92
- subHeadingColor = config .terminalHeadingTextColor ,
93
- itemColor = config .terminalResourceLinkColor ,
94
- )
95
- self .shareKeyBindings ()
94
+ if not config .runMode == "stream" :
95
+ self .getPath = GetPath (
96
+ cancel_entry = config .terminal_cancel_action ,
97
+ promptIndicatorColor = config .terminalPromptIndicatorColor2 ,
98
+ promptEntryColor = config .terminalCommandEntryColor2 ,
99
+ subHeadingColor = config .terminalHeadingTextColor ,
100
+ itemColor = config .terminalResourceLinkColor ,
101
+ )
102
+ self .shareKeyBindings ()
96
103
97
104
def setupDialogs (self ):
98
105
self .dialogs = TerminalModeDialogs (self )
@@ -357,7 +364,7 @@ def addShortcuts(self):
357
364
self .dotCommands [key ] = (f"an alias to '{ value } '" , partial (self .getContent , value ))
358
365
359
366
def getDotCommands (self ):
360
- return {
367
+ return {} if config . runMode == "stream" else {
361
368
config .terminal_cancel_action : ("cancel action in current prompt" , self .cancelAction ),
362
369
".togglecolorbrightness" : ("toggle color brightness" , self .togglecolorbrightness ),
363
370
".togglecolourbrightness" : ("an alias to '.togglecolorbrightness'" , self .togglecolorbrightness ),
@@ -629,7 +636,7 @@ def getDotCommands(self):
629
636
".portablepython" : ("build portable python" , self .buildPortablePython ),
630
637
".system" : ("system command prompt" , SystemCommandPrompt ().run ),
631
638
".sys" : ("an alias to '.system'" , SystemCommandPrompt ().run ),
632
- ".clear" : ("clear screen" , clear ),
639
+ ".clear" : ("clear screen" , self . clear_screen ),
633
640
".wordnet" : ("wordnet dictionary" , self .wordnet ),
634
641
".customize" : ("an alias to '.customise'" , self .customise ),
635
642
".mp3" : ("play mp3 files in music folder" , self .mp3 ),
@@ -646,6 +653,9 @@ def getDotCommands(self):
646
653
#".image": ("bible chat", self.generateImage),
647
654
}
648
655
656
+ def clear_screen (self ):
657
+ clear ()
658
+
649
659
def calculate (self ):
650
660
userInput = ""
651
661
self .print ("Calculate:" )
@@ -1421,7 +1431,11 @@ def showdata(self):
1421
1431
def showdownloads (self ):
1422
1432
content = ""
1423
1433
from uniquebible .util .DatafileLocation import DatafileLocation
1424
- from uniquebible .util .GithubUtil import GithubUtil
1434
+ try :
1435
+ from uniquebible .util .GithubUtil import GithubUtil
1436
+ githubutilEnabled = True
1437
+ except :
1438
+ githubutilEnabled = False
1425
1439
# ["marveldata", "marvelbible", "marvelcommentary", "GitHubBible", "GitHubCommentary", "GitHubBook", "GitHubMap", "GitHubPdf", "GitHubEpub"]
1426
1440
resources = (
1427
1441
("Marvel Datasets" , DatafileLocation .marvelData , "marveldata" ),
@@ -1435,21 +1449,22 @@ def showdownloads(self):
1435
1449
content += """[ {1} ] {0}<br>""" .format (k , config .thisTranslation ["installed" ])
1436
1450
else :
1437
1451
content += """[<ref>DOWNLOAD:::{0}:::{1}</ref> ]<br>""" .format (keyword , k )
1438
- resources = (
1439
- ("GitHub Bibles" , "GitHubBible" , GitHubRepoInfo .bibles [0 ], (config .marvelData , "bibles" ), ".bible" ),
1440
- ("GitHub Commentaries" , "GitHubCommentary" , GitHubRepoInfo .commentaries [0 ], (config .marvelData , "commentaries" ), ".commentary" ),
1441
- ("GitHub Books" , "GitHubBook" , GitHubRepoInfo .books [0 ], (config .marvelData , "books" ), ".book" ),
1442
- ("GitHub Maps" , "GitHubMap" , GitHubRepoInfo .maps [0 ], (config .marvelData , "books" ), ".book" ),
1443
- ("GitHub PDF" , "GitHubPdf" , GitHubRepoInfo .pdf [0 ], (config .marvelData , "pdf" ), ".pdf" ),
1444
- ("GitHub EPUB" , "GitHubEpub" , GitHubRepoInfo .epub [0 ], (config .marvelData , "epub" ), ".epub" ),
1445
- )
1446
- for collection , type , repo , location , extension in resources :
1447
- content += "<h2>{0}</h2>" .format (collection )
1448
- for file in GithubUtil (repo ).getRepoData ():
1449
- if os .path .isfile (os .path .join (* location , file )):
1450
- content += """[ {1} ] {0}<br>""" .format (file .replace (extension , "" ), config .thisTranslation ["installed" ])
1451
- else :
1452
- content += """[<ref>DOWNLOAD:::{1}:::{0}</ref> ]<br>""" .format (file .replace (extension , "" ), type )
1452
+ if githubutilEnabled :
1453
+ resources = (
1454
+ ("GitHub Bibles" , "GitHubBible" , GitHubRepoInfo .bibles [0 ], (config .marvelData , "bibles" ), ".bible" ),
1455
+ ("GitHub Commentaries" , "GitHubCommentary" , GitHubRepoInfo .commentaries [0 ], (config .marvelData , "commentaries" ), ".commentary" ),
1456
+ ("GitHub Books" , "GitHubBook" , GitHubRepoInfo .books [0 ], (config .marvelData , "books" ), ".book" ),
1457
+ ("GitHub Maps" , "GitHubMap" , GitHubRepoInfo .maps [0 ], (config .marvelData , "books" ), ".book" ),
1458
+ ("GitHub PDF" , "GitHubPdf" , GitHubRepoInfo .pdf [0 ], (config .marvelData , "pdf" ), ".pdf" ),
1459
+ ("GitHub EPUB" , "GitHubEpub" , GitHubRepoInfo .epub [0 ], (config .marvelData , "epub" ), ".epub" ),
1460
+ )
1461
+ for collection , kind , repo , location , extension in resources :
1462
+ content += "<h2>{0}</h2>" .format (collection )
1463
+ for file in GithubUtil (repo ).getRepoData ():
1464
+ if os .path .isfile (os .path .join (* location , file )):
1465
+ content += """[ {1} ] {0}<br>""" .format (file .replace (extension , "" ), config .thisTranslation ["installed" ])
1466
+ else :
1467
+ content += """[<ref>DOWNLOAD:::{1}:::{0}</ref> ]<br>""" .format (file .replace (extension , "" ), kind )
1453
1468
content += "<h2>Third-party Resources</h2><p>Read <ref>https://github.com/eliranwong/UniqueBible/wiki/Third-party-resources</ref> about third-party resources.</a></p>"
1454
1469
self .html = content
1455
1470
self .plainText = TextUtil .htmlToPlainText (content ).strip ()
@@ -1701,8 +1716,8 @@ def printMultilineNote(self):
1701
1716
1702
1717
def getclipboardtext (self , confirmMessage = True ):
1703
1718
try :
1704
- if config . terminalEnableTermuxAPI :
1705
- clipboardText = self . getCliOutput ("termux-clipboard-get" )
1719
+ if shutil . which ( "termux-clipboard-get" ) :
1720
+ clipboardText = subprocess . run ("termux-clipboard-get" , shell = True , capture_output = True , text = True ). stdout
1706
1721
elif ("Pyperclip" in config .enabled ):
1707
1722
import pyperclip
1708
1723
clipboardText = pyperclip .paste ()
@@ -1798,8 +1813,11 @@ def share(self, command=""):
1798
1813
pydoc .pipepager (plainText , cmd = "termux-share -a send" )
1799
1814
return ""
1800
1815
else :
1801
- import pyperclip
1802
- pyperclip .copy (weblink )
1816
+ if shutil .which ("termux-clipboard-set" ):
1817
+ pydoc .pipepager (weblink , cmd = "termux-clipboard-set" )
1818
+ else :
1819
+ import pyperclip
1820
+ pyperclip .copy (weblink )
1803
1821
self .print (f"The following link is copied to clipboard:\n " )
1804
1822
self .print (weblink )
1805
1823
self .print ("\n Open it in a web browser or share with others." )
@@ -1814,8 +1832,11 @@ def copy(self, content="", confirmMessage=True):
1814
1832
if config .terminalEnableTermuxAPI :
1815
1833
pydoc .pipepager (content , cmd = "termux-clipboard-set" )
1816
1834
else :
1817
- import pyperclip
1818
- pyperclip .copy (content )
1835
+ if shutil .which ("termux-clipboard-set" ):
1836
+ pydoc .pipepager (weblink , cmd = "termux-clipboard-set" )
1837
+ else :
1838
+ import pyperclip
1839
+ pyperclip .copy (content )
1819
1840
if confirmMessage :
1820
1841
self .print ("Content is copied to clipboard." )
1821
1842
return ""
@@ -1829,8 +1850,11 @@ def copyHtml(self, content="", confirmMessage=True):
1829
1850
if config .terminalEnableTermuxAPI :
1830
1851
pydoc .pipepager (content , cmd = "termux-clipboard-set" )
1831
1852
else :
1832
- import pyperclip
1833
- pyperclip .copy (content )
1853
+ if shutil .which ("termux-clipboard-set" ):
1854
+ pydoc .pipepager (weblink , cmd = "termux-clipboard-set" )
1855
+ else :
1856
+ import pyperclip
1857
+ pyperclip .copy (content )
1834
1858
if confirmMessage :
1835
1859
self .print ("HTML content is copied to clipboard." )
1836
1860
return ""
0 commit comments