mirror of
https://github.com/zoriya/jjui.git
synced 2026-08-16 02:44:50 +00:00
feat(preview): set preview subprocess size via env (#608)
* Set preview subprocess size via env
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
type CommandRunner interface {
|
||||
RunCommandImmediate(args []string) ([]byte, error)
|
||||
RunCommandImmediateWithEnv(args []string, env []string) ([]byte, error)
|
||||
RunCommandStreaming(ctx context.Context, args []string) (*StreamingCommand, error)
|
||||
RunCommand(args []string, continuations ...tea.Cmd) tea.Cmd
|
||||
RunCommandWithInput(args []string, input string, continuations ...tea.Cmd) tea.Cmd
|
||||
@@ -35,9 +36,12 @@ type MainCommandRunner struct {
|
||||
|
||||
func (a *MainCommandRunner) nextID() int { return int(a.idCounter.Add(1)) }
|
||||
|
||||
func (a *MainCommandRunner) RunCommandImmediate(args []string) ([]byte, error) {
|
||||
func (a *MainCommandRunner) RunCommandImmediateWithEnv(args []string, env []string) ([]byte, error) {
|
||||
c := exec.Command("jj", args...)
|
||||
c.Dir = a.Location
|
||||
if len(env) > 0 {
|
||||
c.Env = append(os.Environ(), env...)
|
||||
}
|
||||
if output, err := c.Output(); err != nil {
|
||||
var exitError *exec.ExitError
|
||||
if errors.As(err, &exitError) {
|
||||
@@ -49,6 +53,10 @@ func (a *MainCommandRunner) RunCommandImmediate(args []string) ([]byte, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *MainCommandRunner) RunCommandImmediate(args []string) ([]byte, error) {
|
||||
return a.RunCommandImmediateWithEnv(args, nil)
|
||||
}
|
||||
|
||||
func (a *MainCommandRunner) RunCommandStreaming(ctx context.Context, args []string) (*StreamingCommand, error) {
|
||||
c := exec.CommandContext(ctx, "jj", args...)
|
||||
c.Dir = a.Location
|
||||
|
||||
@@ -219,7 +219,14 @@ func (m *Model) refreshPreviewForItem(item common.SelectedItem) tea.Cmd {
|
||||
})
|
||||
}
|
||||
|
||||
output, _ := m.context.RunCommandImmediate(args)
|
||||
env := []string{
|
||||
// The preview subprocess does not run in a pane-sized PTY, so let
|
||||
// width-sensitive tools like `jj diff` see the preview size via the
|
||||
// conventional terminal size environment variables.
|
||||
"COLUMNS=" + strconv.Itoa(m.view.Width()),
|
||||
"LINES=" + strconv.Itoa(m.view.Height()),
|
||||
}
|
||||
output, _ := m.context.RunCommandImmediateWithEnv(args, env)
|
||||
return updatePreviewContentMsg{
|
||||
Content: string(output),
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ func (t *CommandRunner) RunCommandImmediate(args []string) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (t *CommandRunner) RunCommandImmediateWithEnv(args []string, _ []string) ([]byte, error) {
|
||||
return t.RunCommandImmediate(args)
|
||||
}
|
||||
|
||||
func (t *CommandRunner) RunCommandStreaming(_ context.Context, args []string) (*appContext.StreamingCommand, error) {
|
||||
reader, err := t.RunCommandImmediate(args)
|
||||
return &appContext.StreamingCommand{
|
||||
|
||||
Reference in New Issue
Block a user