Skip to content

Commit

Permalink
Renamte TermController.terminal to TermController.termView
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jan 18, 2018
1 parent 01f61a6 commit fb5ee0a
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 124 deletions.
82 changes: 40 additions & 42 deletions Blink/SpaceController.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ - (void)loadView
[self.view addSubview:_termInput];

self.view.opaque = YES;


NSDictionary *options = [NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:UIPageViewControllerSpineLocationMid]
forKey:UIPageViewControllerOptionSpineLocationKey];

_viewportsController = [[UIPageViewController alloc]
initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
options:options];
_viewportsController.view.opaque = YES;
_viewportsController.dataSource = self;
_viewportsController.delegate = self;
Expand Down Expand Up @@ -123,11 +126,6 @@ - (void)viewDidLoad
}
}

- (void)copy:(id)sender
{

}

- (BOOL)canBecomeFirstResponder
{
return YES;
Expand All @@ -138,7 +136,7 @@ - (BOOL)prefersStatusBarHidden
return YES;
}

- (void)focusOnShell
- (void)_focusOnShell
{
[self.currentTerm attachInput:_termInput];
}
Expand Down Expand Up @@ -170,7 +168,7 @@ - (void)decodeRestorableStateWithCoder:(NSCoder *)coder andStateManager: (StateM
animated:NO
completion:^(BOOL complete) {
if (complete) {
[weakSelf focusOnShell];
[weakSelf _focusOnShell];
}
}];
[self.view setNeedsLayout];
Expand Down Expand Up @@ -303,7 +301,6 @@ - (void)handleTwoFingersDrag:(UIPanGestureRecognizer *)sender
CGFloat y = [sender translationInView:self.view].y;
CGFloat height = self.view.frame.size.height;
CGRect frame = self.view.frame;


if (y > 0) {
[self.view setFrame:CGRectMake(frame.origin.x, y, frame.size.width, frame.size.height)];
Expand All @@ -313,7 +310,7 @@ - (void)handleTwoFingersDrag:(UIPanGestureRecognizer *)sender
if (sender.state == UIGestureRecognizerStateEnded) {
CGPoint velocity = [sender velocityInView:self.view];
[self.view setFrame:CGRectMake(frame.origin.x, 0, frame.size.width, frame.size.height)];

if (velocity.y > height * 2) {
_viewportsController.view.alpha = 1;
[self closeCurrentSpace];
Expand All @@ -339,9 +336,7 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewControl
if (idx >= [_viewports count] - 1) {
return nil;
}
UIViewController *ctrl = _viewports[idx + 1];
[ctrl.view setNeedsLayout];
return ctrl;
return _viewports[idx + 1];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
Expand All @@ -355,20 +350,21 @@ - (UIViewController *)pageViewController:(UIPageViewController *)pageViewControl
if (idx <= 0) {
return nil;
}
UIViewController *ctrl = _viewports[idx - 1];
[ctrl.view setNeedsLayout];
return ctrl;
return _viewports[idx - 1];
}

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers transitionCompleted:(BOOL)completed
- (void)pageViewController:(UIPageViewController *)pageViewController
didFinishAnimating:(BOOL)finished
previousViewControllers:(NSArray<UIViewController *> *)previousViewControllers
transitionCompleted:(BOOL)completed
{
if (completed) {
for (TermController *term in previousViewControllers) {
[term attachInput:nil];
}

[self displayHUD];
[self focusOnShell];
[self _displayHUD];
[self _focusOnShell];
}
}

Expand All @@ -390,7 +386,7 @@ - (UIPageControl *)pageControl
return _pageControl;
}

- (void)displayHUD
- (void)_displayHUD
{
if (!_hud) {
_hud = [[MBProgressHUD alloc] initWithView:_viewportsController.view];
Expand All @@ -405,7 +401,7 @@ - (void)displayHUD
UIPageControl *pages = [self pageControl];

NSInteger idx = [_viewports indexOfObject:self.currentTerm];
NSString *title = self.currentTerm.terminal.title.length ? self.currentTerm.terminal.title : @"blink";
NSString *title = self.currentTerm.title.length ? self.currentTerm.title : @"blink";
NSString *geometry = [NSString stringWithFormat:@"%ld x %ld",
(long)self.currentTerm.sessionParameters.rows
, (long)self.currentTerm.sessionParameters.cols];
Expand Down Expand Up @@ -451,8 +447,8 @@ - (void)removeCurrentSpace {
completion:^(BOOL didComplete) {
// Remove viewport from the list after animation
if (didComplete) {
[weakSelf displayHUD];
[weakSelf focusOnShell];
[weakSelf _displayHUD];
[weakSelf _focusOnShell];
}
}];
} else {
Expand All @@ -463,14 +459,17 @@ - (void)removeCurrentSpace {
completion:^(BOOL didComplete) {
// Remove viewport from the list after animation
if (didComplete) {
[weakSelf displayHUD];
[weakSelf focusOnShell];
[weakSelf _displayHUD];
[weakSelf _focusOnShell];
}
}];
}
}

- (void)_createShellWithUserActivity:(NSUserActivity *) userActivity sessionStateKey:(NSString *)sessionStateKey animated:(BOOL)animated completion:(void (^)(BOOL finished))completion
- (void)_createShellWithUserActivity:(NSUserActivity *) userActivity
sessionStateKey:(NSString *)sessionStateKey
animated:(BOOL)animated
completion:(void (^)(BOOL finished))completion
{
TermController *term = [[TermController alloc] init];
term.sessionStateKey = sessionStateKey;
Expand Down Expand Up @@ -501,8 +500,8 @@ - (void)_createShellWithUserActivity:(NSUserActivity *) userActivity sessionStat
animated:animated
completion:^(BOOL didComplete) {
if (didComplete) {
[weakSelf displayHUD];
[weakSelf focusOnShell];
[weakSelf _displayHUD];
[weakSelf _focusOnShell];
}
if (completion) {
completion(didComplete);
Expand All @@ -522,7 +521,7 @@ - (void)terminalHangup:(TermController *)control

- (void)terminalDidResize:(TermController*)control
{
[self displayHUD];
[self _displayHUD];
}

#pragma mark External Keyboard
Expand Down Expand Up @@ -616,17 +615,17 @@ - (void)setKbdCommands

- (void)_increaseFontSize:(UIKeyCommand *)cmd
{
[self.currentTerm.terminal increaseFontSize];
[self.currentTerm.termView increaseFontSize];
}

- (void)_decreaseFontSize:(UIKeyCommand *)cmd
{
[self.currentTerm.terminal decreaseFontSize];
[self.currentTerm.termView decreaseFontSize];
}

- (void)_resetFontSize:(UIKeyCommand *)cmd
{
[self.currentTerm.terminal resetFontSize];
[self.currentTerm.termView resetFontSize];
}

- (void)playNext:(UIKeyCommand *)cmd
Expand Down Expand Up @@ -673,7 +672,7 @@ - (void)showConfig:(UIKeyCommand *)cmd
- (void)switchShellIdx:(NSInteger)idx direction:(UIPageViewControllerNavigationDirection)direction animated:(BOOL) animated
{
if (idx < 0 || idx >= _viewports.count) {
[self displayHUD];
[self _displayHUD];
return;
}

Expand All @@ -685,11 +684,10 @@ - (void)switchShellIdx:(NSInteger)idx direction:(UIPageViewControllerNavigationD
animated:animated
completion:^(BOOL didComplete) {
if (didComplete) {
[weakSelf displayHUD];
[weakSelf focusOnShell];
[weakSelf _displayHUD];
[weakSelf _focusOnShell];
}
}];

}

- (void)nextShell:(UIKeyCommand *)cmd
Expand Down Expand Up @@ -757,7 +755,7 @@ - (void)moveAllShellsFromSpaceController:(SpaceController *)spaceController
[_viewports addObject:ctrl];
}

[self displayHUD];
[self _displayHUD];
}

- (void)moveCurrentShellFromSpaceController:(SpaceController *)spaceController
Expand All @@ -766,12 +764,12 @@ - (void)moveCurrentShellFromSpaceController:(SpaceController *)spaceController
term.delegate = self;
[_viewports addObject:term];
[spaceController removeCurrentSpace];
[self displayHUD];
[self _displayHUD];
}

- (void)viewScreenWillBecomeActive
{
[self displayHUD];
[self _displayHUD];
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
Expand Down Expand Up @@ -807,7 +805,7 @@ - (void)restoreUserActivityState:(NSUserActivity *)activity
if (targetIdx == NSNotFound) {
if (self.currentTerm.activityKey == nil) {
[self.currentTerm restoreUserActivityState:activity];
[self focusOnShell];
[self _focusOnShell];
} else {
[self _createShellWithUserActivity:activity sessionStateKey:nil animated:YES completion:nil];
}
Expand All @@ -816,7 +814,7 @@ - (void)restoreUserActivityState:(NSUserActivity *)activity

// 3. We are already showing required term. So do nothing.
if (idx == targetIdx) {
[self focusOnShell];
[self _focusOnShell];
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Blink/TermController.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
@property (readonly) FILE *termin;
@property (readonly) FILE *termerr;
@property (readonly) struct winsize *termsz;
@property (strong, nonatomic) TermView *terminal;
@property (readonly, strong, nonatomic) TermView *termView;
@property (readonly, strong, nonatomic) TermInput *termInput;
@property (weak) id<TermControlDelegate> delegate;
@property (strong, nonatomic) NSString* activityKey;
Expand Down
39 changes: 16 additions & 23 deletions Blink/TermController.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ @implementation TermController {
BOOL _appearanceChanged;
BOOL _disableFontSizeSelection;
NSDictionary *_activityUserInfo;
TermInput *_termInput;
BOOL _rawMode;
}

- (NSString *)title {
return _termView.title;
}

- (void)write:(NSString *)input
{
Expand All @@ -62,28 +64,19 @@ - (void)write:(NSString *)input
write(_pinput[1], str, [input lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
}


- (TermView *) termView {
return _terminal;
}

- (TermInput *)termInput {
return _termInput;
}

- (void)attachInput:(TermInput *)termInput
{
_termInput = termInput;
if (termInput) {
_termInput.raw = _rawMode;
_termInput.termDelegate = self;
if ([_termInput isFirstResponder]) {
[_terminal focus];
[_termView focus];
} else {
[_terminal blur];
[_termView blur];
}
} else {
[_terminal blur];
[_termView blur];
}
}

Expand All @@ -95,11 +88,11 @@ - (void)loadView
_sessionStateKey = [[NSProcessInfo processInfo] globallyUniqueString];
}

_terminal = [[TermView alloc] initWithFrame:self.view.frame];
_terminal.restorationIdentifier = @"TermView";
_terminal.termDelegate = self;
_termView = [[TermView alloc] initWithFrame:self.view.frame];
_termView.restorationIdentifier = @"TermView";
_termView.termDelegate = self;

self.view = _terminal;
self.view = _termView;
}


Expand Down Expand Up @@ -173,16 +166,16 @@ - (void)viewDidLoad
_sessionParameters.fontSize = [[BKDefaults selectedFontSize] integerValue];
}

[_terminal loadTerminal];
[_termView loadTerminal];

[self createPTY];
}

- (void)createPTY
{
pipe(_pinput);
_termout = fterm_open(_terminal, 0);
_termerr = fterm_open(_terminal, 0);
_termout = fterm_open(_termView, 0);
_termerr = fterm_open(_termView, 0);
_termin = fdopen(_pinput[0], "r");
_termsz = malloc(sizeof(struct winsize));
_termsz->ws_col = _sessionParameters.cols;
Expand Down Expand Up @@ -300,7 +293,7 @@ - (void)appearanceChanged:(NSNotification *)notification

- (void)terminate
{
[_terminal terminate];
[_termView terminate];

[_session kill];
}
Expand All @@ -318,15 +311,15 @@ - (void)resume

- (void)focus {
_termInput.termDelegate = self;
[_terminal focus];
[_termView focus];
if (![_termInput isFirstResponder]) {
[_termInput becomeFirstResponder];
}
}

- (void)blur {
_termInput.termDelegate = nil;
[_terminal blur];
[_termView blur];
}

@end
Loading

0 comments on commit fb5ee0a

Please sign in to comment.