 			/* Ack the size*/
 			let ackcode: CNEscapeCode = .screenSize(self.currentColumnNumbers, self.currentRowNumbers)
 			mInputPipe.fileHandleForWriting.write(string: ackcode.encode())
+		case .saveCursorPosition:
+			mSavedIndex = mCurrentIndex
+		case .restoreCursorPosition:
+			let str = self.textStorage.string
+			let endidx  = str.distance(from: str.startIndex, to: str.endIndex)
+			mCurrentIndex = min(mSavedIndex, endidx)
 		default:
 			let desc = code.description()
 			NSLog("Unexpected code: \(desc)")

		mOutputPipe			= Pipe()
		mErrorPipe			= Pipe()
		mCurrentIndex			= 0
		mForegroundTextColor		= nil
		mBackgroundTextColor		= nil
		mFont				= CNFont.systemFont(ofSize: CNFont.systemFontSize)

	private var mOutputPipe:		Pipe
	private var mErrorPipe:			Pipe
	private var mCurrentIndex:		Int
	private var mSavedIndex:		Int
	private var mForegroundTextColor:	CNColor?
	private var mBackgroundTextColor:	CNColor?
	private var mFont:			CNFont
