Have got text transformations working
This commit is contained in:
parent
9f2fa96b92
commit
41daf7cfc9
14 changed files with 178 additions and 17 deletions
33
app.go
33
app.go
|
|
@ -2,7 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"lmika.dev/pkg/modash/moslice"
|
||||
)
|
||||
|
||||
// App struct
|
||||
|
|
@ -22,6 +25,30 @@ func (a *App) startup(ctx context.Context) {
|
|||
}
|
||||
|
||||
// Greet returns a greeting for the given name
|
||||
func (a *App) Greet(name string) string {
|
||||
return fmt.Sprintf("Hello %s, It's show time!", name)
|
||||
func (a *App) ProcessText(req ProcessTextRequest) {
|
||||
filter, ok := TextFilters[req.Action]
|
||||
if !ok {
|
||||
log.Printf("Unknown filter: [%s]", req.Action)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := moslice.MapWithError(req.Input, func(span TextSpan) (TextSpan, error) {
|
||||
outStr, err := filter(span.Text)
|
||||
if err != nil {
|
||||
return TextSpan{}, err
|
||||
}
|
||||
return TextSpan{
|
||||
Text: outStr,
|
||||
Pos: span.Pos,
|
||||
Len: span.Len,
|
||||
}, nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Error running filter: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
runtime.EventsEmit(a.ctx, "process-text-response", ProcessTextResponse{
|
||||
Output: resp,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue