]> gitweb.factorcode.org Git - factor.git/blob - extra/terminal/terminal.factor
sequences.suffixed: adding a virtual suffixed sequence
[factor.git] / extra / terminal / terminal.factor
1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: accessors arrays environment kernel math math.parser
5 sequences system vocabs ;
6
7 IN: terminal
8
9 HOOK: (terminal-size) os ( -- columns lines )
10
11 "terminal." os name>> append require
12
13 : terminal-size ( -- dim )
14     "COLUMNS" "LINES"
15     [ os-env [ string>number ] [ 0 ] if* ] bi@
16     2dup [ 0 <= ] either? [
17         (terminal-size)
18         [ over 0 <= [ nip ] [ drop ] if ] bi-curry@ bi*
19     ] when 2array ;
20
21 : terminal-width ( -- width ) terminal-size first ;
22
23 : terimal-height ( -- height ) terminal-size second ;