aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os/job_defs.h
blob: 7fee900ac02650dd2c39459de6e77163d9dab2b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef NVIM_OS_JOB_DEFS_H
#define NVIM_OS_JOB_DEFS_H

#include <uv.h>
#include "nvim/os/rstream_defs.h"
#include "nvim/os/wstream_defs.h"

#define MAX_RUNNING_JOBS 100
typedef struct job Job;

/// Function called when the job reads data
///
/// @param id The job id
/// @param data Some data associated with the job by the caller
typedef void (*job_exit_cb)(Job *job, int status, void *data);

// Job startup options
// job_exit_cb Callback that will be invoked when the job exits
// maxmem Maximum amount of memory used by the job WStream
typedef struct {
  // Argument vector for the process. The first item is the
  // executable to run.
  // [consumed]
  char **argv;
  // Caller data that will be associated with the job
  void *data;
  // If true the job stdin will be available for writing with job_write,
  // otherwise it will be redirected to /dev/null
  bool writable;
  // Callback that will be invoked when data is available on stdout. If NULL
  // stdout will be redirected to /dev/null.
  rstream_cb stdout_cb;
  // Callback that will be invoked when data is available on stderr. If NULL
  // stderr will be redirected to /dev/null.
  rstream_cb  stderr_cb;
  // Callback that will be invoked when the job has exited and will not send
  // data
  job_exit_cb exit_cb;
  // Maximum memory used by the job's WStream
  size_t maxmem;
  // Connect the job to a pseudo terminal
  bool pty;
  // Initial window dimensions if the job is connected to a pseudo terminal
  uint16_t width, height;
  // Value for the $TERM environment variable. A default value of "ansi" is
  // assumed if NULL
  char *term_name;
} JobOptions;

#define JOB_OPTIONS_INIT ((JobOptions) {                     \
    .argv = NULL,                                            \
    .data = NULL,                                            \
    .writable = true,                                        \
    .stdout_cb = NULL,                                       \
    .stderr_cb = NULL,                                       \
    .exit_cb = NULL,                                         \
    .maxmem = 0,                                             \
    .pty = false,                                            \
    .width = 80,                                             \
    .height = 24,                                            \
    .term_name = NULL                                        \
    })
#endif  // NVIM_OS_JOB_DEFS_H