v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-17 08:10:22 -07:00

feat: lock in translator

This commit is contained in:
eeeXun 2022-10-23 11:38:12 +08:00
parent bf24cc548d
commit 4a666c3749
3 changed files with 34 additions and 5 deletions

View File

@ -7,7 +7,7 @@ import (
var ( var (
// Translate // Translate
translator Translator translator = NewTranslator()
// UI // UI
app = tview.NewApplication() app = tview.NewApplication()
src_box = tview.NewTextArea() src_box = tview.NewTextArea()

View File

@ -20,6 +20,13 @@ const (
type Translator struct { type Translator struct {
srcLang string srcLang string
dstLang string dstLang string
soundLock *Lock
}
func NewTranslator() Translator {
return Translator{
soundLock: NewLock(),
}
} }
func (t Translator) Translate(message string) (string, error) { func (t Translator) Translate(message string) (string, error) {

View File

@ -10,5 +10,27 @@ func IndexOf(candidate string, arr []string) int {
} }
func SetTermTitle(title string) { func SetTermTitle(title string) {
print("\033]0;" , title , "\007") print("\033]0;", title, "\007")
}
type Lock struct {
stop bool
threadCount int8
}
func NewLock() *Lock {
return &Lock{
stop: true,
threadCount: 0,
}
}
func (l *Lock) Aquire() {
l.stop = false
l.threadCount++
}
func (l *Lock) Release() {
l.stop = true
l.threadCount--
} }