Skip to content

Commit efe5cd6

Browse files
authored
refactor: rename --clear-screen/-on-detach to symmetric --clear-on-attach/--clear-on-detach (#432)
1 parent 2af1bbb commit efe5cd6

20 files changed

Lines changed: 131 additions & 131 deletions

cmd/config/env.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ var (
115115
//nolint:revive,gochecknoglobals,staticcheck // ignore linter warning about this variable
116116
SB_ATTACH_FULL_CAPTURE = DefineKV("SB_ATTACH_FULL_CAPTURE", "sb/attach/fullCapture")
117117
//nolint:revive,gochecknoglobals,staticcheck // ignore linter warning about this variable
118-
SB_ATTACH_CLEAR_SCREEN = DefineKV("SB_ATTACH_CLEAR_SCREEN", "sb/attach/clearScreen")
118+
SB_ATTACH_CLEAR_ON_ATTACH = DefineKV("SB_ATTACH_CLEAR_ON_ATTACH", "sb/attach/clearOnAttach")
119119
//nolint:revive,gochecknoglobals,staticcheck // ignore linter warning about this variable
120-
SB_ATTACH_CLEAR_SCREEN_ON_DETACH = DefineKV(
121-
"SB_ATTACH_CLEAR_SCREEN_ON_DETACH",
122-
"sb/attach/clearScreenOnDetach",
120+
SB_ATTACH_CLEAR_ON_DETACH = DefineKV(
121+
"SB_ATTACH_CLEAR_ON_DETACH",
122+
"sb/attach/clearOnDetach",
123123
)
124124
//nolint:revive,gochecknoglobals,staticcheck // ignore linter warning about this variable
125125
SB_DETACH_NAME = DefineKV("SB_DETACH_NAME", "sb/detach/name")
@@ -205,11 +205,11 @@ var (
205205
"sbsh.client.disableDetachKeystroke",
206206
)
207207
//nolint:revive,gochecknoglobals,staticcheck // ignore linter warning about this variable
208-
SBSH_CLIENT_CLEAR_SCREEN = DefineKV("SBSH_CLIENT_CLEAR_SCREEN", "sbsh.client.clearScreen")
208+
SBSH_CLIENT_CLEAR_ON_ATTACH = DefineKV("SBSH_CLIENT_CLEAR_ON_ATTACH", "sbsh.client.clearOnAttach")
209209
//nolint:revive,gochecknoglobals,staticcheck // ignore linter warning about this variable
210-
SBSH_CLIENT_CLEAR_SCREEN_ON_DETACH = DefineKV(
211-
"SBSH_CLIENT_CLEAR_SCREEN_ON_DETACH",
212-
"sbsh.client.clearScreenOnDetach",
210+
SBSH_CLIENT_CLEAR_ON_DETACH = DefineKV(
211+
"SBSH_CLIENT_CLEAR_ON_DETACH",
212+
"sbsh.client.clearOnDetach",
213213
)
214214

215215
//nolint:revive,gochecknoglobals,staticcheck // ignore linter warning about this variable

cmd/sb/attach/attach.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ func setupAttachCmdFlags(attachCmd *cobra.Command) {
176176
Bool("full-capture", false, "Replay the entire raw capture buffer on attach instead of repainting the current screen")
177177
_ = viper.BindPFlag(config.SB_ATTACH_FULL_CAPTURE.ViperKey, attachCmd.Flags().Lookup("full-capture"))
178178
attachCmd.Flags().
179-
Bool("clear-screen", false, "Clear the terminal before repainting the session screen on attach (legacy behavior); the default paints below existing content. No effect with --full-capture, whose replay is raw history")
180-
_ = viper.BindPFlag(config.SB_ATTACH_CLEAR_SCREEN.ViperKey, attachCmd.Flags().Lookup("clear-screen"))
179+
Bool("clear-on-attach", false, "Clear the terminal before repainting the session screen on attach (legacy behavior); the default paints below existing content. No effect with --full-capture, whose replay is raw history")
180+
_ = viper.BindPFlag(config.SB_ATTACH_CLEAR_ON_ATTACH.ViperKey, attachCmd.Flags().Lookup("clear-on-attach"))
181181
attachCmd.Flags().
182-
Bool("clear-screen-on-detach", false, "Erase the screen after detaching (^] twice or sb detach); the default leaves screen content untouched")
182+
Bool("clear-on-detach", false, "Erase the screen after detaching (^] twice or sb detach); the default leaves screen content untouched")
183183
_ = viper.BindPFlag(
184-
config.SB_ATTACH_CLEAR_SCREEN_ON_DETACH.ViperKey,
185-
attachCmd.Flags().Lookup("clear-screen-on-detach"),
184+
config.SB_ATTACH_CLEAR_ON_DETACH.ViperKey,
185+
attachCmd.Flags().Lookup("clear-on-detach"),
186186
)
187187
}
188188

@@ -210,8 +210,8 @@ func run(
210210

211211
disableDetach := viper.GetBool(config.SB_ATTACH_DISABLE_DETACH_KEYSTROKE.ViperKey)
212212
fullCapture := viper.GetBool(config.SB_ATTACH_FULL_CAPTURE.ViperKey)
213-
clearScreen := viper.GetBool(config.SB_ATTACH_CLEAR_SCREEN.ViperKey)
214-
clearScreenOnDetach := viper.GetBool(config.SB_ATTACH_CLEAR_SCREEN_ON_DETACH.ViperKey)
213+
clearOnAttach := viper.GetBool(config.SB_ATTACH_CLEAR_ON_ATTACH.ViperKey)
214+
clearOnDetach := viper.GetBool(config.SB_ATTACH_CLEAR_ON_DETACH.ViperKey)
215215

216216
logger.DebugContext(
217217
ctx,
@@ -222,10 +222,10 @@ func run(
222222
disableDetach,
223223
"full_capture",
224224
fullCapture,
225-
"clear_screen",
226-
clearScreen,
227-
"clear_screen_on_detach",
228-
clearScreenOnDetach,
225+
"clear_on_attach",
226+
clearOnAttach,
227+
"clear_on_detach",
228+
clearOnDetach,
229229
)
230230

231231
runErr := attach.Run(ctx, attach.Options{
@@ -235,8 +235,8 @@ func run(
235235
Stderr: os.Stderr,
236236
DisableDetachKeystroke: disableDetach,
237237
FullCapture: fullCapture,
238-
ClearScreen: clearScreen,
239-
ClearScreenOnDetach: clearScreenOnDetach,
238+
ClearOnAttach: clearOnAttach,
239+
ClearOnDetach: clearOnDetach,
240240
Logger: logger,
241241
})
242242
if runErr == nil || errors.Is(runErr, context.Canceled) || errors.Is(runErr, errdefs.ErrContextDone) {

cmd/sbsh/sbsh.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ You can also use sbsh with parameters. For example:
212212
TerminalSpec: terminalSpec,
213213
DetachKeystroke: !disableDetach, // Invert flag: when disable-detach is true, DetachKeystroke is false
214214
ClientMode: api.RunNewTerminal,
215-
ClearScreen: viper.GetBool(config.SBSH_CLIENT_CLEAR_SCREEN.ViperKey),
216-
ClearScreenOnDetach: viper.GetBool(
217-
config.SBSH_CLIENT_CLEAR_SCREEN_ON_DETACH.ViperKey,
215+
ClearOnAttach: viper.GetBool(config.SBSH_CLIENT_CLEAR_ON_ATTACH.ViperKey),
216+
ClearOnDetach: viper.GetBool(
217+
config.SBSH_CLIENT_CLEAR_ON_DETACH.ViperKey,
218218
),
219219
},
220220
}
@@ -315,16 +315,16 @@ func setClientFlags(rootCmd *cobra.Command) error {
315315
}
316316

317317
rootCmd.Flags().
318-
Bool("clear-screen", false, "Clear the terminal before painting the session screen (legacy behavior); the default paints below existing content")
319-
if err := viper.BindPFlag(config.SBSH_CLIENT_CLEAR_SCREEN.ViperKey, rootCmd.Flags().Lookup("clear-screen")); err != nil {
318+
Bool("clear-on-attach", false, "Clear the terminal before painting the session screen (legacy behavior); the default paints below existing content")
319+
if err := viper.BindPFlag(config.SBSH_CLIENT_CLEAR_ON_ATTACH.ViperKey, rootCmd.Flags().Lookup("clear-on-attach")); err != nil {
320320
return err
321321
}
322322

323323
rootCmd.Flags().
324-
Bool("clear-screen-on-detach", false, "Erase the screen after detaching (^] twice or sb detach); the default leaves screen content untouched")
324+
Bool("clear-on-detach", false, "Erase the screen after detaching (^] twice or sb detach); the default leaves screen content untouched")
325325
if err := viper.BindPFlag(
326-
config.SBSH_CLIENT_CLEAR_SCREEN_ON_DETACH.ViperKey,
327-
rootCmd.Flags().Lookup("clear-screen-on-detach"),
326+
config.SBSH_CLIENT_CLEAR_ON_DETACH.ViperKey,
327+
rootCmd.Flags().Lookup("clear-on-detach"),
328328
); err != nil {
329329
return err
330330
}

internal/client/clientrunner/io.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ func (sr *Exec) attach() error {
151151
var response struct{}
152152
sr.metadataMu.RLock()
153153
fullCapture := sr.metadata.Spec.FullCapture
154-
clearScreen := sr.metadata.Spec.ClearScreen
154+
clearOnAttach := sr.metadata.Spec.ClearOnAttach
155155
sr.metadataMu.RUnlock()
156156
conn, err := sr.terminalClient.Attach(
157157
sr.ctx,
158-
&api.AttachRequest{ClientID: sr.id, FullCapture: fullCapture, ClearScreen: clearScreen},
158+
&api.AttachRequest{ClientID: sr.id, FullCapture: fullCapture, ClearOnAttach: clearOnAttach},
159159
&response,
160160
)
161161
if err != nil {

internal/client/clientrunner/io_extra_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ func TestAttach_Success(t *testing.T) {
6868
},
6969
}
7070
sr.metadata.Spec.FullCapture = true
71-
sr.metadata.Spec.ClearScreen = true
71+
sr.metadata.Spec.ClearOnAttach = true
7272

7373
if err := sr.attach(); err != nil {
7474
t.Fatalf("attach: %v", err)
7575
}
76-
if gotReq == nil || gotReq.ClientID != sr.id || !gotReq.FullCapture || !gotReq.ClearScreen {
77-
t.Fatalf("attach request = %+v; want ClientID=%q FullCapture=true ClearScreen=true", gotReq, sr.id)
76+
if gotReq == nil || gotReq.ClientID != sr.id || !gotReq.FullCapture || !gotReq.ClearOnAttach {
77+
t.Fatalf("attach request = %+v; want ClientID=%q FullCapture=true ClearOnAttach=true", gotReq, sr.id)
7878
}
7979
if sr.ioConn != clientConn {
8080
t.Fatal("attach did not store the returned connection in ioConn")

internal/client/clientrunner/lifecycle.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,15 @@ func (sr *Exec) Detach() error {
236236
// funnel through here, so this is the only place the opt-in detach
237237
// clear applies; the Close()/process-exit paths always pass false.
238238
sr.metadataMu.RLock()
239-
clearScreen := sr.metadata.Spec.ClearScreenOnDetach
239+
clearOnDetach := sr.metadata.Spec.ClearOnDetach
240240
sr.metadataMu.RUnlock()
241241

242242
if err := sr.terminalClient.Detach(ctx, &sr.id); err != nil {
243243
sr.logger.Warn("Detach RPC failed; restoring parent terminal anyway", "client_id", sr.id, "error", err)
244244
// Suppress the "Detached" banner — it would be misleading when the RPC
245245
// failed — but the restore still runs. See #383. The opt-in clear still
246246
// applies: the user committed to detaching either way.
247-
sr.restoreParentTerminal("", clearScreen)
247+
sr.restoreParentTerminal("", clearOnDetach)
248248
return err
249249
}
250250

@@ -253,7 +253,7 @@ func (sr *Exec) Detach() error {
253253
// message so it is written after the inbound copier has drained (no
254254
// interleave with mid-flush remote bytes) but while raw mode is still active
255255
// so the embedded \r\n behaves. See issues #364 and #383.
256-
sr.restoreParentTerminal("\x1b[93m\r\nDetached\x1b[0m\r\n", clearScreen)
256+
sr.restoreParentTerminal("\x1b[93m\r\nDetached\x1b[0m\r\n", clearOnDetach)
257257

258258
return nil
259259
}

internal/client/clientrunner/restore_linux_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,13 @@ func TestDetach_CursorStaysAfterBanner(t *testing.T) {
380380
}
381381
}
382382

383-
// TestDetach_OptInClearScreen asserts --clear-screen-on-detach performs a real
383+
// TestDetach_OptInClearScreen asserts --clear-on-detach performs a real
384384
// screen erase — the \x1b[2J\x1b[H bytes on client stdout after the normalize
385385
// sequence — not merely a cursor-home.
386386
func TestDetach_OptInClearScreen(t *testing.T) {
387387
sr, _ := newAttachedExec(t)
388388
sr.terminalClient = &mockTerminalClient{}
389-
sr.metadata.Spec.ClearScreenOnDetach = true
389+
sr.metadata.Spec.ClearOnDetach = true
390390

391391
out := captureDetachOutput(t, sr)
392392

@@ -414,7 +414,7 @@ func TestDetach_OptInClearScreen_RPCFailure(t *testing.T) {
414414
sr.terminalClient = &mockTerminalClient{
415415
detachFunc: func(_ context.Context, _ *api.ID) error { return errMockDetach },
416416
}
417-
sr.metadata.Spec.ClearScreenOnDetach = true
417+
sr.metadata.Spec.ClearOnDetach = true
418418

419419
r, w, errPipe := os.Pipe()
420420
if errPipe != nil {

internal/client/clientrunner/terminal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const escRestoreParentTerm = "\x1b7" + // save cursor (DECSC) so ?1049l's DECRC
103103
"\x1b[?2004l" // disable bracketed paste
104104

105105
// escClearScreenHome is the full screen erase + cursor home the opt-in
106-
// --clear-screen-on-detach flag emits after escRestoreParentTerm — a real
106+
// --clear-on-detach flag emits after escRestoreParentTerm — a real
107107
// erase, not merely a cursor-home. See issue #425.
108108
const escClearScreenHome = "\x1b[2J\x1b[H"
109109

@@ -122,7 +122,7 @@ const escClearScreenHome = "\x1b[2J\x1b[H"
122122
//
123123
// clearScreen, when true, emits a full screen erase + home immediately after
124124
// the normalize sequence — the user-detach paths pass the opt-in
125-
// ClearScreenOnDetach spec value; the Close()/process-exit paths pass false
125+
// ClearOnDetach spec value; the Close()/process-exit paths pass false
126126
// so they keep the screen content untouched. See issue #425.
127127
func (sr *Exec) restoreParentTerminal(postDrainMsg string, clearScreen bool) {
128128
sr.restoreOnce.Do(func() {

internal/terminal/terminalrunner/connections_attach_paint_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestInitialAttachPaintRepaintsScreen(t *testing.T) {
4747
}
4848
}
4949

50-
// --clear-screen (clearScreen=true) restores the legacy clear-and-repaint
50+
// --clear-on-attach (clearScreen=true) restores the legacy clear-and-repaint
5151
// seed paint.
5252
func TestInitialAttachPaintClearScreen(t *testing.T) {
5353
sr := newScreenExec()

internal/terminal/terminalrunner/lifecycle.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ func (sr *Exec) Attach(req *api.AttachRequest, response *api.ResponseWithFD) err
496496
return fmt.Errorf("Attach: terminal not running")
497497
}
498498

499-
cliFD, err := sr.CreateNewClient(&req.ClientID, req.FullCapture, req.ClearScreen)
499+
cliFD, err := sr.CreateNewClient(&req.ClientID, req.FullCapture, req.ClearOnAttach)
500500
if err != nil {
501501
return err
502502
}
@@ -511,7 +511,7 @@ func (sr *Exec) Attach(req *api.AttachRequest, response *api.ResponseWithFD) err
511511
"Attach response",
512512
"id", req.ClientID,
513513
"fullCapture", req.FullCapture,
514-
"clearScreen", req.ClearScreen,
514+
"clearOnAttach", req.ClearOnAttach,
515515
"ok", payload.OK,
516516
"fds", fds,
517517
)

0 commit comments

Comments
 (0)