Skip to content

Instantly share code, notes, and snippets.

@Merovius
Created September 1, 2013 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Merovius/6403936 to your computer and use it in GitHub Desktop.
Save Merovius/6403936 to your computer and use it in GitHub Desktop.
From 93883b8bf4a5d50e388db0d2eb95caebe2cdd42d Mon Sep 17 00:00:00 2001
From: Axel Wagner <mail@merovius.de>
Date: Sun, 1 Sep 2013 13:42:19 +0200
Subject: [PATCH] Correctly handle long lines
---
urxvt/shellex.in | 44 ++++++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/urxvt/shellex.in b/urxvt/shellex.in
index 4fb0744..17b1303 100644
--- a/urxvt/shellex.in
+++ b/urxvt/shellex.in
@@ -3,6 +3,7 @@
use X11::Protocol;
use File::Temp qw|tempfile|;
use File::Basename qw|basename|;
+use POSIX qw|ceil|;
use strict;
# The existing Randr-modules on CPAN seem to work only barely, so instead we
@@ -213,27 +214,30 @@ sub on_add_lines {
$str =~ s/\r/\\r/g;
print "add_lines(string = \"$str\")\n";
- my $nl = ($string =~ tr/\n//);
- if ($nl > 0) {
- my $nrow = 0;
- for my $i ($self->top_row .. $self->nrow-1) {
- if ($self->ROW_l($i) > 0) {
- print "row $i is " . $self->ROW_l($i) . "\n";
- $nrow++;
- }
- }
- $nrow = $nrow > 0 ? $nrow : 1;
- print "resizing to $nrow + $nl\n";
- $nrow += $nl;
-
- # If the window is supposed to be at the bottom, we have to move the
- # window up a little bit
- my $y = $self->{y};
- if ($self->{bottom}) {
- $y -= 2+$nrow*$self->fheight;
- }
- $self->cmd_parse("\e[8;$nrow;t\e[3;$self->{x};${y}t");
+ # We find out, how many new rows are added and resize accordingly.
+ # For this, we split the string into individual lines and determine, how
+ # many rows it will take to display.
+ my @lines = split(/\n/, $string);
+ my ($y, $x) = $self->screen_cur;
+ print "splittet into " . int(@lines) . " lines\n";
+ my $nl = 0;
+ for my $line (@lines) {
+ my $w = $x + $self->strwidth($line);
+ $x = 0;
+ $nl += ceil((1.0 * $w) / $self->ncol);
+ }
+
+ my $nrow = $self->nrow;
+ print "resizing to $nrow + $nl\n";
+ $nrow += $nl;
+
+ # If the window is supposed to be at the bottom, we have to move the
+ # window up a little bit
+ my $y = $self->{y};
+ if ($self->{bottom}) {
+ $y -= 2+$nrow*$self->fheight;
}
+ $self->cmd_parse("\e[8;$nrow;t\e[3;$self->{x};${y}t");
();
}
--
1.8.4.rc3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment