From c2b197031e68c37455716827badbeb84f67d86cb Mon Sep 17 00:00:00 2001 From: Leonardo Mariscal Date: Sun, 23 Jun 2019 13:47:07 -0500 Subject: [PATCH] Renamed pointer to point and cleaned code --- README.md | 7 ++----- figures.nimble | 2 +- src/figures.nim | 33 ++++++++++++++++++--------------- tests/test.nim | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 1363eec..553f239 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,8 @@ Windows CMD only supports a [limited character set](http://en.wikipedia.org/wiki All checks are runned at compile time, if you need a run time solution please let me know and will consider adding support for it. -The new windows terminal fully supports Unicode symbols, unfortunately there -is no proper way to indetify it yet. A work around is currently detecting the -terminal type but it is not documented as such in the official terminal repo. - -You can force unicode symbols by defining ```forceFigures``` +The new windows terminal and integrated VsCode terminal fully support Unicode +symbol. Based from npm [figures](https://github.com/sindresorhus/figures) by sindresorhus. diff --git a/figures.nimble b/figures.nimble index c035c72..4f2de47 100644 --- a/figures.nimble +++ b/figures.nimble @@ -1,6 +1,6 @@ # Package -version = "1.0.0" +version = "1.1.0" author = "Leonardo Mariscal" description = "Unicode symbols with Windows CMD fallbacks " license = "MIT" diff --git a/src/figures.nim b/src/figures.nim index 4b227f5..f1f2858 100644 --- a/src/figures.nim +++ b/src/figures.nim @@ -4,16 +4,20 @@ ## ## `from figures import nil` -# Since the new microsoft terminal is on the horizon forceFigures exists. - when defined(windows): from os import getEnv, execShellCmd - proc isNewWindowsTerminal(): bool = + # This hack is used to display UTF-8 in the Windows command prompt. + when not defined(nochcp): + discard execShellCmd("@chcp 65001 > nul") + + proc terminalSupportUnicode(): bool = # Hopefully https://github.com/microsoft/terminal/issues/1040 comes to be. - not (getEnv("WT_SESSION") == "") + getEnv("WT_SESSION") != "" or getEnv("TERM_PROGRAM") == "vscode" +else: + proc terminalSupportUnicode(): bool = true -when not defined(windows) or defined(forceFigures) or isNewWindowsTerminal(): +when terminalSupportUnicode(): const tick* = "✔" cross* = "✖" @@ -33,7 +37,7 @@ when not defined(windows) or defined(forceFigures) or isNewWindowsTerminal(): dot* = "․" line* = "─" ellipsis* = "…" - pointer* = "❯" + point* = "❯" pointerSmall* = "›" info* = "ℹ" warning* = "⚠" @@ -72,12 +76,15 @@ when not defined(windows) or defined(forceFigures) or isNewWindowsTerminal(): spinner* = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"] # It doesn't look so good in linux/windows - when not defined(linux) and not defined(windows): - const questionMarkPrefix* = "?⃝" - const circleQuestionMark* = "?⃝" - else: + when defined(linux) or defined(windows): const questionMarkPrefix* = "?" + else: + const questionMarkPrefix* = "?⃝" + + when defined(windows): const circleQuestionMark* = "(?)" + else: + const circleQuestionMark* = "?⃝" else: const tick* = "√" @@ -99,7 +106,7 @@ else: dot* = "." line* = "─" ellipsis* = "..." - pointer* = ">" + point* = ">" pointerSmall* = "»" info* = "i" warning* = "‼" @@ -137,7 +144,3 @@ else: fiveEighths* = "5/8" sevenEighths* = "7/8" spinner* = ["-", "\\", "|", "/"] - - # This hack is used to display UTF-8 in the Windows command prompt. - when not defined(nochcp): - discard execShellCmd("@chcp 65001 > nul") diff --git a/tests/test.nim b/tests/test.nim index ce4a972..7fe2d01 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -33,7 +33,7 @@ echo "bullet " & figures.bullet echo "dot " & figures.dot echo "line " & figures.line echo "ellipsis " & figures.ellipsis -echo "pointer " & figures.pointer +echo "point " & figures.point echo "pointerSmall " & figures.pointerSmall echo "info " & figures.info echo "warning " & figures.warning