|
@@ -74,6 +74,11 @@ class ViewController: NSViewController, LocalProcessTerminalViewDelegate, NSUser
|
|
|
|
|
|
static var lastTerminal: LocalProcessTerminalView!
|
|
|
|
|
|
+ func getBufferAsData () -> Data
|
|
|
+ {
|
|
|
+ return terminal.getTerminal().getBufferAsData ()
|
|
|
+ }
|
|
|
+
|
|
|
func updateLogging ()
|
|
|
{
|
|
|
let path = logging ? "/Users/miguel/Downloads/Logs" : nil
|
|
@@ -193,6 +198,46 @@ class ViewController: NSViewController, LocalProcessTerminalViewDelegate, NSUser
|
|
|
terminal.allowMouseReporting.toggle ()
|
|
|
}
|
|
|
|
|
|
+ @objc @IBAction
|
|
|
+ func exportBuffer (_ source: AnyObject)
|
|
|
+ {
|
|
|
+ saveData { self.terminal.getTerminal().getBufferAsData () }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc @IBAction
|
|
|
+ func exportSelection (_ source: AnyObject)
|
|
|
+ {
|
|
|
+ saveData {
|
|
|
+ if let str = self.terminal.getSelection () {
|
|
|
+ return str.data (using: .utf8) ?? Data ()
|
|
|
+ }
|
|
|
+ return Data ()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func saveData (_ getData: @escaping () -> Data)
|
|
|
+ {
|
|
|
+ let savePanel = NSSavePanel ()
|
|
|
+ savePanel.canCreateDirectories = true
|
|
|
+ savePanel.allowedFileTypes = ["txt"]
|
|
|
+ savePanel.title = "Export Buffer Contents As Text"
|
|
|
+ savePanel.nameFieldStringValue = "TerminalCapture"
|
|
|
+
|
|
|
+ savePanel.begin { (result) in
|
|
|
+ if result.rawValue == NSApplication.ModalResponse.OK.rawValue {
|
|
|
+ let data = getData ()
|
|
|
+ if let url = savePanel.url {
|
|
|
+ do {
|
|
|
+ try data.write(to: url)
|
|
|
+ } catch let error as NSError {
|
|
|
+ let alert = NSAlert (error: error)
|
|
|
+ alert.runModal()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@objc @IBAction
|
|
|
func softReset (_ source: AnyObject)
|
|
|
{
|
|
@@ -297,6 +342,11 @@ class ViewController: NSViewController, LocalProcessTerminalViewDelegate, NSUser
|
|
|
m.state = terminal.optionAsMetaKey ? NSControl.StateValue.on : NSControl.StateValue.off
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // Only enable "Export selection" if we have a selection
|
|
|
+ if item.action == #selector(exportSelection(_:)) {
|
|
|
+ return terminal.selectionActive
|
|
|
+ }
|
|
|
return true
|
|
|
}
|
|
|
|