-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
5 deletions.
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,30 @@ | ||
// | ||
// Copyright © 2019 Nikolai Abalov and contributors | ||
// | ||
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
// | ||
|
||
import Foundation | ||
|
||
final class ListPasteboardCommand: Command { | ||
var command: String = "list" | ||
|
||
var shortDescription: String = "List string and url pasteboard items" | ||
|
||
func run(with arguments: [String]) throws -> [Encodable] { | ||
return Pasteboard().list() | ||
} | ||
} | ||
|
||
final class DeletePasteboardCommand: Command { | ||
var command: String = "delete" | ||
|
||
var shortDescription: String = "Clear pasteboard" | ||
|
||
func run(with arguments: [String]) throws -> [Encodable] { | ||
Pasteboard().delete() | ||
|
||
return [] | ||
} | ||
} |
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,36 @@ | ||
// | ||
// Copyright © 2019 Nikolai Abalov and contributors | ||
// | ||
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
struct PasteboardItem: Codable { | ||
let type: String | ||
let value: String | ||
} | ||
|
||
class Pasteboard { | ||
func list() -> [PasteboardItem] { | ||
var items = [PasteboardItem]() | ||
|
||
let pasteboard = UIPasteboard.general | ||
|
||
for string in pasteboard.strings ?? [] { | ||
items.append(PasteboardItem(type: "string", value: string)) | ||
} | ||
|
||
for url in pasteboard.urls ?? [] { | ||
items.append(PasteboardItem(type: "url", value: url.absoluteString)) | ||
} | ||
|
||
return items | ||
} | ||
|
||
func delete() -> Void { | ||
UIPasteboard.general.items = [] | ||
} | ||
} |