-
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.
Implement GoVarnam Inpue Method Engine (#2)
* Fix links * Improve build script * Remove individual binaries before new build * Ignore dylib * Add govarnam library * Disable AppSandbox for IME to register NSConnection. Reference: https://blog.inoki.cc/2021/06/19/Write-your-own-IME-on-macOS-1/ * IME works but no candidates yet * Candidate showing works! Return value from handle is very important! * Made improvements to candidate shower * Refactor: Remove unnecessary code * Remove clientmanager, inputcontroller dependency on lipika-engine * Cursor can now move left, right * Set default orientation vertical * Close window on Escape key * Select first candidate on enter key press * Add resources * Remove duplicate entries because candidatesWindow makes them hidden * candidate selection change doesn't work * Moving up/down in candidates window works * Add more resources * Select candidate based on cursor in candidate table
- Loading branch information
1 parent
4c3e48e
commit 7bb264c
Showing
14 changed files
with
417 additions
and
287 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "GoVarnam/govarnam"] | ||
path = GoVarnam/govarnam | ||
url = [email protected]:varnamproject/govarnam.git |
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 @@ | ||
*.dylib |
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,62 @@ | ||
// | ||
// Varnam.swift | ||
// VarnamIME | ||
// | ||
// Created by Subin on 13/11/21. | ||
// Copyright © 2021 VarnamProject. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct VarnamException: Error { | ||
let message: String | ||
|
||
init(_ message: String) { | ||
self.message = message | ||
} | ||
|
||
public var localizedDescription: String { | ||
return message | ||
} | ||
} | ||
|
||
public class Varnam { | ||
private var varnamHandle: Int32 = 0; | ||
|
||
internal init(_ schemeID: String = "ml") throws { | ||
schemeID.withCString { | ||
let rc = varnam_init_from_id(UnsafeMutablePointer(mutating: $0), &varnamHandle) | ||
try! checkError(rc) | ||
} | ||
} | ||
|
||
public func getLastError() -> String { | ||
return String(cString: varnam_get_last_error(varnamHandle)) | ||
} | ||
|
||
public func checkError(_ rc: Int32) throws { | ||
if (rc != VARNAM_SUCCESS) { | ||
throw VarnamException(getLastError()) | ||
} | ||
} | ||
|
||
public func transliterate(_ input: String) -> [String] { | ||
var arr: UnsafeMutablePointer<varray>? = varray_init() | ||
let cInput = (input as NSString).utf8String | ||
varnam_transliterate( | ||
varnamHandle, | ||
1, | ||
UnsafeMutablePointer(mutating: cInput), | ||
&arr | ||
) | ||
|
||
var results = [String]() | ||
for i in (0..<varray_length(arr)) { | ||
let sug = varray_get(arr, i).assumingMemoryBound(to: Suggestion.self | ||
) | ||
let word = String(cString: sug.pointee.Word) | ||
results.append(word) | ||
} | ||
return results | ||
} | ||
} |
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,5 @@ | ||
// | ||
// Use this file to import your target's public headers that you would like to expose to Swift. | ||
// | ||
|
||
#include "govarnam/libgovarnam.h" |
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,4 @@ | ||
cd govarnam | ||
make library-mac-universal | ||
install_name_tool -id @executable_path/../Frameworks/libgovarnam.dylib libgovarnam.dylib || exit 1 | ||
cp ./libgovarnam.dylib ../ |
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
Oops, something went wrong.