CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-external-editor

Edit a string with the users preferred text editor using $VISUAL or $ENVIRONMENT

79

1.05x
Overview
Eval results
Files

task.mdevals/scenario-9/

Editor Lifecycle Manager

Provide a thin wrapper around a system text editor so callers can run synchronous or asynchronous editing sessions, read the edited content, observe the editor's exit status, and clean up the temporary file explicitly when needed.

Capabilities

Synchronous session with status

  • Launches the editor synchronously, returns the edited text plus the editor's exit status, and ensures the temporary file is removed after reading. @test

Callback-based asynchronous session

  • Launches the editor asynchronously, delivers either an error or the edited text and exit status through the provided callback, and cleans up the temporary file after the callback resolves. @test

Manual cleanup hook

  • Exposes a cleanup operation that callers can trigger without running the editor (for example after cancelling) and surfaces a failure if the temporary file cannot be removed. @test

Custom temporary file options

  • Accepts temporary file options (prefix, postfix, template, dir, mode) that are applied when creating the editable file for both sync and async launches. @test

Implementation

@generates

API

export interface TempFileOptions {
  prefix?: string;
  postfix?: string;
  template?: string;
  dir?: string;
  mode?: number;
}

export interface SessionResult {
  content: string;
  exitStatus: number;
  path: string;
}

export class EditorLifecycle {
  constructor(initialText?: string, fileOptions?: TempFileOptions);

  /**
   * Launch the editor synchronously and return edited content with exit status.
   */
  launchSync(): SessionResult;

  /**
   * Launch the editor asynchronously and invoke the callback with content and exit status.
   */
  launchAsync(callback: (err: Error | null, result?: SessionResult) => void): void;

  /**
   * Remove the temporary file even if no launch occurred.
   */
  discard(): void;
}

Dependencies { .dependencies }

external-editor { .dependency }

Uses an external editor library to manage launching, reading, exit status reporting, and cleanup for the temporary file.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-external-editor

tile.json