Browse Source

Fix something details at 2021-01-01 03:46

zry 3 years ago
parent
commit
7d2e75cc8e
2 changed files with 26 additions and 9 deletions
  1. 25 8
      hhc_mangekyo/user_view.go
  2. 1 1
      hhccli/terminal_handler.go

+ 25 - 8
hhc_mangekyo/user_view.go

@@ -42,14 +42,7 @@ func (uv *MangekyoUserView) makeTree() {
 			Description: v.Description,
 		}
 		end := &hhc_ast.SDTNode_End{
-			Exec: func(ectx *hhc_ast.ExecUserContext) {
-				fview := v.GetViewNameFunc
-				fprompt := v.GetPromptFunc
-				ftitle := v.GetTitleFunc
-				ectx.ChangeView(fview(uv.ctx))
-				ectx.ChangePrompt(fprompt(uv.ctx))
-				ectx.ChangeTitle(ftitle(uv.ctx))
-			},
+			Exec: uv.getViewChangeExecFunc(v),
 		}
 		cmd.AddEnd(end)
 		uv.treeroot.AddCommand(cmd)
@@ -90,6 +83,15 @@ func (uv *MangekyoUserView) addCommands() {
 	c_disp_termwidth.AddEnd(c_disp_termwidth_end)
 	c_disp.AddSubCommand(c_disp_termwidth)
 	uv.treeroot.AddCommand(c_disp)
+	c_exit := &hhc_ast.SDTNode_Command{
+		Name:        "exit",
+		Description: "Disconnect this session.",
+	}
+	c_exit_end := &hhc_ast.SDTNode_End{
+		Exec: uv.execExit,
+	}
+	c_exit.AddEnd(c_exit_end)
+	uv.treeroot.AddCommand(c_exit)
 }
 
 func (uv *MangekyoUserView) execDispTermwidth(ctx *hhc_ast.ExecUserContext) {
@@ -119,3 +121,18 @@ func (uv *MangekyoUserView) execTermwidth(ctx *hhc_ast.ExecUserContext) {
 	uv.cli.SetTerminalWidth(n)
 	ctx.ResultPrintSingleLineString(fmt.Sprintf("Terminal width set to %d.", n))
 }
+
+func (uv *MangekyoUserView) execExit(ctx *hhc_ast.ExecUserContext) {
+	uv.ctx.GetConn().Close()
+}
+
+func (uv *MangekyoUserView) getViewChangeExecFunc(v MangekyoCustomViewPortalCommandDefine) func(ectx *hhc_ast.ExecUserContext) {
+	return func(ectx *hhc_ast.ExecUserContext) {
+		fview := v.GetViewNameFunc
+		fprompt := v.GetPromptFunc
+		ftitle := v.GetTitleFunc
+		ectx.ChangeView(fview(uv.ctx))
+		ectx.ChangePrompt(fprompt(uv.ctx))
+		ectx.ChangeTitle(ftitle(uv.ctx))
+	}
+}

+ 1 - 1
hhccli/terminal_handler.go

@@ -124,7 +124,7 @@ func (ti *TerminalInteractive) SetCurrentView(viewClassName string) error {
 		ti.currentView = v
 	} else {
 		ti.currentView = nil
-		return fmt.Errorf("invalid vcn")
+		return fmt.Errorf("invalid vcn '%s'", viewClassName)
 	}
 	return nil
 }