Commit 08c8ca69 authored by Niels Möller's avatar Niels Möller
Browse files

* src/interact.h: New class abstract_interact (not yet used).

* src/interact.c: New class interact_unix, still #if:ed out.

Rev: src/interact.c:1.2
Rev: src/interact.h:1.2
parent 674ad514
......@@ -38,6 +38,89 @@
#include <errno.h>
#include <fcntl.h>
#if 0
/* GABA:
(class
(name interact_unix)
(super abstract_interact)
(vars
(tty_fd . int)
(dims . "struct terminal_dimensions")
(changed . sig_atomic_t)))
*/
static int
unix_is_tty(struct abstract_interact *s)
{
CAST(interact_unix, self, s);
return self->tty_fd >= 0;
}
/* FIXME: Rewrite to operate on tty_fd. */
static struct lsh_string *
unix_read_password(struct abstract_interact *s UNUSED,
int max_length UNUSED,
struct lsh_string *prompt, int free)
{
/* NOTE: Ignores max_length; instead getpass()'s limit applies. */
char *password;
prompt = make_cstring(prompt, free);
if (!prompt)
return 0;
/* NOTE: This function uses a static buffer. */
password = getpass(prompt->data);
lsh_string_free(prompt);
if (!password)
return 0;
return format_cstring(password);
}
static int
unix_yes_or_no(struct abstract_interact *s,
struct lsh_string *s, int def, int free)
{
CAST(interact_unix, self, s);
UINT8 buffer[TTY_BUFSIZE];
const struct exception *e;
if ( (self->tty_fd < 0) || quiet_flag)
{
if (free)
lsh_string_free(s);
return def;
}
e = write_raw(self->tty_fd, s->length, s->data);
if (free)
lsh_string_free(s);
if (e)
return def;
if (!tty_read_line(TTY_BUFSIZE, buffer))
return def;
switch (buffer[0])
{
case 'y':
case 'Y':
return 1;
default:
return 0;
}
}
#endif
int tty_fd = -1;
......
......@@ -28,6 +28,34 @@
#include "lsh.h"
/* Abstract class defining methods needed to comminucate with the
user's terminal. */
struct terminal_dimensions
{
UINT32 char_width;
UINT32 char_height;
UINT32 pixel_width;
UINT32 pixel_heght;
};
/* GABA:
(class
(name abstract_interact)
(vars
(is_tty method int)
; (read_line method int "UINT32 size" "UINT8 *buffer")
(read_password method string
"UINT32 max_length"
"struct lsh_string *prompt"
"int free")
(yes_or_no method int
"struct lsh_string *prompt"
"int def" "int free")
(window_change method int
"struct terminal_dimensions *d")))
*/
extern int tty_fd;
int lsh_open_tty(void);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment