make ptyview follow the delegate protocol

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@39589 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Riccardo Mottola 2016-03-23 00:19:46 +00:00
parent 98712ea405
commit 0bc7e0d6b1
2 changed files with 41 additions and 19 deletions

View file

@ -1,7 +1,7 @@
/*
** PTYView
**
** Copyright (c) 2008
** Copyright (c) 2008-2016
**
** Author: Gregory Casamento <greg_casamento@yahoo.com>
**
@ -23,8 +23,11 @@
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
@interface PTYView : NSTextView
#import "PCDebuggerViewDelegateProtocol.h"
@interface PTYView : NSObject <PCDebuggerViewDelegateProtocol>
{
NSTextView *tView;
NSTask *task;
NSFileHandle *master_handle;
NSFileHandle *slave_handle;
@ -34,9 +37,6 @@
- (int)openpty;
- (void)logString:(NSString *)str
newLine:(BOOL)newLine;
- (void)logData:(NSData *)data;
- (void)logStdOut:(NSNotification *)aNotif;

View file

@ -1,9 +1,10 @@
/*
** PTYView
**
** Copyright (c) 2008-2012 Free Software Foundation
** Copyright (c) 2008-2016 Free Software Foundation
**
** Author: Gregory Casamento <greg_casamento@yahoo.com>
** Author: Gregory Casamento <greg.casamento@gmail.com>
** Riccardo Mottola <rm@gnu.org>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@ -141,6 +142,22 @@ int openpty(int *amaster, int *aslave, char *name, const struct termios *termp,
#endif
@implementation PTYView
- (NSTextView *)textView
{
return tView;
}
- (void)setTextView: (NSTextView *)tv
{
if (tView != tv)
{
[tView release];
tView = tv;
[tView retain];
}
}
/**
* Creates master device.
*/
@ -158,16 +175,17 @@ int openpty(int *amaster, int *aslave, char *name, const struct termios *termp,
*/
- (void) logString:(NSString *)str
newLine:(BOOL)newLine
withColor:(NSColor *)color
{
NSRange range;
[self replaceCharactersInRange:
NSMakeRange([[self string] length],0) withString:str];
[tView replaceCharactersInRange:
NSMakeRange([[tView string] length],0) withString:str];
if (newLine)
{
[self replaceCharactersInRange:
NSMakeRange([[self string] length], 0) withString:@"\n"];
[tView replaceCharactersInRange:
NSMakeRange([[tView string] length], 0) withString:@"\n"];
}
//
@ -178,12 +196,12 @@ int openpty(int *amaster, int *aslave, char *name, const struct termios *termp,
range = [str rangeOfString: @"\b"];
if (range.location != NSNotFound)
{
NSString *newString = [[self string] substringToIndex: [[self string] length] - 4];
[self setString: newString];
NSString *newString = [[tView string] substringToIndex: [[tView string] length] - 4];
[tView setString: newString];
}
[self scrollRangeToVisible:NSMakeRange([[self string] length], 0)];
[self setNeedsDisplay:YES];
[tView scrollRangeToVisible:NSMakeRange([[tView string] length], 0)];
[tView setNeedsDisplay:YES];
}
/**
@ -195,7 +213,7 @@ int openpty(int *amaster, int *aslave, char *name, const struct termios *termp,
dataString = [[NSString alloc]
initWithData:data
encoding:[NSString defaultCStringEncoding]];
[self logString: dataString newLine: NO];
[self logString: dataString newLine: NO withColor:nil];
RELEASE(dataString);
}
@ -257,7 +275,8 @@ int openpty(int *amaster, int *aslave, char *name, const struct termios *termp,
{
NSLog(@"Task Terminated...");
[self logString: [self stopMessage]
newLine:YES];
newLine:YES
withColor:nil];
}
/**
@ -330,7 +349,8 @@ int openpty(int *amaster, int *aslave, char *name, const struct termios *termp,
NS_DURING
{
[self logString: [self startMessage]
newLine:YES];
newLine:YES
withColor:nil];
[task launch];
}
NS_HANDLER
@ -342,7 +362,8 @@ int openpty(int *amaster, int *aslave, char *name, const struct termios *termp,
NSLog(@"Task Terminated Unexpectedly...");
[self logString: @"\n=== Task Terminated Unexpectedly ===\n"
newLine:YES];
newLine:YES
withColor:nil];
//Clean up after task is terminated
[[NSNotificationCenter defaultCenter]
@ -366,6 +387,7 @@ int openpty(int *amaster, int *aslave, char *name, const struct termios *termp,
{
[NOTIFICATION_CENTER removeObserver: self];
[self terminate];
[tView release];
[super dealloc];
}