interact.h 3.1 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
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
/* interact.h
 *
 * Interact with the user.
 *
 * $Id$*/

/* lsh, an implementation of the ssh protocol
 *
 * Copyright (C) 1999 Niels Mller
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef LSH_INTERACT_H_INCLUDED
#define LSH_INTERACT_H_INCLUDED

#include "lsh.h"

31
/* Forward declaration */
32
struct interact;
33
34
35
36
37
38
39
40
struct terminal_dimensions;

#define GABA_DECLARE
#include "interact.h.x"
#undef GABA_DECLARE

/* Abstract class defining methods needed to communicate with the
 * user's terminal. */
41
42
43
44
45
46

struct terminal_dimensions
{
  UINT32 char_width;
  UINT32 char_height;
  UINT32 pixel_width;
47
  UINT32 pixel_height;
48
49
};

50
51
52
53
54
55
56
57
58
59
60
/* GABA:
   (class
     (name terminal_attributes)
     (vars
       (make_raw method (object terminal_attributes))
       (encode method (string))))
*/

#define TERM_MAKE_RAW(t) ((t)->make_raw((t)))
#define TERM_ENCODE(t) ((t)->encode((t)))

61
62
63
64
/* GABA:
   (class
     (name window_change_callback)
     (vars
65
       (f method void "struct interact *i")))
66
67
68
69
*/

#define WINDOW_CHANGE_CALLBACK(c, i) ((c)->f((c), (i)))

70
71
/* GABA:
   (class
72
     (name interact)
73
74
75
     (vars
       (is_tty method int)
       ; (read_line method int "UINT32 size" "UINT8 *buffer")
76
       (read_password method (string)
77
78
79
80
81
82
                  "UINT32 max_length"
                  "struct lsh_string *prompt"
		  "int free")
       (yes_or_no method int
                  "struct lsh_string *prompt"
		  "int def" "int free")
83
84
85
86

       (get_attributes method (object terminal_attributes) )
       (set_attributes method int "struct terminal_attributes *attr")
       
87
88
89
       (window_size method int "struct terminal_dimensions *")
       (window_change_subscribe method (object resource)
		  "struct window_change_callback *callback")))
90
91
*/

92
93
94
95
96
97
#define INTERACT_IS_TTY(i) \
  ((i)->is_tty((i)))
#define INTERACT_READ_PASSWORD(i, l, p, f) \
  ((i)->read_password((i), (l), (p), (f)))
#define INTERACT_YES_OR_NO(i, p, d, f) \
  ((i)->yes_or_no((i), (p), (d), (f)))
98
99
100
101
#define INTERACT_GET_ATTRIBUTES(i) \
  ((i)->get_attributes((i)))
#define INTERACT_SET_ATTRIBUTES(i, t) \
  ((i)->set_attributes((i), (t)))
102
103
104
105
106
#define INTERACT_WINDOW_SIZE(i, d) \
  ((i)->window_size((i), (d)))
#define INTERACT_WINDOW_SUBSCRIBE(i, c) \
  ((i)->window_change_subscribe((i), (c)))

107
#if 0
Niels Möller's avatar
Niels Möller committed
108
109
110
111
112
extern int tty_fd;

int lsh_open_tty(void);
int tty_read_line(UINT32 size, UINT8 *buffer);
int yes_or_no(struct lsh_string *s, int def, int free);
113
114
115
116
#endif

struct interact *
make_unix_interact(struct io_backend *backend);
Niels Möller's avatar
Niels Möller committed
117
118

#endif /* LSH_INTERACT_H_INCLUDED */