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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
b71ca7e
Add Cub scripting prototype
louisdh Feb 6, 2018
3e5c199
Add Swiftlint
louisdh Feb 6, 2018
d9469d8
Merge branch 'master' into cub-scripting
louisdh Feb 6, 2018
3efef61
Fix pods
louisdh Feb 6, 2018
ae0c08a
Merge branch 'master' into cub-scripting
louisdh Feb 8, 2018
52c1bde
Merge branch 'master' into cub-scripting
louisdh Feb 8, 2018
2fffdc4
swiftlint autocorrect --format --use-tabs
louisdh Feb 8, 2018
31af3af
Update project
louisdh Feb 8, 2018
d9018d8
Merge branch 'master' into cub-scripting
louisdh Feb 8, 2018
58251e3
Add cub command
louisdh Feb 8, 2018
0497a67
Scripting rewrite
louisdh Feb 10, 2018
0eeeea1
Merge branch 'master' into cub-scripting
louisdh Feb 10, 2018
4d81534
Remove whitespace
louisdh Feb 10, 2018
350cb3f
Remove commented code
louisdh Feb 10, 2018
a1e9f43
Merge branch 'master' into cub-scripting
louisdh Feb 13, 2018
6113745
Move Cub.swift to Commands folder
louisdh Feb 13, 2018
4ab52c6
Merge branch 'master' into cub-scripting
louisdh Feb 13, 2018
334b81c
Update pods
louisdh Mar 2, 2018
6de7154
Fix error
louisdh Mar 2, 2018
e213773
Merge branch 'master' into cub-scripting
louisdh Mar 2, 2018
9c431ee
Add gitmodules
louisdh Mar 2, 2018
2657938
Fix submodule
louisdh Mar 2, 2018
00cabba
Fix text output styles from Cub
louisdh Mar 3, 2018
843ecc0
Fix output from Cub command
louisdh Mar 3, 2018
74f409d
TerminalView: Don't append text if empty string.
louisdh Mar 3, 2018
23b4c0d
Fix document type, NSUbiquitousContainerSupportedFolderLevels
louisdh Mar 3, 2018
be6138c
Add Cub input functions
louisdh Mar 3, 2018
25baa7d
Improve Cub error handling.
louisdh Mar 3, 2018
7397a45
Update Cub to v0.7.1
louisdh Mar 3, 2018
a30cfac
Fix print function.
louisdh Mar 3, 2018
e8595a3
Pod update
louisdh Mar 3, 2018
8f43801
Use SavannaKit master
louisdh Mar 3, 2018
de10325
Script edit view controller WIP
louisdh Mar 3, 2018
f472b27
Update SavannaKit
louisdh Mar 4, 2018
fbdd9e5
Cleanup
louisdh Mar 4, 2018
bf37aef
Add auto completer to script editor
louisdh Mar 4, 2018
fa639a2
Global scripts WIP
louisdh Mar 4, 2018
1bc31b8
Auto complete: don't skip hidden directories
louisdh Mar 4, 2018
f0d8d88
Fix panel background colors
louisdh Mar 4, 2018
1ed6881
Script editor: fix inputAssistantView style
louisdh Mar 5, 2018
47dc405
Script editor: auto completion cleanup
louisdh Mar 5, 2018
af286a4
Update SavannaKit
louisdh Mar 5, 2018
ffd43f9
Add "url" to Script class
louisdh Mar 6, 2018
07c6f58
Implement PanelContentDelegate on ScriptEditViewController
louisdh Mar 6, 2018
826de69
Fix Cub scripts calling Cub scripts
louisdh Mar 7, 2018
714f6dc
PanelKit fixes
louisdh Mar 7, 2018
3803d0f
Update SavannaKit
louisdh Mar 7, 2018
a1afac1
Set contentWrapperView's background color
louisdh Mar 7, 2018
8221a86
Merge branch 'master' into cub-scripting
louisdh Mar 7, 2018
4eed964
Add Savanna command
louisdh Mar 7, 2018
4c46f61
Only adjust script panel for keyboard if text view is first responder.
louisdh Mar 7, 2018
4d84b8a
Merge branch 'master' into cub-scripting
louisdh Mar 20, 2018
6380233
Fix typos
louisdh Mar 20, 2018
d3ce647
Merge branch 'master' into cub-scripting
louisdh Mar 22, 2018
046a8a0
Update dependencies
louisdh Mar 22, 2018
adee51d
Update test for Cub and Savanna commands.
louisdh Mar 22, 2018
dcfbe1d
Disable Main Thread Checker for tests.
louisdh Mar 22, 2018
38e956c
Merge branch 'master' into cub-scripting
louisdh Mar 31, 2018
84bba0c
Pridelands WIP
louisdh Apr 1, 2018
dfbd0b1
Merge branch 'master' into cub-scripting
louisdh Apr 1, 2018
69c233b
Script UI WIP
louisdh Apr 3, 2018
44e6d8a
Add HueKit
louisdh Apr 3, 2018
73cf0b0
Script UI WIP
louisdh Apr 4, 2018
7bd0313
Edit script metadata WIP
louisdh Apr 4, 2018
8c51310
Update pods
louisdh Apr 6, 2018
fde9985
Add PridelandDocument
louisdh Apr 6, 2018
d10471b
Remove local podspec
louisdh Apr 6, 2018
920a3e8
Prideland overview WIP
louisdh Apr 6, 2018
d001003
Prideland overviews reloading
louisdh Apr 6, 2018
681b33b
Cleanup
louisdh Apr 6, 2018
2d9db7e
Update colors
louisdh Apr 6, 2018
7e8c10c
Update ScriptEditViewController for prideland
louisdh Apr 6, 2018
bb2d54c
Fix auto complete crash
louisdh Apr 6, 2018
333086c
Script view controller: adjust for keyboard
louisdh Apr 6, 2018
09e7d55
Script auto complete: show correct titles.
louisdh Apr 6, 2018
7e8139d
Scripts: Update gradients.
louisdh Apr 7, 2018
8865972
Script metadata WIP
louisdh Apr 7, 2018
329d780
Restructure
louisdh Apr 8, 2018
38ae772
Move String utils to separate file
louisdh Apr 8, 2018
f3623ee
Restructure
louisdh Apr 8, 2018
6be15fa
Fix linting warning
louisdh Apr 8, 2018
4bbc75c
Remove unnecessary UIKit import
louisdh Apr 8, 2018
a42f4db
Cleanup
louisdh Apr 8, 2018
a8f514c
Refactor Cub script error handling
louisdh Apr 8, 2018
a37c6a7
Don't use TerminalView for script error output, use executor.delegate
louisdh Apr 8, 2018
fcdf334
No longer rely on TerminalView for script execution.
louisdh Apr 8, 2018
546d9d1
Fix share command
louisdh Apr 8, 2018
c1da715
Script create/update
louisdh Apr 8, 2018
49dcd77
Script saving
louisdh Apr 9, 2018
e8bbd39
Close script documents
louisdh Apr 9, 2018
c54edd6
Fix script executing, cleanup old scripting code.
louisdh Apr 9, 2018
7677a52
Remove Savanna command
louisdh Apr 9, 2018
30cf8bb
Fix test
louisdh Apr 9, 2018
4c535cf
Remove "Library" from scripts screen.
louisdh Apr 9, 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
106 changes: 77 additions & 29 deletions OpenTerm.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"color-space" : "display-p3",
"components" : {
"red" : "0x00",
"alpha" : "1.000",
"blue" : "0x00",
"green" : "0xDB"
"blue" : "0x6D",
"green" : "0xE9"
}
}
}
Expand Down
305 changes: 255 additions & 50 deletions OpenTerm/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions OpenTerm/Commands/Cub.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// 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 {

guard let tabViewContainer = UIApplication.shared.keyWindow?.rootViewController as? TabViewContainerViewController<TerminalTabViewController> else {
return 1
}

guard let activeVC = tabViewContainer.primaryTabViewController.visibleViewController as? TerminalViewController else {
return 1
}

let terminalView = activeVC.terminalView

let usage = "Usage: cub script.cub\n"

guard argc == 2 else {
fputs(usage, thread_stderr)
return 1
}

guard let fileName = argv?[1] else {
fputs(usage, thread_stderr)
return 1
}

let path = String(cString: fileName)

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(data: data, encoding: .utf8) else {
fputs("Missing file \"\(path)\"\n", thread_stderr)
return 1
}

let runner = Runner.runner(executor: terminalView.executor, executorDelegate: terminalView)

do {

try runner.run(source)

} catch {

terminalView.stderrParser.delegate = terminalView
terminalView.stdoutParser.delegate = terminalView

terminalView.executor.delegate = terminalView

if let error = error as? DisplayableError {

terminalView.writeOutput("Error occurred: \(error.description(inSource: source))")

} else {

terminalView.writeOutput("Unknown error occurred")

}

return 1
}

return 0
}
18 changes: 11 additions & 7 deletions OpenTerm/Commands/Share.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ public weak var shareFileViewController: UIViewController?
public func shareFile(argc: Int32, argv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>?) -> Int32 {
var itemsToShare = [Any]()

// share text from stdin when present
var bytes = [Int8]()
while stdin != thread_stdin {
var byte: Int8 = 0
let count = read(fileno(thread_stdin), &byte, 1)
guard count == 1 else {
break

if Int(argc) == 1 {

// share text from stdin when present
while stdin != thread_stdin {
var byte: Int8 = 0
let count = read(fileno(thread_stdin), &byte, 1)
guard count == 1 else {
break
}
bytes.append(byte)
}
bytes.append(byte)
}

let data = Data(bytes: bytes, count: bytes.count)
Expand Down
106 changes: 106 additions & 0 deletions OpenTerm/Controller/Scripting/PridelandCollectionViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// PridelandCollectionViewCell.swift
// OpenTerm
//
// Created by Louis D'hauwe on 01/04/2018.
// Copyright © 2018 Silver Fox. All rights reserved.
//

import UIKit

class PridelandCollectionViewCell: UICollectionViewCell {

let gradientLayer = CAGradientLayer()

@IBOutlet weak var titleLbl: UILabel!
@IBOutlet weak var descriptionLbl: UILabel!

override func awakeFromNib() {
super.awakeFromNib()

gradientLayer.colors = [UIColor.white.cgColor, UIColor.black.cgColor]
gradientLayer.startPoint = .zero
gradientLayer.endPoint = CGPoint(x: 1, y: 1)

self.contentView.layer.insertSublayer(gradientLayer, at: 0)

self.contentView.layer.cornerRadius = 16.0
self.contentView.layer.masksToBounds = true

}

override func layoutSubviews() {
super.layoutSubviews()

gradientLayer.frame = self.contentView.bounds

}

func show(_ prideland: PridelandOverview) {

titleLbl.text = prideland.metadata.name
descriptionLbl.text = prideland.metadata.description

let hue = CGFloat(prideland.metadata.hueTint)

updateGradient(hue: hue)

}

private func updateGradient(hue: CGFloat) {

let gradientColor1: UIColor
var gradientColor2: UIColor

let hue2: CGFloat

if hue < 0.1 {

hue2 = 1.0 - (0.1 - hue)

} else {

hue2 = hue - 0.1

}

if hue > 0.1 && hue < 0.6 {

gradientColor1 = UIColor(hue: hue, saturation: 1.0, brightness: 1.0, alpha: 1.0)
gradientColor2 = UIColor(hue: hue2, saturation: 0.9, brightness: 0.5, alpha: 1.0)

} else {

gradientColor1 = UIColor(hue: hue, saturation: 1.0, brightness: 1.0, alpha: 1.0)
gradientColor2 = UIColor(hue: hue2, saturation: 1.0, brightness: 1.0, alpha: 1.0)

}

var grayscale1: CGFloat = 0
var grayscale2: CGFloat = 0

gradientColor1.getWhite(&grayscale1, alpha: nil)
gradientColor2.getWhite(&grayscale2, alpha: nil)

if abs(grayscale1 - grayscale2) < 0.1 {

gradientColor2 = UIColor(hue: hue2, saturation: 0.8, brightness: 0.6, alpha: 1.0)
gradientColor2.getWhite(&grayscale2, alpha: nil)

}

// Gradient should always be light -> dark
if grayscale1 < grayscale2 {

gradientLayer.colors = [gradientColor2.cgColor, gradientColor1.cgColor]

} else {

gradientLayer.colors = [gradientColor1.cgColor, gradientColor2.cgColor]

}


}

}
64 changes: 64 additions & 0 deletions OpenTerm/Controller/Scripting/PridelandCollectionViewCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="PridelandCollectionViewCell" id="gTV-IL-0wX" customClass="PridelandCollectionViewCell" customModule="OpenTerm" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="281" height="139"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="281" height="139"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uXP-W8-rIG">
<rect key="frame" x="0.0" y="0.0" width="281" height="139"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="wbY-6H-ySy">
<rect key="frame" x="20" y="20" width="241" height="99"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dmw-TQ-GTC">
<rect key="frame" x="0.0" y="0.0" width="241" height="20"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" name="Menlo-Regular" family="Menlo" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalCompressionResistancePriority="749" text="Description of the command Description of the command Description of the command Description of the command" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XaG-UW-eSE">
<rect key="frame" x="0.0" y="20" width="241" height="79"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
</view>
<constraints>
<constraint firstItem="uXP-W8-rIG" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" id="8Dy-A6-OHY"/>
<constraint firstAttribute="trailing" secondItem="uXP-W8-rIG" secondAttribute="trailing" id="8St-tj-vHP"/>
<constraint firstAttribute="bottom" secondItem="wbY-6H-ySy" secondAttribute="bottom" constant="20" id="NUP-7B-2An"/>
<constraint firstItem="wbY-6H-ySy" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" constant="20" id="Q2r-FG-ubV"/>
<constraint firstAttribute="trailing" secondItem="wbY-6H-ySy" secondAttribute="trailing" constant="20" id="X4d-5h-4mK"/>
<constraint firstItem="uXP-W8-rIG" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" id="azP-oN-TaZ"/>
<constraint firstItem="wbY-6H-ySy" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" constant="20" id="e7I-TJ-5gq"/>
<constraint firstAttribute="bottom" secondItem="uXP-W8-rIG" secondAttribute="bottom" id="wJh-nn-3lZ"/>
</constraints>
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
<size key="customSize" width="281" height="139"/>
<connections>
<outlet property="descriptionLbl" destination="XaG-UW-eSE" id="jPa-Ar-aKg"/>
<outlet property="titleLbl" destination="dmw-TQ-GTC" id="4Wh-pQ-KLp"/>
</connections>
<point key="canvasLocation" x="-37.5" y="22.5"/>
</collectionViewCell>
</objects>
</document>
Loading