📄 terminal.c
字号:
/* terminal.c -- How to handle the physical terminal for Info. $Id: terminal.c,v 1.1.1.3 1998/03/24 18:20:18 law Exp $ Copyright (C) 1988, 89, 90, 91, 92, 93, 96, 97, 98 Free Software Foundation, Inc. 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, 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. Written by Brian Fox (bfox@ai.mit.edu). */#include "info.h"#include "terminal.h"#include "termdep.h"#include <sys/types.h>#include <signal.h>/* The Unix termcap interface code. */#ifdef HAVE_NCURSES_TERMCAP_H#include <ncurses/termcap.h>#else#ifdef HAVE_TERMCAP_H#include <termcap.h>#else/* On Solaris2, sys/types.h #includes sys/reg.h, which #defines PC. Unfortunately, PC is a global variable used by the termcap library. */#undef PC/* Termcap requires these variables, whether we access them or not. */char *BC, *UP;char PC; /* Pad character */short ospeed; /* Terminal output baud rate */extern int tgetnum (), tgetflag (), tgetent ();extern char *tgetstr (), *tgoto ();extern void tputs ();#endif /* not HAVE_TERMCAP_H */#endif /* not HAVE_NCURSES_TERMCAP_H *//* Function "hooks". If you make one of these point to a function, that function is called when appropriate instead of its namesake. Your function is called with exactly the same arguments that were passed to the namesake function. */VFunction *terminal_begin_inverse_hook = (VFunction *)NULL;VFunction *terminal_end_inverse_hook = (VFunction *)NULL;VFunction *terminal_prep_terminal_hook = (VFunction *)NULL;VFunction *terminal_unprep_terminal_hook = (VFunction *)NULL;VFunction *terminal_up_line_hook = (VFunction *)NULL;VFunction *terminal_down_line_hook = (VFunction *)NULL;VFunction *terminal_clear_screen_hook = (VFunction *)NULL;VFunction *terminal_clear_to_eol_hook = (VFunction *)NULL;VFunction *terminal_get_screen_size_hook = (VFunction *)NULL;VFunction *terminal_goto_xy_hook = (VFunction *)NULL;VFunction *terminal_initialize_terminal_hook = (VFunction *)NULL;VFunction *terminal_new_terminal_hook = (VFunction *)NULL;VFunction *terminal_put_text_hook = (VFunction *)NULL;VFunction *terminal_ring_bell_hook = (VFunction *)NULL;VFunction *terminal_write_chars_hook = (VFunction *)NULL;VFunction *terminal_scroll_terminal_hook = (VFunction *)NULL;/* **************************************************************** *//* *//* Terminal and Termcap *//* *//* **************************************************************** *//* A buffer which holds onto the current terminal description, and a pointer used to float within it. */static char *term_buffer = (char *)NULL;static char *term_string_buffer = (char *)NULL;/* Some strings to control terminal actions. These are output by tputs (). */static char *term_goto, *term_clreol, *term_cr, *term_clrpag;static char *term_begin_use, *term_end_use;static char *term_AL, *term_DL, *term_al, *term_dl;static char *term_keypad_on, *term_keypad_off;/* How to go up a line. */static char *term_up;/* How to go down a line. */static char *term_dn;/* An audible bell, if the terminal can be made to make noise. */static char *audible_bell;/* A visible bell, if the terminal can be made to flash the screen. */static char *visible_bell;/* The string to write to turn on the meta key, if this term has one. */static char *term_mm;/* The string to write to turn off the meta key, if this term has one. */static char *term_mo;/* The string to turn on inverse mode, if this term has one. */static char *term_invbeg;/* The string to turn off inverse mode, if this term has one. */static char *term_invend;/* Although I can't find any documentation that says this is supposed to return its argument, all the code I've looked at (termutils, less) does so, so fine. */static intoutput_character_function (c) int c;{ putc (c, stdout); return c;}/* Macro to send STRING to the terminal. */#define send_to_terminal(string) \ do { \ if (string) \ tputs (string, 1, output_character_function); \ } while (0)/* Tell the terminal that we will be doing cursor addressable motion. */static voidterminal_begin_using_terminal (){ RETSIGTYPE (*sigsave) (); if (term_keypad_on) send_to_terminal (term_keypad_on); if (!term_begin_use || !*term_begin_use) return;#ifdef SIGWINCH sigsave = signal (SIGWINCH, SIG_IGN); #endif send_to_terminal (term_begin_use); /* Without this fflush and sleep, running info in a shelltool or cmdtool (TERM=sun-cmd) with scrollbars loses -- the scrollbars are not restored properly. From: strube@physik3.gwdg.de (Hans Werner Strube). */ fflush (stdout); sleep (1);#ifdef SIGWINCH signal (SIGWINCH, sigsave);#endif}/* Tell the terminal that we will not be doing any more cursor addressable motion. */static voidterminal_end_using_terminal (){ RETSIGTYPE (*sigsave) (); if (term_keypad_off) send_to_terminal (term_keypad_off); if (!term_end_use || !*term_end_use) return;#ifdef SIGWINCH sigsave = signal (SIGWINCH, SIG_IGN);#endif send_to_terminal (term_end_use); fflush (stdout); sleep (1);#ifdef SIGWINCH signal (SIGWINCH, sigsave);#endif}/* **************************************************************** *//* *//* Necessary Terminal Functions *//* *//* **************************************************************** *//* The functions and variables on this page implement the user visible portion of the terminal interface. *//* The width and height of the terminal. */int screenwidth, screenheight;/* Non-zero means this terminal can't really do anything. */int terminal_is_dumb_p = 0;/* Non-zero means that this terminal has a meta key. */int terminal_has_meta_p = 0;/* Non-zero means that this terminal can produce a visible bell. */int terminal_has_visible_bell_p = 0;/* Non-zero means to use that visible bell if at all possible. */int terminal_use_visible_bell_p = 0;/* Non-zero means that the terminal can do scrolling. */int terminal_can_scroll = 0;/* The key sequences output by the arrow keys, if this terminal has any. */char *term_ku = (char *)NULL;char *term_kd = (char *)NULL;char *term_kr = (char *)NULL;char *term_kl = (char *)NULL;char *term_kP = (char *)NULL; /* page-up */char *term_kN = (char *)NULL; /* page-down *//* Move the cursor to the terminal location of X and Y. */voidterminal_goto_xy (x, y) int x, y;{ if (terminal_goto_xy_hook) (*terminal_goto_xy_hook) (x, y); else { if (term_goto) tputs (tgoto (term_goto, x, y), 1, output_character_function); }}/* Print STRING to the terminal at the current position. */voidterminal_put_text (string) char *string;{ if (terminal_put_text_hook) (*terminal_put_text_hook) (string); else { printf ("%s", string); }}/* Print NCHARS from STRING to the terminal at the current position. */voidterminal_write_chars (string, nchars) char *string; int nchars;{ if (terminal_write_chars_hook) (*terminal_write_chars_hook) (string, nchars); else { if (nchars) fwrite (string, 1, nchars, stdout); }}/* Clear from the current position of the cursor to the end of the line. */voidterminal_clear_to_eol (){ if (terminal_clear_to_eol_hook) (*terminal_clear_to_eol_hook) (); else { send_to_terminal (term_clreol); }}/* Clear the entire terminal screen. */voidterminal_clear_screen (){ if (terminal_clear_screen_hook) (*terminal_clear_screen_hook) (); else { send_to_terminal (term_clrpag); }}/* Move the cursor up one line. */voidterminal_up_line (){ if (terminal_up_line_hook) (*terminal_up_line_hook) (); else { send_to_terminal (term_up); }}/* Move the cursor down one line. */voidterminal_down_line (){ if (terminal_down_line_hook) (*terminal_down_line_hook) (); else { send_to_terminal (term_dn); }}/* Turn on reverse video if possible. */voidterminal_begin_inverse (){ if (terminal_begin_inverse_hook) (*terminal_begin_inverse_hook) (); else { send_to_terminal (term_invbeg); }}/* Turn off reverse video if possible. */voidterminal_end_inverse (){ if (terminal_end_inverse_hook) (*terminal_end_inverse_hook) (); else { send_to_terminal (term_invend); }}/* Ring the terminal bell. The bell is run visibly if it both has one and terminal_use_visible_bell_p is non-zero. */voidterminal_ring_bell (){ if (terminal_ring_bell_hook) (*terminal_ring_bell_hook) (); else { if (terminal_has_visible_bell_p && terminal_use_visible_bell_p) send_to_terminal (visible_bell); else send_to_terminal (audible_bell); }}/* At the line START, delete COUNT lines from the terminal display. */static voidterminal_delete_lines (start, count) int start, count;{ int lines; /* Normalize arguments. */ if (start < 0) start = 0; lines = screenheight - start; terminal_goto_xy (0, start); if (term_DL) tputs (tgoto (term_DL, 0, count), lines, output_character_function); else { while (count--) tputs (term_dl, lines, output_character_function); } fflush (stdout);}/* At the line START, insert COUNT lines in the terminal display. */static voidterminal_insert_lines (start, count) int start, count;{ int lines; /* Normalize arguments. */ if (start < 0) start = 0; lines = screenheight - start; terminal_goto_xy (0, start); if (term_AL) tputs (tgoto (term_AL, 0, count), lines, output_character_function); else { while (count--) tputs (term_al, lines, output_character_function); } fflush (stdout);}/* Scroll an area of the terminal, starting with the region from START to END, AMOUNT lines. If AMOUNT is negative, the lines are scrolled towards the top of the screen, else they are scrolled towards the bottom of the screen. */voidterminal_scroll_terminal (start, end, amount) int start, end, amount;{ if (!terminal_can_scroll) return; /* Any scrolling at all? */ if (amount == 0) return; if (terminal_scroll_terminal_hook) (*terminal_scroll_terminal_hook) (start, end, amount); else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -