about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bindings/termcap.nim15
-rw-r--r--src/display/term.nim16
2 files changed, 21 insertions, 10 deletions
diff --git a/src/bindings/termcap.nim b/src/bindings/termcap.nim
index 02962a67..5a98ccc0 100644
--- a/src/bindings/termcap.nim
+++ b/src/bindings/termcap.nim
@@ -1,9 +1,20 @@
-const termlib = (func(): string =
-  let libs = ["terminfo", "mytinfo", "termlib", "termcap", "tinfo", "ncurses", "curses"]
+import os
+const termlib = (proc(): string =
+  const libs = [
+    "terminfo", "mytinfo", "termlib", "termcap", "tinfo", "ncurses", "curses"
+  ]
   for lib in libs:
     let res = staticExec("pkg-config --libs --silence-errors " & lib)
     if res != "":
       return res
+  # Apparently on some systems pkg-config will fail to locate ncurses.
+  const dirs = [
+    "/lib", "/usr/lib", "/usr/local/lib"
+  ]
+  for lib in libs:
+    for dir in dirs:
+      if fileExists(dir & "/lib" & lib & ".a"):
+        return "-l" & lib
 )()
 when termlib != "":
   {.passl: termlib.}
diff --git a/src/display/term.nim b/src/display/term.nim
index cbfa07ca..57ee2213 100644
--- a/src/display/term.nim
+++ b/src/display/term.nim
@@ -66,10 +66,6 @@ type
     orig_flags2: cint
     orig_termios: Termios
 
-func hascap(term: Terminal, c: TermcapCap): bool = term.tc.caps[c] != nil
-func cap(term: Terminal, c: TermcapCap): string = $term.tc.caps[c]
-func ccap(term: Terminal, c: TermcapCap): cstring = term.tc.caps[c]
-
 # control sequence introducer
 template CSI(s: varargs[string, `$`]): string =
   "\e[" & s.join(';')
@@ -96,6 +92,14 @@ when not termcap_found:
     CSI() & "K"
   template ED(): string =
     CSI() & "J"
+else:
+  func hascap(term: Terminal, c: TermcapCap): bool = term.tc.caps[c] != nil
+  func cap(term: Terminal, c: TermcapCap): string = $term.tc.caps[c]
+  func ccap(term: Terminal, c: TermcapCap): cstring = term.tc.caps[c]
+
+  var goutfile: File
+  proc putc(c: char): cint {.cdecl.} =
+    goutfile.write(c)
 
 template SGR*(s: varargs[string, `$`]): string =
   CSI(s) & "m"
@@ -111,10 +115,6 @@ const ANSIColorMap = [
   ColorsRGB["white"],
 ]
 
-var goutfile: File
-proc putc(c: char): cint {.cdecl.} =
-  goutfile.write(c)
-
 proc write(term: Terminal, s: string) =
   when termcap_found:
     discard tputs(cstring(s), cint(s.len), putc)