Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

When in alternate screen mode and resized, also resize the main buffe…

…r. Use the correct default bg/fg color for the main buffer (not the current value, but what was in use at the time of the swap).
  • Loading branch information...
commit f8cc1336b2cedff9bde804d6a529edc43cc027fb 1 parent cd19b9c
@gnachman authored
Showing with 84 additions and 15 deletions.
  1. +1 −0  VT100Screen.h
  2. +83 −15 VT100Screen.m
View
1  VT100Screen.h
@@ -118,6 +118,7 @@ void StringToScreenChars(NSString *s,
// temporary buffer to store main buffer in SAVE_BUFFER/RESET_BUFFER mode
screen_char_t *temp_buffer;
+ screen_char_t temp_default_char;
// default line stuff
screen_char_t default_bg_code;
View
98 VT100Screen.m
@@ -234,6 +234,7 @@ - (screen_char_t *)_getLineAtIndex:(int)anIndex fromLine:(screen_char_t *)aLine;
- (screen_char_t*)_getDefaultLineWithWidth:(int)width;
- (int)_addLineToScrollbackImpl;
- (void)_setInitialTabStops;
+- (screen_char_t)defaultChar;
@end
@@ -941,10 +942,8 @@ - (int)_appendScreenToScrollback:(int)numLines
return numLines;
}
-- (void)restoreScreenFromScrollback
+- (void)restoreScreenFromScrollbackWithDefaultLine:(screen_char_t *)defaultLine
{
- screen_char_t* defaultLine = [self _getDefaultLineWithWidth:WIDTH];
-
// Move scrollback lines into screen
int num_lines_in_scrollback = [linebuffer numLinesWithWidth:WIDTH];
int dest_y;
@@ -1036,6 +1035,34 @@ - (void)resizeWidth:(int)new_width height:(int)new_height
[self _appendScreenToScrollback:HEIGHT];
}
+ // If we're in the alternate screen, create a temporary linebuffer and append
+ // the base screen's contents to it.
+ LineBuffer *tempLineBuffer = [[[LineBuffer alloc] init] autorelease];
+ if (temp_buffer) {
+ screen_char_t *saved_buffer_lines = buffer_lines;
+ screen_char_t *saved_screen_top = screen_top;
+ LineBuffer *saved_line_buffer = linebuffer;
+
+ linebuffer = tempLineBuffer;
+ buffer_lines = temp_buffer;
+ screen_top = temp_buffer;
+
+ int altUsedHeight = [self _usedHeight];
+ if (HEIGHT - new_height >= altUsedHeight) {
+ // Height is decreasing but pushing HEIGHT lines into the buffer would scroll all the used
+ // lines off the top, leaving the cursor floating without any text. Keep all used lines that
+ // fit onscreen.
+ [self _appendScreenToScrollback:MAX(altUsedHeight, new_height)];
+ } else {
+ // Keep last used line a fixed distance from the bottom of the screen
+ [self _appendScreenToScrollback:HEIGHT];
+ }
+
+ linebuffer = saved_line_buffer;
+ buffer_lines = saved_buffer_lines;
+ screen_top = saved_screen_top;
+ }
+
BOOL startPositionBeforeEnd = NO;
BOOL endPostionBeforeEnd = NO;
if (hasSelection) {
@@ -1099,7 +1126,34 @@ - (void)resizeWidth:(int)new_width height:(int)new_height
HEIGHT = new_height;
// Restore the screen contents that were pushed onto the linebuffer.
- [self restoreScreenFromScrollback];
+ [self restoreScreenFromScrollbackWithDefaultLine:[self _getDefaultLineWithWidth:WIDTH]];
+
+ // If we're in the alternate screen, restore its contents from the temporary
+ // linebuffer.
+ if (temp_buffer) {
+ screen_char_t *saved_buffer_lines = buffer_lines;
+ screen_char_t *saved_screen_top = screen_top;
+ LineBuffer *saved_line_buffer = linebuffer;
+
+ // Allocate a new temp_buffer of the right size.
+ screen_char_t* aDefaultLine = [self _getDefaultLineWithChar:temp_default_char];
+ free(temp_buffer);
+ temp_buffer = (screen_char_t*)calloc(REAL_WIDTH * HEIGHT, (sizeof(screen_char_t)));
+ for(i = 0; i < HEIGHT; i++) {
+ memcpy(temp_buffer+i*REAL_WIDTH, aDefaultLine, REAL_WIDTH*sizeof(screen_char_t));
+ }
+
+ linebuffer = tempLineBuffer;
+ buffer_lines = temp_buffer;
+ screen_top = temp_buffer;
+
+ [self restoreScreenFromScrollbackWithDefaultLine:aDefaultLine];
+ temp_buffer = buffer_lines;
+
+ linebuffer = saved_line_buffer;
+ buffer_lines = saved_buffer_lines;
+ screen_top = saved_screen_top;
+ }
#ifdef DEBUG_RESIZEDWIDTH
NSLog(@"After pops\n");
@@ -1130,16 +1184,6 @@ - (void)resizeWidth:(int)new_width height:(int)new_height
ALT_SAVE_CURSOR_Y = new_height-1;
}
- // if we did the resize in SAVE_BUFFER mode, too bad, get rid of it
- if (temp_buffer) {
- screen_char_t* aDefaultLine = [self _getDefaultLineWithWidth:WIDTH];
- free(temp_buffer);
- temp_buffer = (screen_char_t*)calloc(REAL_WIDTH * HEIGHT, (sizeof(screen_char_t)));
- for(i = 0; i < HEIGHT; i++) {
- memcpy(temp_buffer+i*REAL_WIDTH, aDefaultLine, REAL_WIDTH*sizeof(screen_char_t));
- }
- }
-
// The linebuffer may have grown. Ensure it doesn't have too many lines.
#ifdef DEBUG_RESIZEDWIDTH
NSLog(@"Before dropExcessLines have %d\n", [linebuffer numLinesWithWidth: WIDTH]);
@@ -1814,6 +1858,7 @@ - (void)saveBuffer
memcpy(temp_buffer, screen_top, (HEIGHT-n)*REAL_WIDTH*sizeof(screen_char_t));
memcpy(temp_buffer + (HEIGHT - n) * REAL_WIDTH, buffer_lines, n * REAL_WIDTH * sizeof(screen_char_t));
}
+ temp_default_char = [self defaultChar];
}
- (void)restoreBuffer
@@ -3415,7 +3460,7 @@ - (void)setHistory:(NSArray *)history
// We don't know the cursor position yet but give the linebuffer something
// so it doesn't get confused in restoreScreenFromScrollback.
[linebuffer setCursor:0];
- [self restoreScreenFromScrollback];
+ [self restoreScreenFromScrollbackWithDefaultLine:[self _getDefaultLineWithWidth:WIDTH]];
}
- (void)setAltScreen:(NSArray *)lines
@@ -3431,6 +3476,7 @@ - (void)setAltScreen:(NSArray *)lines
aDefaultLine,
REAL_WIDTH * sizeof(screen_char_t));
}
+ temp_default_char = [self defaultChar];
// Copy the lines back over it
for (int i = 0; i < MIN(lines.count, HEIGHT); i++) {
@@ -3856,6 +3902,18 @@ - (screen_char_t *)_getLineAtIndex:(int)anIndex fromLine:(screen_char_t *)aLine
return the_line;
}
+- (screen_char_t *)_getDefaultLineWithChar:(screen_char_t)defaultChar {
+ NSMutableData *data = [NSMutableData data];
+ for (int i = 0; i < WIDTH; i++) {
+ [data appendBytes:&defaultChar length:sizeof(defaultChar)];
+ }
+ screen_char_t eol;
+ memset(&eol, 0, sizeof(eol));
+ eol.code = EOL_HARD;
+ [data appendBytes:&eol length:sizeof(eol)];
+ return data.bytes;
+}
+
// returns a line set to default character and attributes
// released when session is closed
- (screen_char_t*)_getDefaultLineWithWidth:(int)width
@@ -3922,6 +3980,16 @@ - (int)_addLineToScrollbackImpl
return dropped;
}
+- (screen_char_t)defaultChar {
+ screen_char_t fg = [TERMINAL foregroundColorCodeReal];
+ screen_char_t bg = [TERMINAL backgroundColorCodeReal];
+ screen_char_t c;
+ memset(&c, 0, sizeof(c));
+ CopyForegroundColor(&c, fg);
+ CopyBackgroundColor(&c, bg);
+ return c;
+}
+
- (void)_setInitialTabStops
{
[self clearTabStop];
Please sign in to comment.
Something went wrong with that request. Please try again.