//
// Copyright (c) 2014 Secret Geometry, Inc.  All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Debug.h"
#import "Tuple.h"
#import "TerminalViewDelegate.h"

@class TerminalMacView, TerminalIosView;

extern NSString* const TerminalSessionWillBeginNotification;
extern NSString* const TerminalSessionDidBeginNotification;
extern NSString* const TerminalSessionWillEndNotification;
extern NSString* const TerminalSessionDidEndNotification;
extern NSString* const TerminalTextDidChangeNotification;
extern NSString* const TerminalSessionFailedToConnectNotification;


//
//
//
@interface TerminalController : NSObject <TerminalViewDelegate>

- (id) initWithServer:(NSString*)server
                 user:(NSString*)user
             password:(NSString*)password
              keyFile:(NSString*)keyFile
                 port:(NSUInteger)port
           identifier:(NSString*)identifier;

#ifdef TERMKIT_IOS
    @property (nonatomic, strong) IBOutlet TerminalIosView* terminalView;
#else
    @property (nonatomic, strong) IBOutlet TerminalMacView* terminalView;
#endif

@property (nonatomic, copy) NSString* server;
@property (nonatomic, copy) NSString* user;
@property (nonatomic, copy) NSString* password;
@property (nonatomic, copy) NSString* keyFile;
@property (nonatomic, copy) NSString* terminalIdentifier;
@property (nonatomic, copy) NSString* descriptiveTitle;
@property (nonatomic) NSUInteger port;
@property (nonatomic) NSUInteger terminalIndex;
@property (readonly) NSUInteger rowCount;
@property (readonly) NSUInteger columnCount;
@property (readonly) NSUInteger totalRowCount;
@property (nonatomic) NSTimeInterval startTime;
@property (nonatomic) GridLocation cursorPos;
@property (readonly) NSUInteger processCount;
@property (readonly) NSString* activeProcessName;
@property (readonly) NSArray* allProcessNames;

- (void) start;
- (void) logout;
- (void) suspend;
- (void) resume;

- (BOOL) disconnected;
- (BOOL) connecting;
- (BOOL) connected;
- (BOOL) suspended;
- (NSString*) message;

- (unichar) characterAt:(GridLocation)loc;
- (NSString*) stringFrom:(GridLocation)startLoc to:(GridLocation)endLoc;

- (void) writeChar:(unichar)uc;
- (void) writeString:(NSString*)text;

- (void) clearBuffer;

- (void) resetInDirectory:(NSString*)path;
- (void) updateTerminal:(id)sender;
- (void) startTimer;
- (void) stopTimer;

- (void) functionKey:(int)key;
- (void) deleteKey;
- (void) forwardDeleteKey;
- (void) upArrowKey;
- (void) downArrowKey;
- (void) leftArrowKey;
- (void) rightArrowKey;
- (void) pageUpKey;
- (void) pageDownKey;
- (void) moveWordLeft;
- (void) moveWordRight;

- (void*) getContext;

@end
