With some pointers from 
Colin, https://github.com/trptcolin/reply/issues/75, I was able to find a 
workable solution using stty:

user=> (->> (clojure.java.shell/sh "/bin/sh" "-c" "stty -a < /dev/tty") 
:out (re-find #"(\d+) columns") second)
"238"

As for the $COLUMNS dilemma, it seems that's a java-specific issue - 
http://stackoverflow.com/a/1286677/83510.
I'm curious why `tput cols` doesn't work but that's for another day.


On Monday, July 23, 2012 12:01:17 PM UTC-4, Gabriel Horner wrote:
>
> Hi,
>
> For a clojar I'm writing <http://github.com/cldwalker/table>, I'd like to 
> know a user's terminal width so I can resize output appropriately. All the 
> following techniques, which work fine in a ruby repl, don't work in 
> leiningen2:
>
> $ lein repl
> user=> (System/getenv "COLUMNS")
> nil
>
> user=> (clojure.java.shell/sh "tput" "cols")
> {:exit 0, :out "80\n", :err ""}
> ; This is incorrect as my terminal width is 238
>
> user=> (clojure.java.shell/sh "stty" "size")
> {:exit 1, :out "", :err "stty: stdin isn't a terminal\n"}
>
> The only thing that does work is if I `export COLUMNS`, something I don't 
> have to do for a ruby repl. Thoughts on why none of these approaches work 
> and what a correct one would be?
>
> Thanks,
> Gabriel
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to