From 327031f1a2b67011df2a75b8765b5011218df19a Mon Sep 17 00:00:00 2001 From: Carlos Cabanero Date: Tue, 13 Sep 2016 10:55:09 -0400 Subject: [PATCH] Fixes Test Terminal not showing changes - When changing Themes in the Appearance section, the Test Terminal was not showing all changes properly. This is because the already rendered sections do not redraw. Solved by clearing the terminal, and redrawing the test with new configuration. - Another source of problems was reusing the rows for the WKWebView, and not referring the proper Terminal. - Also made changes to change the font size according to the last changes after resets. --- Blink/TermController.m | 4 +- Blink/TermView.h | 3 +- Blink/TermView.m | 11 ++- Resources/termcontrol.js | 14 ++-- Settings/Base.lproj/Settings.storyboard | 2 +- .../Appearance/BKAppearanceViewController.m | 70 +++++++++++-------- 6 files changed, 63 insertions(+), 41 deletions(-) diff --git a/Blink/TermController.m b/Blink/TermController.m index 86331a4ef..4410f7451 100644 --- a/Blink/TermController.m +++ b/Blink/TermController.m @@ -244,10 +244,10 @@ - (void)updateTermRows:(NSNumber *)rows Cols:(NSNumber *)cols [_session sigwinch]; } -- (void)fontSizeChanged:(NSNumber *)size +- (void)fontSizeChanged:(NSNumber *)newSize { // Ignore the font size settings in case it was manually changed - if (size != [BKDefaults selectedFontSize]) { + if (!([newSize isEqualToNumber:[BKDefaults selectedFontSize]])) { _disableFontSizeSelection = YES; } } diff --git a/Blink/TermView.h b/Blink/TermView.h index 791ecadb7..9a39a7da4 100644 --- a/Blink/TermView.h +++ b/Blink/TermView.h @@ -58,8 +58,9 @@ extern NSString * const TermViewFFuncSeq; - (void)setScrollEnabled:(BOOL)scroll; - (void)setRawMode:(BOOL)raw; - (BOOL)rawMode; +- (void)clear; - (void)setColumnNumber:(NSInteger)count; -- (void)setFontSize:(NSNumber *)size; +- (void)setFontSize:(NSNumber *)newSize; - (void)setInputEnabled:(BOOL)enabled; - (void)loadTerminal; - (void)write:(NSString *)data; diff --git a/Blink/TermView.m b/Blink/TermView.m index eb6f124dd..8f0ae135c 100644 --- a/Blink/TermView.m +++ b/Blink/TermView.m @@ -295,12 +295,17 @@ - (void)setInputEnabled:(BOOL)enabled - (void)setColumnNumber:(NSInteger)count { - [_webView evaluateJavaScript:[NSString stringWithFormat:@"setWidth(\"%d\");", count] completionHandler:nil]; + [_webView evaluateJavaScript:[NSString stringWithFormat:@"setWidth(\"%ld\");", (long)count] completionHandler:nil]; } -- (void)setFontSize:(NSNumber *)size +- (void)setFontSize:(NSNumber *)newSize { - [_webView evaluateJavaScript:[NSString stringWithFormat:@"setFontSize(\"%@\");", size] completionHandler:nil]; + [_webView evaluateJavaScript:[NSString stringWithFormat:@"setFontSize(\"%@\");", newSize] completionHandler:nil]; +} + +- (void)clear +{ + [_webView evaluateJavaScript:[NSString stringWithFormat:@"clear();"] completionHandler:nil]; } - (void)loadTerminal diff --git a/Resources/termcontrol.js b/Resources/termcontrol.js index 7b88cb009..8efbf5e28 100644 --- a/Resources/termcontrol.js +++ b/Resources/termcontrol.js @@ -24,14 +24,14 @@ window.addEventListener('resize', sigwinch); var increaseTermFontSize = function() { var size = t.getFontSize(); - t.setFontSize(++size); + setFontSize(++size); } var decreaseTermFontSize = function() { var size = t.getFontSize(); - t.setFontSize(--size); + setFontSize(--size); } var resetTermFontSize = function() { - t.setFontSize(0); + setFontSize(0); } var scaleTermStart = function() { @@ -40,11 +40,11 @@ var scaleTermStart = function() { var scaleTerm = function(scale) { if (scale > 2.0) scale = 2.0; if (scale < 0.5) scale = 0.5; - t.setFontSize(Math.floor(this.fontSize * scale)); - window.webkit.messageHandlers.interOp.postMessage({"op": "fontSizeChanged", "data": {size: t.getFontSize()}}); + setFontSize(Math.floor(this.fontSize * scale)); } var setFontSize = function(size) { t.setFontSize(size); + window.webkit.messageHandlers.interOp.postMessage({"op": "fontSizeChanged", "data": {size: t.getFontSize()}}); } var focusTerm = function() { @@ -69,3 +69,7 @@ var loadFontFromCSS = function(cssPath, name) { }); t.prefs_.set('font-family', name); } + +var clear = function() { + t.clear(); +} diff --git a/Settings/Base.lproj/Settings.storyboard b/Settings/Base.lproj/Settings.storyboard index e359eb4a3..32352a9c1 100755 --- a/Settings/Base.lproj/Settings.storyboard +++ b/Settings/Base.lproj/Settings.storyboard @@ -1283,7 +1283,7 @@ - + diff --git a/Settings/ViewControllers/Appearance/BKAppearanceViewController.m b/Settings/ViewControllers/Appearance/BKAppearanceViewController.m index ce29682fc..3289ab5c4 100644 --- a/Settings/ViewControllers/Appearance/BKAppearanceViewController.m +++ b/Settings/ViewControllers/Appearance/BKAppearanceViewController.m @@ -57,7 +57,7 @@ @interface BKAppearanceViewController () @property (nonatomic, strong) NSIndexPath *selectedThemeIndexPath; @property (weak, nonatomic) UITextField *fontSizeField; @property (weak, nonatomic) UIStepper *fontSizeStepper; -@property (nonatomic, strong) TerminalView *testTerminal; +@property (weak, nonatomic) TerminalView *testTerminal; @end @@ -164,14 +164,15 @@ - (void)setThemesUIForCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)in - (void)attachTestTerminalToView:(UIView *)view { - _testTerminal = [[TerminalView alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)]; - _testTerminal.delegate = self; - _testTerminal.backgroundColor = [UIColor blackColor]; - [_testTerminal setInputEnabled:NO]; - if (!view.subviews.count) { + _testTerminal = [[TerminalView alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)]; [view addSubview:_testTerminal]; + } else { + _testTerminal = view.subviews[0]; } + _testTerminal.delegate = self; + _testTerminal.backgroundColor = [UIColor blackColor]; + [_testTerminal setInputEnabled:NO]; [_testTerminal loadTerminal]; } @@ -228,10 +229,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N _fontSizeField = [cell viewWithTag:FONT_SIZE_FIELD_TAG]; _fontSizeStepper = [cell viewWithTag:FONT_SIZE_STEPPER_TAG]; if ([BKDefaults selectedFontSize] != nil) { - _fontSizeStepper.value = [BKDefaults selectedFontSize].integerValue; + [_fontSizeStepper setValue:[BKDefaults selectedFontSize].integerValue]; _fontSizeField.text = [NSString stringWithFormat:@"%@ px", [BKDefaults selectedFontSize]]; } else { - _fontSizeField.placeholder = @"10 px"; + _fontSizeField.placeholder = @""; } return cell; } @@ -251,8 +252,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath _selectedThemeIndexPath = indexPath; [tableView deselectRowAtIndexPath:indexPath animated:YES]; [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark]; - - [self showcaseTheme:[[BKTheme all] objectAtIndex:_selectedThemeIndexPath.row]]; + BKTheme *theme = [[BKTheme all] objectAtIndex:_selectedThemeIndexPath.row]; + [BKDefaults setThemeName:[theme name]]; + [self showcaseTheme:theme]; // } } else if (indexPath.section == BKAppearance_Fonts) { // if (indexPath.row == [[BKFont all] count]) { @@ -265,7 +267,10 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath _selectedFontIndexPath = indexPath; [tableView deselectRowAtIndexPath:indexPath animated:YES]; [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark]; - [self showcaseFont:[[BKFont all] objectAtIndex:_selectedFontIndexPath.row]]; + BKFont *font = [[BKFont all] objectAtIndex:_selectedFontIndexPath.row]; + [BKDefaults setFontName:[font name]]; + [self showcaseFont:font]; + // } } } @@ -328,10 +333,9 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd } } -- (IBAction)stepperButtonPressed:(id)sender +- (IBAction)stepperValueChanged:(id)sender { NSNumber *newSize = [NSNumber numberWithInteger:(int)[_fontSizeStepper value]]; - _fontSizeField.text = [NSString stringWithFormat:@"%@ px", newSize]; [_testTerminal setFontSize:newSize]; } @@ -362,8 +366,24 @@ - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *) - (void)terminalIsReady { + NSLog(@"reset"); [_testTerminal setColumnNumber:60]; -// Write content + BKTheme *selectedTheme = [BKTheme withName:[BKDefaults selectedThemeName]]; + if (selectedTheme) { + [self showcaseTheme:selectedTheme]; + } + + BKFont *selectedFont = [BKFont withName:[BKDefaults selectedFontName]]; + if (selectedFont) { + [self showcaseFont:selectedFont]; + } + + [_testTerminal setFontSize:[BKDefaults selectedFontSize]]; +} + +- (void)writeColorShowcase +{ + // Write content NSMutableArray *lines = [[NSMutableArray alloc] init]; NSArray *fgs = @[@" m",@" 1m",@" 30m",@"1;30m",@" 31m",@"1;31m",@" 32m",@"1;32m",@" 33m",@"1;33m",@" 34m",@"1;34m",@" 35m",@"1;35m",@" 36m",@"1;36m",@" 37m",@"1;37m"]; NSArray *bgs = @[@"40m",@"41m",@"42m",@"43m",@"44m",@"45m",@"46m",@"47m"]; @@ -376,24 +396,13 @@ - (void)terminalIsReady } NSString *showcase = [lines componentsJoinedByString:@"\r\n"]; [_testTerminal write:showcase]; - - BKTheme *selectedTheme = [BKTheme withName:[BKDefaults selectedThemeName]]; - if (selectedTheme) { - [self showcaseTheme:selectedTheme]; - } - - BKFont *selectedFont = [BKFont withName:[BKDefaults selectedFontName]]; - if (selectedFont) { - [self showcaseFont:selectedFont]; - } - - [_testTerminal setFontSize:[BKDefaults selectedFontSize]]; } -- (void)fontSizeChanged:(NSNumber *)size +- (void)fontSizeChanged:(NSNumber *)newSize { - _fontSizeStepper.value = size.integerValue; - _fontSizeField.text = [NSString stringWithFormat:@"%@ px", size]; + [BKDefaults setFontSize:newSize]; + _fontSizeStepper.value = newSize.integerValue; + [_fontSizeField setText:[NSString stringWithFormat:@"%@ px", newSize]]; } - (void)write:(NSString *)input @@ -403,7 +412,10 @@ - (void)write:(NSString *)input - (void)showcaseTheme:(BKTheme *)theme { + [_testTerminal clear]; [_testTerminal loadTerminalThemeJS:theme.content]; + // Wait for the terminal to setup everything internally + [self performSelector:@selector(writeColorShowcase) withObject:self afterDelay:0.25]; } - (void)showcaseFont:(BKFont *)font