termsetup

package
v1.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package termsetup makes shift+Enter and ctrl+Enter work in the terminal interface.

A terminal sends the same byte for Enter, shift+Enter and ctrl+Enter, so the program cannot tell them apart; ctrl+j is the one newline key every terminal delivers. Terminals that support a keyboard protocol (kitty, WezTerm, Ghostty, recent Alacritty, iTerm2...) report the modifiers by themselves. Windows Terminal and the VS Code terminal do not, but they can be told to send the sequences the protocol uses for these two keys (ESC [ 13 ; 2 u and ESC [ 13 ; 5 u), which the interface already decodes. This package writes that setting.

Both files it edits are JSON with comments, so they are patched as text: what the user wrote is kept as it is, a backup is made first, and nothing is written unless the result still parses.

Index

Constants

View Source
const (
	// ShiftEnterSequence and CtrlEnterSequence are what the terminal is told to send.
	ShiftEnterSequence = "\x1b[13;2u"
	CtrlEnterSequence  = "\x1b[13;5u"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	DryRun bool
	GOOS   string
	Getenv func(string) string
}

Options controls Run.

type Result

type Result struct {
	Target string // "Windows Terminal", "VS Code"
	Path   string
	Status Status
	Backup string // path of the backup, when one was made
	Detail string
}

Result describes one target file.

func Run

func Run(opts Options) []Result

Run sets up every supported terminal found on this machine.

type Status

type Status string

Status is what happened to one file.

const (
	Added     Status = "added"     // the keys were written
	Already   Status = "already"   // the keys were already there
	Conflict  Status = "conflict"  // shift+enter is bound to something else: left alone
	WouldAdd  Status = "would-add" // dry run: the keys would be written
	NotFound  Status = "not-found" // no such terminal on this machine
	Failed    Status = "failed"
	Unchanged Status = "unchanged"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL