diff --git a/internal/cmd/environment.go b/internal/cmd/environment.go index 42530b82..5ebe5fe7 100644 --- a/internal/cmd/environment.go +++ b/internal/cmd/environment.go @@ -134,7 +134,7 @@ func storeSnapshotCmd() *cobra.Command { return "manual" }(), "Strategy for session selection. Options are manual, recent. Defaults to manual") - cmd.Flags().IntVar(&limit, "limit", 15, "Limit the number of lines") + cmd.Flags().IntVar(&limit, "limit", 50, "Limit the number of lines") cmd.Flags().BoolVarP(&all, "all", "A", false, "Show all lines") return &cmd diff --git a/internal/command/command_terminal.go b/internal/command/command_terminal.go index 5dca488c..786ca3ab 100644 --- a/internal/command/command_terminal.go +++ b/internal/command/command_terminal.go @@ -9,6 +9,11 @@ import ( "go.uber.org/zap" ) +var introMsg = []byte( + " # Runme terminal: Upon exit, exported environment variables will roll up into your session." + + " Type 'save' to add this session to the notebook.\n\n", +) + type terminalCommand struct { internalCommand @@ -48,14 +53,12 @@ func (c *terminalCommand) Start(ctx context.Context) (err error) { } } - if _, err := c.stdinWriter.Write([]byte(" eval $(runme beta env source --silent --insecure --export)\n clear\n")); err != nil { + if _, err := c.stdinWriter.Write([]byte(" eval $(runme beta env source --silent --insecure --export)\n alias save=\"exit\"\n clear\n")); err != nil { return err } // todo(sebastian): good enough for prototype; it makes more sense to write this message at the TTY-level - initMsg := []byte(" # Runme: This terminal forked your session. " + - "Upon exit exported environment variables will be rolled up into the session.\n\n") - _, err = c.stdinWriter.Write(initMsg) + _, err = c.stdinWriter.Write(introMsg) return err } diff --git a/internal/command/command_terminal_test.go b/internal/command/command_terminal_test.go index 77a50bf0..3b0412b1 100644 --- a/internal/command/command_terminal_test.go +++ b/internal/command/command_terminal_test.go @@ -62,6 +62,40 @@ func TestTerminalCommand_EnvPropagation(t *testing.T) { assert.Equal(t, []string{"TEST_ENV=1"}, session.GetAllEnv()) } +func TestTerminalCommand_Intro(t *testing.T) { + t.Parallel() + + session := NewSession() + stdinR, stdinW := io.Pipe() + stdout := bytes.NewBuffer(nil) + + factory := NewFactory(WithLogger(zaptest.NewLogger(t))) + + cmd, err := factory.Build( + &ProgramConfig{ + ProgramName: "bash", + Interactive: true, + Mode: runnerv2.CommandMode_COMMAND_MODE_TERMINAL, + }, + CommandOptions{ + Session: session, + StdinWriter: stdinW, + Stdin: stdinR, + Stdout: stdout, + }, + ) + require.NoError(t, err) + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + require.NoError(t, cmd.Start(ctx)) + + expectContainLine(t, stdout, "eval $(runme beta env source --silent --insecure --export)") + // todo(sebastian): why won't this work on docker? winsize? + // expectContainLine(t, stdout, strings.Trim(string(introMsg), " \r\n")) +} + func expectContainLine(t *testing.T, r io.Reader, expected string) { t.Helper()