Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparing a beta release of Runme Terminal #673

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions internal/command/command_terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down
34 changes: 34 additions & 0 deletions internal/command/command_terminal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading