Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * SHL - PTY Helpers |
| 3 | * |
| 4 | * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@gmail.com> |
| 5 | * Dedicated to the Public Domain |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * PTY Helpers |
| 10 | */ |
| 11 | |
| 12 | #ifndef SHL_PTY_H |
| 13 | #define SHL_PTY_H |
| 14 | |
| 15 | #include <errno.h> |
| 16 | #include <stdbool.h> |
| 17 | #include <stdint.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include <unistd.h> |
| 21 | |
| 22 | /* pty */ |
| 23 | |
| 24 | struct shl_pty; |
| 25 | |
Stéphane Marchesin | f8807af | 2014-08-18 10:34:41 -0700 | [diff] [blame] | 26 | typedef void (*shl_pty_input_cb) (struct shl_pty *pty, char *u8, |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 27 | size_t len, void *data); |
| 28 | |
| 29 | pid_t shl_pty_open(struct shl_pty **out, shl_pty_input_cb cb, void *data, |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 30 | unsigned short term_width, unsigned short term_height, |
| 31 | int pts_fd); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 32 | void shl_pty_ref(struct shl_pty *pty); |
| 33 | void shl_pty_unref(struct shl_pty *pty); |
| 34 | void shl_pty_close(struct shl_pty *pty); |
| 35 | |
| 36 | bool shl_pty_is_open(struct shl_pty *pty); |
| 37 | int shl_pty_get_fd(struct shl_pty *pty); |
| 38 | pid_t shl_pty_get_child(struct shl_pty *pty); |
| 39 | |
| 40 | int shl_pty_dispatch(struct shl_pty *pty); |
| 41 | int shl_pty_write(struct shl_pty *pty, const char *u8, size_t len); |
| 42 | int shl_pty_signal(struct shl_pty *pty, int sig); |
| 43 | int shl_pty_resize(struct shl_pty *pty, unsigned short term_width, |
| 44 | unsigned short term_height); |
| 45 | |
| 46 | /* pty bridge */ |
| 47 | |
| 48 | int shl_pty_bridge_new(void); |
| 49 | void shl_pty_bridge_free(int bridge); |
| 50 | |
| 51 | int shl_pty_bridge_dispatch(int bridge, int timeout); |
| 52 | int shl_pty_bridge_add(int bridge, struct shl_pty *pty); |
| 53 | void shl_pty_bridge_remove(int bridge, struct shl_pty *pty); |
| 54 | |
| 55 | #endif /* SHL_PTY_H */ |