Recently Written · git

clic

MIRROR ONLY Gopher client with pretty colours in Common Lisp

git clone https://github.com/equwal/clic

Log | Files | Refs


commit ba86c5e114249375116d7d40a5b66bc2e2baa4ce
Solene Rapenne <solene@perso.pw>
2017-11-11 22:06:08 +0000

add support for terminal size for ecl
Thanks to pjb on #ecl that wrote the ffi code

 clic.lisp | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/clic.lisp b/clic.lisp
index d7b8ad2..edfc1b7 100644
--- a/clic.lisp
+++ b/clic.lisp
@@ -9,7 +9,7 @@
 ;;;; SBCL only
 #+sbcl
 (progn
-  (load-shared-object "./extension.so")
+  (load-shared-object #p"./extension.so")
   (declaim (inline getTerminalHeight))
   (sb-alien:define-alien-routine "getTerminalHeight" unsigned-int)
   (defun c-termsize ()
@@ -18,9 +18,15 @@
 
 #+ecl
 (progn
-  "we don't do C binding with ecl"
-  (defun c-termsize()
-    40))
+  (ffi:clines "
+    #include <sys/ioctl.h>
+    #include <limits.h>
+    unsigned int getTerminalHeight()  {
+      struct winsize w; 
+      return ioctl(1,TIOCGWINSZ,&w)<0?UINT_MAX:w.ws_row;}")
+  (ffi:def-function
+      ("getTerminalHeight" c-termsize)
+      () :returning :unsigned-int))
 ;;;; END C binding
 
 ;; structure to store links