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:
parent
bf24cc548d
commit
4a666c3749
2
main.go
2
main.go
@ -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()
|
||||||
|
@ -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) {
|
||||||
|
22
utils.go
22
utils.go
@ -12,3 +12,25 @@ 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--
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user