v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-17 00:00:16 -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 (
// Translate
translator Translator
translator = NewTranslator()
// UI
app = tview.NewApplication()
src_box = tview.NewTextArea()

View File

@ -13,13 +13,20 @@ import (
)
const (
textURL = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=%s&tl=%s&dt=t&q=%s"
textURL = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=%s&tl=%s&dt=t&q=%s"
soundURL = "https://translate.google.com.vn/translate_tts?ie=UTF-8&q=%s&tl=%s&client=tw-ob"
)
type Translator struct {
srcLang string
dstLang string
srcLang string
dstLang string
soundLock *Lock
}
func NewTranslator() Translator {
return Translator{
soundLock: NewLock(),
}
}
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) {
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--
}