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

Add scripting, using Cub #75

Merged
merged 94 commits into from
Apr 9, 2018
Merged

Add scripting, using Cub #75

merged 94 commits into from
Apr 9, 2018

Conversation

louisdh
Copy link
Owner

@louisdh louisdh commented Feb 6, 2018

Not ready to be merged yet, but having this pull request is a nice way of detecting any merge conflicts.

@louisdh louisdh self-assigned this Feb 6, 2018
@louisdh louisdh mentioned this pull request Feb 6, 2018
@@ -30,6 +30,10 @@ extension String {

}

let executor = CommandExecutor()

var activeVC: ViewController!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of the above lines conflict with the Tabs change, which will introduce multiple ViewController instances, and moves executor to the TerminalView.

To get the visible view controller, there is an API on the TerminalTabViewController called visibleViewController


DispatchQueue.main.async {

callback(.number(Double(code)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not care about the output of the command, just the return code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to create a class conforming to CommandExecutorCommand, then create your own TerminalExecutor and become its delegate, instead of using the visible view controller's executor.


do {

activeVC.terminalView.isExecutingScript = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isExecutingScript and isWaitingForCommand should probably be put into an enum TerminalState.

Looks like they are used only to determine whether or not to write the prompt, so some refactoring would probably be able to remove the need for these anyways.

@@ -46,6 +46,8 @@ class CommandExecutor {
/// Context from commands run by this executor
private var context = CommandExecutionContext()

private var commandExecutedCallback: ((ReturnCode) -> Void)?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, we should either use delegate pattern or callback pattern, not both.

#71 moves the "command finished" delegate method into the Parser class as parserDidEndTransmission, so this will conflict.

This was done because the command will return a status code, but stdout will most likely come into the pipe afterwards, then is parsed on a different thread, and finally output will be printed to the text view. Only after that should a new prompt be drawn, so the parserDidEndTransmission is called when the Parser finishes a command, which is after the command exits.

If you only care about the exit code (as you currently do), then adding a callback here would be fine, as it would be called at a different time than the Parser delegate parserDidEndTransmission, but if you want to capture output, more work will be required, and putting a callback here would not be smart.

# Conflicts:
#	OpenTerm.xcodeproj/project.pbxproj
#	OpenTerm/Controller/Scripting/ScriptEditViewController.swift
#	OpenTerm/Controller/ViewController.swift
#	OpenTerm/Util/Execution/CommandExecutor.swift
#	OpenTerm/View/TerminalView.swift
#	Podfile
#	Podfile.lock
#	Pods/Manifest.lock
#	Pods/Pods.xcodeproj/project.pbxproj
#	Pods/Target Support Files/Pods-OpenTerm/Pods-OpenTerm-frameworks.sh
#	Pods/Target Support Files/Pods-OpenTerm/Pods-OpenTerm.debug.xcconfig
#	Pods/Target Support Files/Pods-OpenTerm/Pods-OpenTerm.release.xcconfig
@louisdh
Copy link
Owner Author

louisdh commented Feb 8, 2018

fyi: I've already added Cub and SavannaKit in master. Makes the diff from this PR a bit nicer (as well as fixing merge conflicts).


func didChangeText(_ syntaxTextView: SyntaxTextView) {
save()
// autoCompleteManager.reloadData()
Copy link
Contributor

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.


print("run command: \(commandStr)")

// executor.dispatch(commandStr, callback: { (code) in
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Owner Author

Choose a reason for hiding this comment

The 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.

DispatchQueue.main.async {

activeVC.terminalView.isExecutingScript = false
// activeVC.terminalView.isWaitingForCommand = false
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

self.terminalView.stderrParser.delegate = nil
self.terminalView.stdoutParser.delegate = nil

self.terminalView.executor.delegate = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's safe to modify these delegates. This will have a conflict with PR #85, which moves the parsers down to a lower level.

@louisdh louisdh changed the title [WIP] Add Cub scripting Add scripting, using Cub Apr 9, 2018
@louisdh
Copy link
Owner Author

louisdh commented Apr 9, 2018

Scripting is now stable, further work will happen on master.

@louisdh louisdh merged commit 06d2d03 into master Apr 9, 2018
@louisdh louisdh deleted the cub-scripting branch April 9, 2018 19:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants