diff options
Diffstat (limited to 'prompt_info')
-rw-r--r-- | prompt_info/prompt_replace.pl | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/prompt_info/prompt_replace.pl b/prompt_info/prompt_replace.pl index 90bb6f6..20fb7b1 100644 --- a/prompt_info/prompt_replace.pl +++ b/prompt_info/prompt_replace.pl @@ -39,14 +39,24 @@ init(); sub update_terminal_size { - - my $rows = qx/tput lines/; - my $cols = qx/tput cols/; - chomp $rows; - chomp $cols; - - $term_w = 0+$cols; - $term_h = 0+$rows; + my @stty_data = qx/stty -a/; + my $line = $stty_data[0]; + + # linux + # speed 38400 baud; rows 36; columns 126; line = 0; + if ($line =~ m/rows (\d+); columns (\d+);/) { + $term_h = $1; + $term_w = $2; + # osx + # speed 9600 baud; 40 rows; 235 columns; + } elsif ($line =~ m/(\d+) rows; (\d+) columns;/) { + $term_h = $1; + $term_w = $2; + } else { + # guess? + $term_h = 24; + $term_w = 80; + } print "Terminal detected as $term_w cols by $term_h rows" if DEBUG; } |