mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
fish: Detect UTF-8 output and open termcap/terminfo database.
Provide a generic mechanism within guestfish to detect if output if UTF-8 and to open the termcap (or terminfo) database for the current terminal type.
This commit is contained in:
35
fish/fish.c
35
fish/fish.c
@@ -30,6 +30,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <locale.h>
|
||||
#include <langinfo.h>
|
||||
#include <termios.h>
|
||||
|
||||
#ifdef HAVE_LIBREADLINE
|
||||
@@ -69,6 +70,7 @@ struct mp {
|
||||
char *mountpoint;
|
||||
};
|
||||
|
||||
static void set_up_terminal (void);
|
||||
static char add_drives (struct drv *drv, char next_drive);
|
||||
static void prepare_drives (struct drv *drv);
|
||||
static void mount_mps (struct mp *mp);
|
||||
@@ -96,6 +98,8 @@ int command_num = 0;
|
||||
int keys_from_stdin = 0;
|
||||
const char *libvirt_uri = NULL;
|
||||
int inspector = 0;
|
||||
int utf8_mode = 0;
|
||||
int have_terminfo = 0;
|
||||
|
||||
static void __attribute__((noreturn))
|
||||
usage (int status)
|
||||
@@ -159,6 +163,8 @@ main (int argc, char *argv[])
|
||||
bindtextdomain (PACKAGE, LOCALEBASEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
set_up_terminal ();
|
||||
|
||||
enum { HELP_OPTION = CHAR_MAX + 1 };
|
||||
|
||||
static const char *options = "a:c:d:Df:h::im:nN:rv?Vx";
|
||||
@@ -509,6 +515,35 @@ main (int argc, char *argv[])
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* The <term.h> header file which defines this has "issues". */
|
||||
extern int tgetent (char *, const char *);
|
||||
|
||||
static void
|
||||
set_up_terminal (void)
|
||||
{
|
||||
/* http://www.cl.cam.ac.uk/~mgk25/unicode.html#activate */
|
||||
utf8_mode = STREQ (nl_langinfo (CODESET), "UTF-8");
|
||||
|
||||
char *term = getenv ("TERM");
|
||||
if (term == NULL) {
|
||||
//fprintf (stderr, _("guestfish: TERM (terminal type) not defined.\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
int r = tgetent (NULL, term);
|
||||
if (r == -1) {
|
||||
fprintf (stderr, _("guestfish: could not access termcap or terminfo database.\n"));
|
||||
return;
|
||||
}
|
||||
if (r == 0) {
|
||||
fprintf (stderr, _("guestfish: terminal type \"%s\" not defined.\n"),
|
||||
term);
|
||||
return;
|
||||
}
|
||||
|
||||
have_terminfo = 1;
|
||||
}
|
||||
|
||||
void
|
||||
pod2text (const char *name, const char *shortdesc, const char *str)
|
||||
{
|
||||
|
||||
@@ -53,6 +53,8 @@ extern int read_only;
|
||||
extern int quit;
|
||||
extern int verbose;
|
||||
extern int command_num;
|
||||
extern int utf8_mode;
|
||||
extern int have_terminfo;
|
||||
extern const char *libvirt_uri;
|
||||
extern int issue_command (const char *cmd, char *argv[], const char *pipe);
|
||||
extern void pod2text (const char *name, const char *shortdesc, const char *body);
|
||||
|
||||
Reference in New Issue
Block a user