Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Add TerminalBuffer & TerminalCursor, parse \n \r \b, and more escape codes #85

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7f87ab5
Added TerminalCursor, more control character recognition
ian-mcdowell Feb 11, 2018
25f4c61
Merge branch 'master' into carriage
ian-mcdowell Feb 11, 2018
604e891
A few fixes after merge
ian-mcdowell Feb 11, 2018
248f75b
Added tests for TerminalCursor
ian-mcdowell Feb 11, 2018
04e1292
Added TerminalBufferTests, Moved GCD helpers into Dispatch+Custom
ian-mcdowell Feb 11, 2018
194a57f
Removed absolute path from pbxproj to fix build
ian-mcdowell Feb 11, 2018
b072134
Removed cyclomatic complexity error for Parser method
ian-mcdowell Feb 11, 2018
3eaa455
Added ParserTests, XCTAssert -> XCTAssertEqual, enabled codecov
ian-mcdowell Feb 12, 2018
779714b
Moved ios_system setup to AppDelegate
ian-mcdowell Feb 13, 2018
66ba9f8
Synchronize TerminalCursor & textview cursor, add distance to Termina…
ian-mcdowell Feb 13, 2018
f3b3af8
Fixed bug causing history to be corrupted
ian-mcdowell Feb 13, 2018
ba89fcf
Added Outputsanitizer into the Parser
ian-mcdowell Feb 13, 2018
0abe5dc
Merge branch 'master' into carriage
ian-mcdowell Feb 13, 2018
d09ebcd
Fixed parser tests
ian-mcdowell Feb 13, 2018
59f516d
Added basic sanitizer test, refactored ParserTests a bit
ian-mcdowell Feb 13, 2018
872573a
Fix for missing libtext.dylib & share reading from stdin (#90)
ian-mcdowell Feb 13, 2018
55804dc
Added ls colors test
ian-mcdowell Feb 13, 2018
3d36b8c
Added CommandExecutorTests, ls & cat tests
ian-mcdowell Feb 14, 2018
569865f
Merge branch 'master' into carriage
ian-mcdowell Feb 14, 2018
f474440
Performance improvements for ANSITextState
ian-mcdowell Feb 14, 2018
c577698
No longer mess with process stdout/stderr since it causes bugs
ian-mcdowell Feb 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions OpenTerm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
3C1A47B12031357500D7CC5C /* Pods_OpenTerm.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FC01604DAC695ABD64544260 /* Pods_OpenTerm.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3C1A47B22031357B00D7CC5C /* ios_system.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BE3768EE1FEC4DCE00D5A2D1 /* ios_system.framework */; };
3C1A47B520336F0F00D7CC5C /* libtext.dylib in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3C1A47B320336F0200D7CC5C /* libtext.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
3C1A47B72033F0E600D7CC5C /* CommandExecutorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C1A47B62033F0E600D7CC5C /* CommandExecutorTests.swift */; };
3C2E4374201EF67C00E4254A /* TerminalView+AutoComplete.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C2E4373201EF67C00E4254A /* TerminalView+AutoComplete.swift */; };
3C2E4385201EFF4700E4254A /* AutoCompleteManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C2E4384201EFF4700E4254A /* AutoCompleteManager.swift */; };
3C406E1A20207CE7005F97C4 /* CommandExecutor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C406E1920207CE7005F97C4 /* CommandExecutor.swift */; };
Expand All @@ -31,12 +32,18 @@
3CA32105201FFC1300974B5F /* ScriptEditViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CA32104201FFC1300974B5F /* ScriptEditViewController.swift */; };
3CA3210920211D5600974B5F /* ScriptExecutorCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CA3210820211D5600974B5F /* ScriptExecutorCommand.swift */; };
3CA3210B20212D4200974B5F /* CommandExecutionContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CA3210A20212D4200974B5F /* CommandExecutionContext.swift */; };
3CD59E63202EFE18002298B4 /* TerminalCursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD59E62202EFE17002298B4 /* TerminalCursor.swift */; };
3CD59E67202FDEBA002298B4 /* TerminalCursorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD59E66202FDEBA002298B4 /* TerminalCursorTests.swift */; };
3CD59E6920301329002298B4 /* TerminalBufferTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD59E6820301329002298B4 /* TerminalBufferTests.swift */; };
3CD59E6B20301588002298B4 /* Dispatch+Custom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD59E6A20301588002298B4 /* Dispatch+Custom.swift */; };
3CD59E6D20311978002298B4 /* ParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CD59E6C20311978002298B4 /* ParserTests.swift */; };
3CE5764320225E1B00760E43 /* HistoryManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CE5764220225E1B00760E43 /* HistoryManager.swift */; };
3CE5764820226A1500760E43 /* ANSITextState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CE5764720226A1500760E43 /* ANSITextState.swift */; };
3CE57680202A529200760E43 /* TerminalTabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C905FC42025CAEC0084BA63 /* TerminalTabViewController.swift */; };
3CE57681202A52ED00760E43 /* TerminalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE3808571FD9BFB600393EB8 /* TerminalViewController.swift */; };
3CE5769E202A7EC500760E43 /* Parser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CE5769D202A7EC500760E43 /* Parser.swift */; };
3CE576A0202A874C00760E43 /* OutputSanitizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CE5769F202A874C00760E43 /* OutputSanitizer.swift */; };
3CE576AA202E61DE00760E43 /* TerminalBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CE576A9202E61DE00760E43 /* TerminalBuffer.swift */; };
5A38CC73C499E1A878353871 /* Pods_OpenTerm.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC01604DAC695ABD64544260 /* Pods_OpenTerm.framework */; };
BE165408201909040067EC92 /* xCallBackUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE165407201909030067EC92 /* xCallBackUrl.swift */; };
BE244DC8201FBB6000A7EA4E /* cacert.pem in Resources */ = {isa = PBXBuildFile; fileRef = BE244DC7201FBB6000A7EA4E /* cacert.pem */; };
Expand Down Expand Up @@ -103,6 +110,7 @@
3C1A47A22031355700D7CC5C /* libssh_cmd.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libssh_cmd.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
3C1A47A32031355700D7CC5C /* libtar.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libtar.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
3C1A47B320336F0200D7CC5C /* libtext.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libtext.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
3C1A47B62033F0E600D7CC5C /* CommandExecutorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandExecutorTests.swift; sourceTree = "<group>"; };
3C2E4373201EF67C00E4254A /* TerminalView+AutoComplete.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TerminalView+AutoComplete.swift"; sourceTree = "<group>"; };
3C2E4384201EFF4700E4254A /* AutoCompleteManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoCompleteManager.swift; sourceTree = "<group>"; };
3C406E1920207CE7005F97C4 /* CommandExecutor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandExecutor.swift; sourceTree = "<group>"; };
Expand All @@ -115,10 +123,16 @@
3CA32104201FFC1300974B5F /* ScriptEditViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptEditViewController.swift; sourceTree = "<group>"; };
3CA3210820211D5600974B5F /* ScriptExecutorCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScriptExecutorCommand.swift; sourceTree = "<group>"; };
3CA3210A20212D4200974B5F /* CommandExecutionContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandExecutionContext.swift; sourceTree = "<group>"; };
3CD59E62202EFE17002298B4 /* TerminalCursor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalCursor.swift; sourceTree = "<group>"; };
3CD59E66202FDEBA002298B4 /* TerminalCursorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalCursorTests.swift; sourceTree = "<group>"; };
3CD59E6820301329002298B4 /* TerminalBufferTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalBufferTests.swift; sourceTree = "<group>"; };
3CD59E6A20301588002298B4 /* Dispatch+Custom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dispatch+Custom.swift"; sourceTree = "<group>"; };
3CD59E6C20311978002298B4 /* ParserTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParserTests.swift; sourceTree = "<group>"; };
3CE5764220225E1B00760E43 /* HistoryManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HistoryManager.swift; sourceTree = "<group>"; };
3CE5764720226A1500760E43 /* ANSITextState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ANSITextState.swift; sourceTree = "<group>"; };
3CE5769D202A7EC500760E43 /* Parser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Parser.swift; sourceTree = "<group>"; };
3CE5769F202A874C00760E43 /* OutputSanitizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutputSanitizer.swift; sourceTree = "<group>"; };
3CE576A9202E61DE00760E43 /* TerminalBuffer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TerminalBuffer.swift; sourceTree = "<group>"; };
448CC7691FD84EB5D2C24705 /* Pods-OpenTerm.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OpenTerm.debug.xcconfig"; path = "Pods/Target Support Files/Pods-OpenTerm/Pods-OpenTerm.debug.xcconfig"; sourceTree = "<group>"; };
BE165407201909030067EC92 /* xCallBackUrl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = xCallBackUrl.swift; sourceTree = "<group>"; };
BE244DC7201FBB6000A7EA4E /* cacert.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = cacert.pem; sourceTree = "<group>"; };
Expand Down Expand Up @@ -243,6 +257,15 @@
path = Scripting;
sourceTree = "<group>";
};
3CD59E61202EFDFA002298B4 /* Terminal */ = {
isa = PBXGroup;
children = (
3CD59E62202EFE17002298B4 /* TerminalCursor.swift */,
3CE576A9202E61DE00760E43 /* TerminalBuffer.swift */,
);
path = Terminal;
sourceTree = "<group>";
};
3CE5764120225E1B00760E43 /* History */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -360,6 +383,7 @@
BEA8E28F2001346D00002475 /* Util */ = {
isa = PBXGroup;
children = (
3CD59E61202EFDFA002298B4 /* Terminal */,
3CE576442022607000760E43 /* Parsing & Formatting */,
3C406E1B2020987B005F97C4 /* AutoComplete */,
3C406E1820207CDA005F97C4 /* Execution */,
Expand All @@ -372,6 +396,7 @@
BEA499251FD9C4D7001B9B9D /* DocumentManager.swift */,
BE9275052013961D00BD2761 /* UserDefaultsController.swift */,
3C905FC920265BC60084BA63 /* StoreReviewPrompter.swift */,
3CD59E6A20301588002298B4 /* Dispatch+Custom.swift */,
);
path = Util;
sourceTree = "<group>";
Expand All @@ -381,6 +406,10 @@
children = (
BEC75BFC202B716600216462 /* OpenTermTests.swift */,
BEC75BFE202B716600216462 /* Info.plist */,
3CD59E66202FDEBA002298B4 /* TerminalCursorTests.swift */,
3CD59E6820301329002298B4 /* TerminalBufferTests.swift */,
3CD59E6C20311978002298B4 /* ParserTests.swift */,
3C1A47B62033F0E600D7CC5C /* CommandExecutorTests.swift */,
);
path = OpenTermTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -600,10 +629,13 @@
F4602B49200A63FC009D0547 /* UserDefaults+UIColor.swift in Sources */,
28CDA426202444CC0055206D /* BookmarkViewController.swift in Sources */,
3CA32105201FFC1300974B5F /* ScriptEditViewController.swift in Sources */,
3CE576AA202E61DE00760E43 /* TerminalBuffer.swift in Sources */,
3C2E4374201EF67C00E4254A /* TerminalView+AutoComplete.swift in Sources */,
BEECFF391FFEC187009608B3 /* SettingsViewController.swift in Sources */,
3CD59E6B20301588002298B4 /* Dispatch+Custom.swift in Sources */,
F456629E200B9BC500C574AA /* ColorDisplayView.swift in Sources */,
BE165408201909040067EC92 /* xCallBackUrl.swift in Sources */,
3CD59E63202EFE18002298B4 /* TerminalCursor.swift in Sources */,
BEA499261FD9C4D7001B9B9D /* DocumentManager.swift in Sources */,
BE505066201E5ED900CDFC60 /* Share.swift in Sources */,
3CE5764820226A1500760E43 /* ANSITextState.swift in Sources */,
Expand All @@ -629,7 +661,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3CD59E6D20311978002298B4 /* ParserTests.swift in Sources */,
3CD59E6920301329002298B4 /* TerminalBufferTests.swift in Sources */,
BEC75BFD202B716600216462 /* OpenTermTests.swift in Sources */,
3CD59E67202FDEBA002298B4 /* TerminalCursorTests.swift in Sources */,
3C1A47B72033F0E600D7CC5C /* CommandExecutorTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion OpenTerm.xcodeproj/xcshareddata/xcschemes/OpenTerm.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
14 changes: 14 additions & 0 deletions OpenTerm/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit
import TabView
import ios_system

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -17,6 +18,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

initializeEnvironment()
replaceCommand("open-url", mangleFunctionName("openUrl"), true)
replaceCommand("share", mangleFunctionName("shareFile"), true)
replaceCommand("pbcopy", mangleFunctionName("pbcopy"), true)
replaceCommand("pbpaste", mangleFunctionName("pbpaste"), true)

window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = TabViewContainerViewController<TerminalTabViewController>(theme: TabViewThemeDark())
window?.tintColor = .defaultMainTintColor
Expand All @@ -27,6 +34,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

private func mangleFunctionName(_ functionName: String) -> String {
// This works because all functions have the same signature:
// (argc: Int32, argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>?) -> Int32
// The first part is the class name: _T0 + length + name. To change if not "OpenTerm"
return "_T08OpenTerm" + String(functionName.count) + functionName + "s5Int32VAD4argc_SpySpys4Int8VGSgGSg4argvtF"
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
Expand Down
15 changes: 1 addition & 14 deletions OpenTerm/Controller/TerminalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ class TerminalViewController: UIViewController {

NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground), name: .UIApplicationDidEnterBackground, object: nil)

initializeEnvironment()
replaceCommand("open-url", mangleFunctionName("openUrl"), true)
replaceCommand("share", mangleFunctionName("shareFile"), true)
replaceCommand("pbcopy", mangleFunctionName("pbcopy"), true)
replaceCommand("pbpaste", mangleFunctionName("pbpaste"), true)

// Call reloadData for the added commands.
terminalView.autoCompleteManager.reloadData()

Expand Down Expand Up @@ -167,13 +161,6 @@ class TerminalViewController: UIViewController {
self.overflowState = self.traitCollection.horizontalSizeClass == .compact ? .compact : .expanded
}

private func mangleFunctionName(_ functionName: String) -> String {
// This works because all functions have the same signature:
// (argc: Int32, argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>?) -> Int32
// The first part is the class name: _T0 + length + name. To change if not "OpenTerm"
return "_T08OpenTerm" + String(functionName.count) + functionName + "s5Int32VAD4argc_SpySpys4Int8VGSgGSg4argvtF"
}

func setSSLCertIfNeeded() {

guard let cString = getenv("SSL_CERT_FILE") else {
Expand Down Expand Up @@ -296,7 +283,7 @@ class TerminalViewController: UIViewController {
return [
// Navigation between commands
UIKeyCommand(input: UIKeyInputUpArrow, modifierFlags: UIKeyModifierFlags(rawValue: 0), action: #selector(selectPreviousCommand), discoverabilityTitle: "Previous command"),
UIKeyCommand(input: UIKeyInputDownArrow, modifierFlags: UIKeyModifierFlags(rawValue: 0), action: #selector(selectNextCommand), discoverabilityTitle: "Next command"),
UIKeyCommand(input: UIKeyInputDownArrow, modifierFlags: UIKeyModifierFlags(rawValue: 0), action: #selector(selectNextCommand), discoverabilityTitle: "Next command")
]
}

Expand Down
21 changes: 21 additions & 0 deletions OpenTerm/Util/Dispatch+Custom.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Dispatch+Custom.swift
// OpenTerm
//
// Created by Ian McDowell on 2/10/18.
// Copyright © 2018 Silver Fox. All rights reserved.
//

import Foundation

extension DispatchQueue {

/// Performs the given block on the main thread, without dispatching if already there.
static func performOnMain(_ block: @escaping () -> Void) {
if Thread.isMainThread {
block()
} else {
DispatchQueue.main.async(execute: block)
}
}
}
38 changes: 15 additions & 23 deletions OpenTerm/Util/Execution/CommandExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ class CommandExecutor {
private let stdin_pipe = Pipe()
private let stdout_pipe = Pipe()
private let stderr_pipe = Pipe()

// Files for pipes, passed to ios_system
fileprivate let stdin_file: UnsafeMutablePointer<FILE>
private let stdout_file: UnsafeMutablePointer<FILE>
private let stderr_file: UnsafeMutablePointer<FILE>
fileprivate let stdout_file: UnsafeMutablePointer<FILE>
fileprivate let stderr_file: UnsafeMutablePointer<FILE>

/// Context from commands run by this executor
private var context = CommandExecutionContext()
var context = CommandExecutionContext()

init() {
self.currentWorkingDirectory = DocumentManager.shared.activeDocumentsFolderURL
Expand All @@ -82,18 +84,13 @@ class CommandExecutor {

// Dispatch a new text-based command to execute.
func dispatch(_ command: String) {
let push_stdin = stdin
let push_stdout = stdout
let push_stderr = stderr

CommandExecutor.executionQueue.async {
self.state = .running

// Set the executor's CWD as the process-wide CWD
DocumentManager.shared.currentDirectoryURL = self.currentWorkingDirectory
stdin = self.stdin_file
stdout = self.stdout_file
stderr = self.stderr_file

let returnCode: ReturnCode
do {
let executorCommand = self.executorCommand(forCommand: command, inContext: self.context)
Expand All @@ -117,13 +114,10 @@ class CommandExecutor {
// Save return code into the context
self.context[.status] = "\(returnCode)"

// Write the end code to stdout_pipe
// TODO: Also need to send to stderr?
self.stdout_pipe.fileHandleForWriting.write(Parser.Code.endOfTransmission.rawValue.data(using: .utf8)!)

stdin = push_stdin
stdout = push_stdout
stderr = push_stderr
// Write the end code to stdout and stderr
let etx = Parser.Code.endOfTransmission.rawValue.data(using: .utf8)!
self.stdout_pipe.fileHandleForWriting.write(etx)
self.stderr_pipe.fileHandleForWriting.write(etx)

self.state = .idle
}
Expand Down Expand Up @@ -187,14 +181,12 @@ struct SystemExecutorCommand: CommandExecutorCommand {

func run(forExecutor executor: CommandExecutor) throws -> ReturnCode {

// Pass the value of the string to system, return its exit code.
let returnCode = ios_system(command.utf8CString)

// Flush pipes to make sure all data is read
fflush(stdout)
fflush(stderr)
thread_stdin = executor.stdin_file
thread_stdout = executor.stdout_file
thread_stderr = executor.stderr_file

return returnCode
// Pass the value of the string to system, return its exit code.
return ios_system(command.utf8CString)
}
}

Expand Down
1 change: 1 addition & 0 deletions OpenTerm/Util/History/HistoryManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class HistoryManager {
try command.write(to: historyFileURL, atomically: true, encoding: .utf8)
} else {
let fileHandle = try FileHandle.init(forWritingTo: historyFileURL)
fileHandle.seekToEndOfFile()
if let value = (command + "\n").data(using: .utf8) {
fileHandle.write(value)
}
Expand Down
Loading