Skip to content

Commit

Permalink
Preparing a beta release of Runme Terminal (#673)
Browse files Browse the repository at this point in the history
Mostly cosmetic changes.
  • Loading branch information
sourishkrout authored Sep 24, 2024
1 parent 040b765 commit dc8d765
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
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

0 comments on commit dc8d765

Please sign in to comment.