package main
import (
"context"
"math"
"time"
"github.com/pancsta/asyncmachine-go/internal/utils"
"github.com/pancsta/asyncmachine-go/pkg/helpers"
am "github.com/pancsta/asyncmachine-go/pkg/machine"
"github.com/pancsta/asyncmachine-go/tools/debugger"
ss "github.com/pancsta/asyncmachine-go/tools/debugger/states"
"github.com/pancsta/asyncmachine-go/tools/debugger/types"
"github.com/spf13/cobra"
)
var (
dataFile = "assets/asyncmachine-go/am-dbg-exports/pubsub-sim.gob.br"
logLevel = am .LogOps
filterLogLevel = am .LogChanges
startupMachine = "sim-p1"
startupTx = 27
initialView = "matrix"
playInterval = 200 * time .Millisecond
debugAddr = ""
stateNames = am .S {
"Start" ,
"IsDHT" ,
"Ready" ,
"IdentityReady" ,
"GenIdentity" ,
"BootstrapsConnected" ,
"EventHostConnected" ,
"Connected" ,
"Connecting" ,
"Disconnecting" ,
"JoiningTopic" ,
"TopicJoined" ,
"LeavingTopic" ,
"TopicLeft" ,
"SendingMsgs" ,
"MsgsSent" ,
"FwdToSim" ,
am .StateException ,
}
)
func main() {
rootCmd := types .RootCmd (cliRun )
err := rootCmd .Execute ()
if err != nil {
panic (err )
}
}
func cliRun(_ *cobra .Command , _ []string , p types .Params ) {
ctx := context .Background ()
p .LogLevel = logLevel
p .ImportData = dataFile
p .DebugAddr = debugAddr
dbg , err := debugger .New (ctx , debugger .Opts {
Filters : &debugger .OptsFilters {
LogLevel : filterLogLevel ,
},
ImportData : p .ImportData ,
DbgLogLevel : p .LogLevel ,
DbgLogger : types .GetLogger (&p , "" ),
AddrRpc : p .ListenAddr ,
EnableMouse : p .EnableMouse ,
EnableClipboard : p .EnableClipboard ,
Version : utils .GetVersion (),
Id : "video" ,
MaxMemMb : 1000 ,
})
if err != nil {
panic (err )
}
helpers .MachDebug (dbg .Mach , debugAddr , logLevel , false ,
&am .SemConfig {Full : true })
dbg .Start (startupMachine , startupTx , initialView , "" )
go render (dbg )
select {
case <- dbg .Mach .WhenDisposed ():
case <- dbg .Mach .WhenNot1 (ss .Start , nil ):
}
dbg .Dispose ()
}
func render(dbg *debugger .Debugger ) {
mach := dbg .Mach
<-mach .When1 (ss .Ready , nil )
time .Sleep (100 * time .Millisecond )
goFwd (mach , 20 )
mach .Add1 (ss .TreeMatrixView , nil )
goFwd (mach , 14 )
mach .Add1 (ss .TimelineStepsFocused , nil )
tx := dbg .NextTx ()
goFwdSteps (mach , len (tx .Steps )+1 )
tx = dbg .NextTx ()
ii := -1
for i := 0 ; i < len (tx .Steps ); i ++ {
ii = (ii + 1 ) % len (stateNames )
mach .Add1 (ss .StateNameSelected , am .A {"state" : stateNames [ii ]})
goFwdSteps (mach , 1 )
}
ii ++
for i := 0 ; i < len (tx .Steps ); i ++ {
ii = (ii - 1 ) % len (stateNames )
ii = int (math .Max (0 , float64 (ii )))
if ii > -1 {
mach .Add1 (ss .StateNameSelected , am .A {"state" : stateNames [ii ]})
} else {
mach .Remove1 (ss .StateNameSelected , nil )
}
goBackSteps (mach , 1 )
}
mach .Remove1 (ss .StateNameSelected , nil )
mach .Add (am .S {ss .TreeMatrixView , ss .MatrixRain }, nil )
mach .Add1 (ss .ClientListFocused , nil )
goBack (mach , 14 )
dbg .SetFilterLogLevel (am .LogOps )
mach .Add1 (ss .TreeLogView , nil )
goBack (mach , 14 )
SkipEnd ()
mach .Add1 (ss .LogTimestamps , nil )
dbg .SetFilterLogLevel (am .LogChanges )
mach .Add1 (ss .Toolbar1Focused , am .A {"filter" : debugger .ToolLogTimestamps })
goBack (mach , 1 )
time .Sleep (3 * time .Second )
mach .Dispose ()
}
func SkipEnd () {
playInterval = 200 * time .Millisecond
}
func SkipStart () {
playInterval = 10 * time .Millisecond
}
func goFwd(mach *am .Machine , amount int ) {
for i := 0 ; i < amount ; i ++ {
mach .Add1 (ss .Fwd , nil )
time .Sleep (playInterval )
}
}
func goBack(mach *am .Machine , amount int ) {
for i := 0 ; i < amount ; i ++ {
mach .Add1 (ss .Back , nil )
time .Sleep (playInterval )
}
}
func goFwdSteps(mach *am .Machine , amount int ) {
for i := 0 ; i < amount ; i ++ {
mach .Add1 (ss .FwdStep , nil )
time .Sleep (playInterval )
}
}
func goBackSteps(mach *am .Machine , amount int ) {
for i := 0 ; i < amount ; i ++ {
mach .Add1 (ss .BackStep , nil )
time .Sleep (playInterval )
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .