File tree Expand file tree Collapse file tree 1 file changed +31
-16
lines changed Expand file tree Collapse file tree 1 file changed +31
-16
lines changed Original file line number Diff line number Diff line change @@ -589,22 +589,7 @@ sub trim {
589
589
# Print a line of em-dash or line-drawing chars the full width of the screen
590
590
sub horizontal_rule {
591
591
my $color = $_ [0] || " " ;
592
-
593
- # Make width static so we only calculate it once
594
- state $width ;
595
- if (!$width ) {
596
- my $tput = ` tput cols 2>1` ;
597
- if (!$tput ) {
598
- print color(' orange' ) . " Warning: `tput cols` did not return numeric input" . color(' reset' ) . " \n " ;
599
- $tput = 80;
600
- }
601
-
602
- $width = $ruler_width || $tput ;
603
- }
604
-
605
- if (is_windows()) {
606
- $width --;
607
- }
592
+ my $width = get_terminal_width();
608
593
609
594
# em-dash http://www.fileformat.info/info/unicode/char/2014/index.htm
610
595
# my $dash = "\x{2014}";
@@ -879,4 +864,34 @@ sub starts_with_ansi {
879
864
}
880
865
}
881
866
867
+ sub get_terminal_width {
868
+ # Make width static so we only calculate it once
869
+ state $width ;
870
+
871
+ if ($width ) {
872
+ return $width ;
873
+ }
874
+
875
+ # If there is a ruler width in the config we use that
876
+ if ($ruler_width ) {
877
+ $width = $ruler_width ;
878
+ # Otherwise we check the terminal width using tput
879
+ } else {
880
+ my $tput = ` tput cols` ;
881
+
882
+ if ($tput ) {
883
+ $width = int ($tput );
884
+
885
+ if (is_windows()) {
886
+ $width --;
887
+ }
888
+ } else {
889
+ print color(' orange' ) . " Warning: `tput cols` did not return numeric input" . color(' reset' ) . " \n " ;
890
+ $width = 80;
891
+ }
892
+ }
893
+
894
+ return $width ;
895
+ }
896
+
882
897
# vim: tabstop=4 shiftwidth=4 noexpandtab autoindent softtabstop=4
You can’t perform that action at this time.
0 commit comments