Skip to content

Commit

Permalink
feat: settings for terminal exit warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Sep 20, 2024
1 parent ceea1de commit 4ff2f84
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pkg/cy/stories.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cfoust/cy/pkg/layout/split"
"github.com/cfoust/cy/pkg/mux"
S "github.com/cfoust/cy/pkg/mux/screen"
"github.com/cfoust/cy/pkg/params"
"github.com/cfoust/cy/pkg/stories"
)

Expand Down Expand Up @@ -39,6 +40,7 @@ func createStoryClient(ctx context.Context, cy *Cy) (client *Client, screen mux.
ctx,
client,
geom.DEFAULT_SIZE,
params.New(),
emu.WithoutHistory,
)

Expand Down
18 changes: 11 additions & 7 deletions pkg/mux/screen/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cfoust/cy/pkg/geom"
"github.com/cfoust/cy/pkg/geom/tty"
"github.com/cfoust/cy/pkg/mux"
"github.com/cfoust/cy/pkg/params"
"github.com/cfoust/cy/pkg/taro"

"github.com/charmbracelet/lipgloss"
Expand All @@ -25,6 +26,7 @@ type Terminal struct {
deadlock.RWMutex
*mux.UpdatePublisher
render *taro.Renderer
params *params.Parameters

terminal emu.Terminal
stream Stream
Expand Down Expand Up @@ -54,19 +56,19 @@ func (t *Terminal) State() *tty.State {
return state
}

message := "exited"

p := t.params
message := p.TerminalTextExited()
offsetStyle := t.render.NewStyle().
Foreground(lipgloss.Color("10")).
Background(lipgloss.Color("240"))
Foreground(p.ColorInfo()).
Background(lipgloss.Color("8"))

if realError, ok := exitError.(*exec.ExitError); ok {
offsetStyle = t.render.NewStyle().
Foreground(lipgloss.Color("9")).
Background(lipgloss.Color("240"))
Foreground(p.ColorError()).
Background(lipgloss.Color("8"))

message = fmt.Sprintf(
"exited (%d)",
message+" (%d)",
realError.ExitCode(),
)
}
Expand Down Expand Up @@ -164,6 +166,7 @@ func NewTerminal(
ctx context.Context,
stream Stream,
size Size,
params *params.Parameters,
options ...emu.TerminalOption,
) *Terminal {
options = append(options,
Expand All @@ -176,6 +179,7 @@ func NewTerminal(
terminal: emu.New(options...),
stream: stream,
render: taro.NewRenderer(),
params: params,
}

go func() {
Expand Down
8 changes: 7 additions & 1 deletion pkg/mux/screen/tree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cfoust/cy/pkg/geom"
"github.com/cfoust/cy/pkg/mux/screen"
"github.com/cfoust/cy/pkg/mux/stream"
"github.com/cfoust/cy/pkg/params"

"github.com/stretchr/testify/require"
)
Expand All @@ -20,7 +21,12 @@ func TestRoot(t *testing.T) {
func emptyPane(g *Group) *Pane {
return g.NewPane(
context.Background(),
screen.NewTerminal(context.Background(), stream.NewReader(), geom.DEFAULT_SIZE),
screen.NewTerminal(
context.Background(),
stream.NewReader(),
geom.DEFAULT_SIZE,
params.New(),
),
)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/params/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ type defaultParams struct {
SearchTextSearching string
// The text shown in the status bar when no matches are found.
SearchTextNoMatchesFound string
// The text shown when a terminal session exits.
TerminalTextExited string
}

var (
Expand Down Expand Up @@ -193,5 +195,6 @@ var (
SearchStatusBarBg: style.NewColor("4"),
SearchTextSearching: "searching",
SearchTextNoMatchesFound: "no matches found for",
TerminalTextExited: "exited",
}
)
47 changes: 47 additions & 0 deletions pkg/params/defaults_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/replay/replayable/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func New(
lifetime.Ctx(),
sessions.NewEventStream(stream, r.player),
geom.DEFAULT_SIZE,
params,
emu.WithoutHistory,
)

Expand Down

0 comments on commit 4ff2f84

Please sign in to comment.