Skip to content

Commit

Permalink
v35.19; improved wrapping CJK words
Browse files Browse the repository at this point in the history
  • Loading branch information
eliranwong committed Nov 2, 2023
1 parent 60f1e78 commit 8203ef6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion UniqueBibleAppVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
35.18
35.19
3 changes: 3 additions & 0 deletions latest_changes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Changes in 35.19:
* improved wrapping Chinese, Japanese and Korean words in terminal mode

Changes in 35.18:
* fixed bible data

Expand Down
12 changes: 6 additions & 6 deletions patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,6 @@
(33.96, "file", "gui/SimpleBrowser.py")
(33.96, "file", "gui/WorkSpace.py")
(33.96, "file", "gui/YouTubePopover.py")
(33.96, "file", "startup/nonGui.py")
(33.98, "file", "gui/MenuItems.py")
(34.04, "file", "htmlResources/material/action/terminal/materialiconsoutlined/48dp/2x/outline_terminal_black_48dp.png")
(34.05, "file", "plugins/menu/Terminal.py")
Expand Down Expand Up @@ -1385,11 +1384,12 @@
(35.12, "file", "plugins/terminal/open html content with w3m.py")
(35.13, "file", "util/CrossPlatform.py")
(35.13, "file", "util/TextEditorUtility.py")
(35.14, "file", "util/ConfigUtil.py")
(35.16, "file", "util/VlcUtil.py")
(35.16, "file", "util/LocalCliHandler.py")
(35.17, "file", "util/TextUtil.py")
(35.18, "file", "util/TextCommandParser.py")
(35.18, "file", "patches.txt")
(35.18, "file", "UniqueBibleAppVersion.txt")
(35.18, "file", "latest_changes.txt")
(35.19, "file", "startup/nonGui.py")
(35.19, "file", "util/LocalCliHandler.py")
(35.19, "file", "util/ConfigUtil.py")
(35.19, "file", "patches.txt")
(35.19, "file", "UniqueBibleAppVersion.txt")
(35.19, "file", "latest_changes.txt")
2 changes: 1 addition & 1 deletion startup/nonGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def run_terminal_mode():
print(f"Running Unique Bible App {config.version} in terminal mode ...")
if ("Art" in config.enabled):
from art import text2art
print(text2art("UBA"))
print(text2art("UBA")[:-1])

checkMigration()
needUpdate = checkApplicationUpdateCli()
Expand Down
2 changes: 1 addition & 1 deletion util/ConfigUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def getCurrentVenvDir():
# Start of terminal mode setting
setConfig("terminalWrapWords", """
# Wrap words in terminal mode.""",
False)
True)
setConfig("terminalEnableTermuxAPI", """
# Option to enable use of Termux:API tools in UBA.
# Make sure you have both Termux:API app and termux-api package installed if you want to enable it.
Expand Down
47 changes: 34 additions & 13 deletions util/LocalCliHandler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import re, config, pprint, os, requests, platform, pydoc, markdown, sys, subprocess, json, shutil, webbrowser, traceback, textwrap, wcwidth
import re, config, pprint, os, requests, platform, pydoc, markdown, sys, subprocess, json, shutil, webbrowser, traceback, textwrap, wcwidth, unicodedata
import openai, threading, time
from duckduckgo_search import ddg
from functools import partial
Expand Down Expand Up @@ -158,6 +158,12 @@ def setOsOpenCmd(self):
elif platform.system() == "Windows":
config.open = config.openWindows

def is_CJK(self, text):
for char in text:
if 'CJK' in unicodedata.name(char):
return True
return False

# wrap html text at spaces
def getWrappedHTMLText(self, text, terminal_width=None):
if not " " in text:
Expand All @@ -169,20 +175,35 @@ def getWrappedHTMLText(self, text, terminal_width=None):

def addWords(words):
words = words.split(" ")
length = len(words)
for index, item in enumerate(words):
isLastItem = (length - index == 1)
itemWidth = self.getStringWidth(item)
if isLastItem:
newLineWidth = self.lineWidth + itemWidth
else:
newLineWidth = self.lineWidth + itemWidth + 1
if newLineWidth > terminal_width:
self.wrappedText += f"\n{item}" if isLastItem else f"\n{item} "
self.lineWidth = itemWidth if isLastItem else itemWidth + 1
isLastItem = (len(words) - index == 1)

if self.is_CJK(item):
for iIndex, i in enumerate(item):
isSpaceItem = (not isLastItem and (len(item) - iIndex == 1))
iWidth = self.getStringWidth(i)
if isSpaceItem:
newLineWidth = self.lineWidth + iWidth + 1
else:
newLineWidth = self.lineWidth + iWidth
if newLineWidth > terminal_width:
self.wrappedText += f"\n{i} " if isSpaceItem else f"\n{i}"
self.lineWidth = iWidth + 1 if isSpaceItem else iWidth
else:
self.wrappedText += f"{i} " if isSpaceItem else i
self.lineWidth += iWidth + 1 if isSpaceItem else iWidth
else:
self.wrappedText += item if isLastItem else f"{item} "
self.lineWidth += itemWidth if isLastItem else itemWidth + 1
itemWidth = self.getStringWidth(item)
if isLastItem:
newLineWidth = self.lineWidth + itemWidth
else:
newLineWidth = self.lineWidth + itemWidth + 1
if newLineWidth > terminal_width:
self.wrappedText += f"\n{item}" if isLastItem else f"\n{item} "
self.lineWidth = itemWidth if isLastItem else itemWidth + 1
else:
self.wrappedText += item if isLastItem else f"{item} "
self.lineWidth += itemWidth if isLastItem else itemWidth + 1

def processLine(lineText):
if re.search("<[^<>]+?>", lineText):
Expand Down

0 comments on commit 8203ef6

Please sign in to comment.