Skip to content

Commit

Permalink
Fixes Test Terminal not showing changes
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Carlos Cabanero committed Sep 16, 2016
1 parent d03203f commit 327031f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Blink/TermController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion Blink/TermView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions Blink/TermView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions Resources/termcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -69,3 +69,7 @@ var loadFontFromCSS = function(cssPath, name) {
});
t.prefs_.set('font-family', name);
}

var clear = function() {
t.clear();
}
2 changes: 1 addition & 1 deletion Settings/Base.lproj/Settings.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@
<constraint firstAttribute="width" constant="94" id="Xbi-MQ-gaa"/>
</constraints>
<connections>
<action selector="stepperButtonPressed:" destination="wNx-Mq-Q3D" eventType="valueChanged" id="sUe-9h-stv"/>
<action selector="stepperValueChanged:" destination="wNx-Mq-Q3D" eventType="valueChanged" id="reR-xL-0PA"/>
</connections>
</stepper>
</subviews>
Expand Down
70 changes: 41 additions & 29 deletions Settings/ViewControllers/Appearance/BKAppearanceViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ @interface BKAppearanceViewController () <TerminalDelegate>
@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

Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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]) {
Expand All @@ -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];

// }
}
}
Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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"];
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 327031f

Please sign in to comment.