/* Caracteristiques du terminal */
/* Copyright (C) 2008 Emmanuel Varoquaux
This file is part of XOS.
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 3 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, see . */
#include "terminal.h"
#include
#include
static int tty;
/* Sequences de controle */
static char seq_buf[64];
char cursor_home_seq[] = "\e[H";
char *cursor_up_seq(int n)
{
sprintf(seq_buf, "\e[%dA", n);
return seq_buf;
}
char *cursor_down_seq(int n)
{
sprintf(seq_buf, "\e[%dB", n);
return seq_buf;
}
char *cursor_forward_seq(int n)
{
sprintf(seq_buf, "\e[%dC", n);
return seq_buf;
}
char *cursor_backward_seq(int n)
{
sprintf(seq_buf, "\e[%dD", n);
return seq_buf;
}
char erase_end_of_line_seq[] = "\e[K";
char erase_screen_seq[] = "\e[2J";
/* Taille de l'ecran */
#define DEFAULT_SCREENWIDTH 80
#define DEFAULT_SCREENHEIGHT 24
int screenwidth;
int screenheight;
static void get_screensize()
{
int has_winsize;
struct winsize winsize;
has_winsize = ioctl(tty, TIOCGWINSZ, &winsize) == 0;
screenwidth = has_winsize && winsize.ws_col >= 2 ? winsize.ws_col : DEFAULT_SCREENWIDTH;
screenheight = has_winsize && winsize.ws_row >= 1 ? winsize.ws_row : DEFAULT_SCREENHEIGHT;
}
/* Initialisation */
void get_term_info()
{
tty = fileno(rl_instream);
get_screensize();
}
/* Cloche */
void ring_bell()
{
fputc('\a', stderr);
fflush(stderr);
}