-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add getClipboardText() * Add Clipboard protocol * Provide SDLClipboard implementation * Test clipboard interaction * Remove unused function Co-authored-by: Christian Treffs <[email protected]>
- Loading branch information
Showing
5 changed files
with
80 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// Clipboard.swift | ||
// Fireblade PAL | ||
// | ||
// Copyright © 2018-2021 Fireblade Team. All rights reserved. | ||
// Licensed under MIT License. See LICENSE file for details. | ||
|
||
public protocol Clipboard { | ||
/// Get UTF-8 text from the clipboard. | ||
func getText() throws -> String | ||
|
||
/// Put UTF-8 text into the clipboard. | ||
func setText(_ text: String) throws | ||
|
||
/// Query whether the clipboard exists and contains a non-empty text string. | ||
func hasText() -> Bool | ||
} |
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,34 @@ | ||
// | ||
// SDLClipboard.swift | ||
// Fireblade PAL | ||
// | ||
// Copyright © 2018-2021 Fireblade Team. All rights reserved. | ||
// Licensed under MIT License. See LICENSE file for details. | ||
|
||
#if FRB_PLATFORM_SDL | ||
|
||
@_implementationOnly import SDL2 | ||
|
||
public struct SDLClipboard: Clipboard { | ||
init() {} | ||
|
||
public func getText() throws -> String { | ||
guard let pText = SDL_GetClipboardText() else { | ||
throw SDLError() | ||
} | ||
defer { SDL_free(pText) } | ||
return String(cString: pText) | ||
} | ||
|
||
public func setText(_ text: String) throws { | ||
if SDL_SetClipboardText(text) < 0 { | ||
throw SDLError() | ||
} | ||
} | ||
|
||
public func hasText() -> Bool { | ||
SDL_HasClipboardText() == SDL_TRUE | ||
} | ||
} | ||
|
||
#endif |
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