Skip to content

Commit

Permalink
Better theme reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jan 23, 2018
1 parent 337821b commit bc153ac
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
8 changes: 5 additions & 3 deletions Blink/SpaceController.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ - (void)_attachInputToCurrentTerm

- (void)decodeRestorableStateWithCoder:(NSCoder *)coder andStateManager: (StateManager *)stateManager
{
_unfocused = [coder decodeBoolForKey:@"_infocused"];
NSArray *sessionStateKeys = [coder decodeObjectForKey:@"sessionStateKeys"];

_viewports = [[NSMutableArray alloc] init];
Expand Down Expand Up @@ -190,6 +191,7 @@ - (void)encodeRestorableStateWithCoder:(NSCoder *)coder
}
[coder encodeInteger:idx forKey:@"idx"];
[coder encodeObject:sessionStateKeys forKey:@"sessionStateKeys"];
[coder encodeBool:_unfocused forKey:@"_infocused"];
}

- (void)registerForNotifications
Expand Down Expand Up @@ -535,12 +537,15 @@ - (void)_displayHUD
_hud.bezelView.color = [UIColor darkGrayColor];
_hud.contentColor = [UIColor whiteColor];
_hud.userInteractionEnabled = NO;
_hud.alpha = 0.6;

UIPageControl *pages = [[UIPageControl alloc] init];
pages.currentPageIndicatorTintColor = [UIColor cyanColor];
pages.numberOfPages = [_viewports count];
pages.currentPage = [_viewports indexOfObject:self.currentTerm];

_hud.customView = pages;

NSString *title = self.currentTerm.title.length ? self.currentTerm.title : @"blink";

MCPSessionParameters *params = self.currentTerm.sessionParameters;
Expand All @@ -555,9 +560,6 @@ - (void)_displayHUD
_hud.label.text = [NSString stringWithFormat:@"%@\n%@", title, geometry];
}

_hud.customView = pages;
_hud.alpha = 0.6;

[_hud hideAnimated:YES afterDelay:1.f];
}

Expand Down
1 change: 1 addition & 0 deletions Blink/TermController.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
- (void)resume;
- (void)focus;
- (void)blur;
- (void)reload;

- (void)attachInput:(TermInput *)termInput;

Expand Down
17 changes: 15 additions & 2 deletions Blink/TermController.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ @implementation TermController {
int _pinput[2];
MCPSession *_session;
NSDictionary *_activityUserInfo;
BOOL _isReloading;
}

- (void)loadView
Expand Down Expand Up @@ -227,7 +228,14 @@ - (void)dealloc

- (void)sessionFinished
{
[_delegate terminalHangup:self];
if (_isReloading) {
_isReloading = NO;
[self destroyPTY];
[self createPTY];
[_termView reload];
} else {
[_delegate terminalHangup:self];
}
}

#pragma mark Notifications
Expand All @@ -236,9 +244,14 @@ - (void)sessionFinished
- (void)terminate
{
[_termView terminate];

[_session kill];
}

- (void)reload
{
_isReloading = YES;
}

- (void)suspend
{
[_session suspend];
Expand Down
13 changes: 9 additions & 4 deletions Sessions/MCPSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ - (int)main:(int)argc argv:(char **)argv
} else if ([cmd isEqualToString:@"exit"]) {
break;
} else if ([cmd isEqualToString:@"theme"]) {
[self _switchTheme: args];
BOOL reload = [self _switchTheme: args];
if (reload) {
return 0;
}
} else if ([cmd isEqualToString:@"music"]) {
[self _controlMusic: args];
} else if ([cmd isEqualToString:@"ssh-copy-id"]) {
Expand Down Expand Up @@ -297,7 +300,7 @@ - (void)_showConfig
});
}

- (void)_switchTheme:(NSString *)args
- (BOOL)_switchTheme:(NSString *)args
{
if ([args isEqualToString:@""] || [args isEqualToString:@"info"]) {
NSString *themeName = [BKDefaults selectedThemeName];
Expand All @@ -306,19 +309,21 @@ - (void)_switchTheme:(NSString *)args
if (!theme) {
[self out:@"Not found".UTF8String];
}
return NO;
} else {
BKTheme *theme = [BKTheme withName:args];
if (!theme) {
[self out:@"Theme not found".UTF8String];
return NO;
}

[BKDefaults setThemeName:theme.name];
[BKDefaults saveDefaults];

dispatch_async(dispatch_get_main_queue(), ^{
[_stream.control terminate];
[_stream.control resume];
[_stream.control reload];
});
return YES;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sessions/Session.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ int makeargs(const char *args, char ***aa)
free(params);
[session.stream close];
[session.delegate performSelectorOnMainThread:@selector(sessionFinished) withObject:nil waitUntilDone:YES];

session.stream = nil;

return NULL;
}

Expand Down

0 comments on commit bc153ac

Please sign in to comment.