12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package hhc_mangekyo
- import (
- "context"
- "fmt"
- "git.swzry.com/zry/go-hhc-cli/hhc_telws"
- "git.swzry.com/zry/go-hhc-cli/hhccli"
- )
- type MangekyoHandlerFactory struct {
- uhdl MangekyoUserLogicHandler
- mh *MangekyoHandler
- }
- type MangekyoHandler struct {
- fact *MangekyoHandlerFactory
- }
- func NewMangekyoHandlerFactory(handler MangekyoUserLogicHandler) *MangekyoHandlerFactory {
- mhf := &MangekyoHandlerFactory{
- uhdl: handler,
- }
- mhf.mh = &MangekyoHandler{
- fact: mhf,
- }
- return mhf
- }
- func (mhf *MangekyoHandlerFactory) GetSessionHandler() hhc_telws.TelwsSessionHandler {
- return mhf.mh
- }
- func (mh *MangekyoHandler) HandleConnection(ctx *hhc_telws.TelwsSessionContext) error {
- rw := ctx.GetReadWriter()
- dtitle := mh.fact.uhdl.GetDefaultTitle(ctx)
- _, _ = fmt.Fprintf(rw, "\033]0;%s\007", dtitle)
- _, _ = fmt.Fprintf(rw, "Welcome, %s.\r\n", ctx.GetUsername())
- cfg := hhccli.TerminalInteractiveConfig{
- InputStream: rw,
- OutputStream: rw,
- ErrorStream: rw,
- InitialTerminalWidth: 80,
- DebugLogFunction: func(lv hhccli.TerminalInteractiveDebugLogLevel, msg ...interface{}) {
- },
- InitialPrompt: mh.fact.uhdl.GetDefaultPromptString(ctx),
- BackspaceRune: '\x7F',
- }
- cli := hhccli.NewTerminalInteractive(cfg)
- rctx := context.Background()
- cvps := mh.fact.uhdl.GetCustomViewPortalCommands()
- uv := NewMangeKyoUserView(ctx, cvps, cli)
- cli.RegisterView("entry", uv)
- err := mh.fact.uhdl.NewSession(ctx, cli)
- if err != nil {
- return err
- }
- err = cli.SetCurrentView("entry")
- if err != nil {
- return err
- }
- err = cli.Run(rctx)
- return err
- }
|