about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-11-19 21:42:39 +0100
committerbptato <nincsnevem662@gmail.com>2021-11-19 21:52:31 +0100
commit8bbff1f79920fa8175da7425f8f23ad08b97f79e (patch)
tree830abcc6918f8c96bce5538eff5384518876e378 /src/utils/twtstr.nim
parent42aacf6bf1a52a8ebad902d8ee5adeef57f8822a (diff)
downloadchawan-8bbff1f79920fa8175da7425f8f23ad08b97f79e.tar.gz
User stylesheets and applyStylesheets optimizations
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 6291df36..d2a06165 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -4,6 +4,10 @@ import unicode
 import tables
 import json
 import bitops
+import os
+
+when defined(posix):
+  import posix
 
 func ansiStyle*(str: string, style: Style): seq[string] =
   result &= ansiStyleCode(style)
@@ -176,6 +180,28 @@ func skipBlanks*(buf: string, at: int): int =
   while result < buf.len and buf[result].isWhitespace():
     inc result
 
+proc expandPath*(path: string): string =
+  if path.len == 0:
+    return path
+  result = path
+  var i = 0
+  if path[0] == '~':
+    if path.len == 1:
+      result = getHomeDir()
+    elif path[1] == '/':
+      result = getHomeDir() / path.substr(2)
+      inc i
+    else:
+      when defined(posix):
+        i = 1
+        var usr = ""
+        while path[i] != '/':
+          usr &= path[i]
+          inc i
+        let p = getpwnam(usr)
+        if p != nil:
+          result = $p.pw_dir / path.substr(i)
+
 template CSI*(s: varargs[string, `$`]): string =
   var r = "\e["
   var first = true