This repository has been archived by the owner on Feb 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 249
Add scripting, using Cub #75
Merged
Merged
Changes from 10 commits
Commits
Show all changes
94 commits
Select commit
Hold shift + click to select a range
b71ca7e
Add Cub scripting prototype
louisdh 3e5c199
Add Swiftlint
louisdh d9469d8
Merge branch 'master' into cub-scripting
louisdh 3efef61
Fix pods
louisdh ae0c08a
Merge branch 'master' into cub-scripting
louisdh 52c1bde
Merge branch 'master' into cub-scripting
louisdh 2fffdc4
swiftlint autocorrect --format --use-tabs
louisdh 31af3af
Update project
louisdh d9018d8
Merge branch 'master' into cub-scripting
louisdh 58251e3
Add cub command
louisdh 0497a67
Scripting rewrite
louisdh 0eeeea1
Merge branch 'master' into cub-scripting
louisdh 4d81534
Remove whitespace
louisdh 350cb3f
Remove commented code
louisdh a1e9f43
Merge branch 'master' into cub-scripting
louisdh 6113745
Move Cub.swift to Commands folder
louisdh 4ab52c6
Merge branch 'master' into cub-scripting
louisdh 334b81c
Update pods
louisdh 6de7154
Fix error
louisdh e213773
Merge branch 'master' into cub-scripting
louisdh 9c431ee
Add gitmodules
louisdh 2657938
Fix submodule
louisdh 00cabba
Fix text output styles from Cub
louisdh 843ecc0
Fix output from Cub command
louisdh 74f409d
TerminalView: Don't append text if empty string.
louisdh 23b4c0d
Fix document type, NSUbiquitousContainerSupportedFolderLevels
louisdh be6138c
Add Cub input functions
louisdh 25baa7d
Improve Cub error handling.
louisdh 7397a45
Update Cub to v0.7.1
louisdh a30cfac
Fix print function.
louisdh e8595a3
Pod update
louisdh 8f43801
Use SavannaKit master
louisdh de10325
Script edit view controller WIP
louisdh f472b27
Update SavannaKit
louisdh fbdd9e5
Cleanup
louisdh bf37aef
Add auto completer to script editor
louisdh fa639a2
Global scripts WIP
louisdh 1bc31b8
Auto complete: don't skip hidden directories
louisdh f0d8d88
Fix panel background colors
louisdh 1ed6881
Script editor: fix inputAssistantView style
louisdh 47dc405
Script editor: auto completion cleanup
louisdh af286a4
Update SavannaKit
louisdh ffd43f9
Add "url" to Script class
louisdh 07c6f58
Implement PanelContentDelegate on ScriptEditViewController
louisdh 826de69
Fix Cub scripts calling Cub scripts
louisdh 714f6dc
PanelKit fixes
louisdh 3803d0f
Update SavannaKit
louisdh a1afac1
Set contentWrapperView's background color
louisdh 8221a86
Merge branch 'master' into cub-scripting
louisdh 4eed964
Add Savanna command
louisdh 4c46f61
Only adjust script panel for keyboard if text view is first responder.
louisdh 4d84b8a
Merge branch 'master' into cub-scripting
louisdh 6380233
Fix typos
louisdh d3ce647
Merge branch 'master' into cub-scripting
louisdh 046a8a0
Update dependencies
louisdh adee51d
Update test for Cub and Savanna commands.
louisdh dcfbe1d
Disable Main Thread Checker for tests.
louisdh 38e956c
Merge branch 'master' into cub-scripting
louisdh 84bba0c
Pridelands WIP
louisdh dfbd0b1
Merge branch 'master' into cub-scripting
louisdh 69c233b
Script UI WIP
louisdh 44e6d8a
Add HueKit
louisdh 73cf0b0
Script UI WIP
louisdh 7bd0313
Edit script metadata WIP
louisdh 8c51310
Update pods
louisdh fde9985
Add PridelandDocument
louisdh d10471b
Remove local podspec
louisdh 920a3e8
Prideland overview WIP
louisdh d001003
Prideland overviews reloading
louisdh 681b33b
Cleanup
louisdh 2d9db7e
Update colors
louisdh 7e8c10c
Update ScriptEditViewController for prideland
louisdh bb2d54c
Fix auto complete crash
louisdh 333086c
Script view controller: adjust for keyboard
louisdh 09e7d55
Script auto complete: show correct titles.
louisdh 7e8139d
Scripts: Update gradients.
louisdh 8865972
Script metadata WIP
louisdh 329d780
Restructure
louisdh 38ae772
Move String utils to separate file
louisdh f3623ee
Restructure
louisdh 6be15fa
Fix linting warning
louisdh 4bbc75c
Remove unnecessary UIKit import
louisdh a42f4db
Cleanup
louisdh a8f514c
Refactor Cub script error handling
louisdh a37c6a7
Don't use TerminalView for script error output, use executor.delegate
louisdh fcdf334
No longer rely on TerminalView for script execution.
louisdh 546d9d1
Fix share command
louisdh c1da715
Script create/update
louisdh 49dcd77
Script saving
louisdh e8bbd39
Close script documents
louisdh c54edd6
Fix script executing, cleanup old scripting code.
louisdh 7677a52
Remove Savanna command
louisdh 30cf8bb
Fix test
louisdh 4c535cf
Remove "Library" from scripts screen.
louisdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
// | ||
// Cub.swift | ||
// OpenTerm | ||
// | ||
// Created by Louis D'hauwe on 03/02/2018. | ||
// Copyright © 2018 Silver Fox. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Cub | ||
import ios_system | ||
import TabView | ||
|
||
public func cub(argc: Int32, argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>?) -> Int32 { | ||
|
||
let tabViewContainer = UIApplication.shared.keyWindow?.rootViewController as! TabViewContainerViewController<TerminalTabViewController> | ||
|
||
guard let activeVC = tabViewContainer.primaryTabViewController.visibleViewController as? TerminalViewController else { | ||
return 0 | ||
} | ||
|
||
activeVC.terminalView.isExecutingScript = true | ||
let executor = activeVC.terminalView.executor | ||
|
||
guard argc == 2 else { | ||
fputs("Usage: cub script.cub\n", thread_stderr) | ||
return 1 | ||
} | ||
|
||
guard let fileName = argv?[1] else { | ||
fputs("Usage: cub script.cub\n", thread_stderr) | ||
return 1 | ||
} | ||
|
||
let path = String(cString: fileName) | ||
|
||
guard FileManager.default.fileExists(atPath: path) else { | ||
fputs("Missing file \(path)\n", thread_stderr) | ||
return 1 | ||
} | ||
|
||
let url = URL(fileURLWithPath: path) | ||
|
||
guard let data = FileManager.default.contents(atPath: url.path) else { | ||
fputs("Missing file \(path)\n", thread_stderr) | ||
return 1 | ||
} | ||
|
||
guard let source = String.init(data: data, encoding: .utf8) else { | ||
fputs("Missing file \(path)\n", thread_stderr) | ||
return 1 | ||
} | ||
|
||
let runner = Runner(logDebug: true, logTime: false) | ||
|
||
runner.registerExternalFunction(name: "print", argumentNames: ["input"], returns: false) { (arguments, callback) in | ||
|
||
for (name, arg) in arguments { | ||
fputs("\(arg)\n", thread_stdout) | ||
} | ||
|
||
callback(nil) | ||
return | ||
} | ||
|
||
runner.registerExternalFunction(name: "exec", argumentNames: ["command"], returns: true) { (arguments, callback) in | ||
|
||
var arguments = arguments | ||
|
||
guard let command = arguments.removeValue(forKey: "command") else { | ||
callback(.number(1)) | ||
return | ||
} | ||
|
||
guard case let .string(commandStr) = command else { | ||
callback(.number(1)) | ||
return | ||
} | ||
|
||
print("run command: \(commandStr)") | ||
|
||
// executor.dispatch(commandStr, callback: { (code) in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will you end up doing here for execution? Will you need to add a callback? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added CubCommandExecutor, which conforms to CommandExecutorDelegate and ParserDelegate. It takes a TerminalView and temporarily sets itself as the delegates. |
||
// | ||
// print("did run command: \(commandStr) -> \(code)") | ||
// | ||
// DispatchQueue.main.async { | ||
// | ||
// callback(.number(Double(code))) | ||
// } | ||
// | ||
// }) | ||
|
||
} | ||
|
||
runner.registerExternalFunction(name: "format", argumentNames: ["input", "arg"], returns: true) { (arguments, callback) in | ||
|
||
var arguments = arguments | ||
|
||
guard let input = arguments.removeValue(forKey: "input") else { | ||
callback(.string("")) | ||
return | ||
} | ||
|
||
guard case let .string(inputStr) = input else { | ||
callback(.string("")) | ||
return | ||
} | ||
|
||
var otherValues = arguments.values | ||
|
||
var varArgs = [CVarArg]() | ||
|
||
for value in otherValues { | ||
|
||
switch value { | ||
case .bool(let b): | ||
break | ||
case .number(let n): | ||
varArgs.append(n) | ||
case .string(let str): | ||
varArgs.append(str) | ||
case .struct: | ||
break | ||
} | ||
|
||
} | ||
|
||
let output = String(format: inputStr, arguments: varArgs) | ||
|
||
callback(.string(output)) | ||
return | ||
} | ||
|
||
print("run") | ||
|
||
do { | ||
|
||
runner.executionFinishedCallback = { | ||
|
||
print("executionFinishedCallback") | ||
|
||
DispatchQueue.main.async { | ||
|
||
activeVC.terminalView.isExecutingScript = false | ||
// activeVC.terminalView.isWaitingForCommand = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR #82 adds an enum state to the terminal, currently running or idle. Use that instead of adding this boolean. |
||
|
||
// activeVC.terminalView.commandExecutor(executor, didFinishDispatchWithExitCode: 0) | ||
// activeVC.terminalView.commandE | ||
} | ||
|
||
} | ||
|
||
try runner.run(source) | ||
|
||
} catch { | ||
return 1 | ||
} | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't check in the commented out lines in this file, but it's up to you.