📄 hwind.c
字号:
/******************* start of original comments ********************//* * Written by Douglas Thomson (1989/1990) * * This source code is released into the public domain. *//* * Name: hardware independent screen IO module * Purpose: This file contains the code to interface the rest of the * editor to the display and input hardware. * File: hwind.c * Author: Douglas Thomson * System: this file is intended to be system-independent * Date: October 2, 1989 * Notes: This is the only module that is allowed to call the hardware * dependent display IO library. * Typically, functions here check whether any action is * necessary (for example, the cursor may already happen to be * in the required position), call hardware dependent functions * to achieve the required effect, and finally update status * information about the current state of the terminal display. * The idea behind this approach is to keep the hardware * dependent code as small and simple as possible, thus making * porting the code easier. *//********************* end of original comments ********************//* * Some routines were added to display current editor modes in the lite bar * at the bottom of the screen. Other routines were rewritten in assembly. * I feel the need for speed. * * New editor name: TDE, the Thomson-Davis Editor. * Author: Frank Davis * Date: June 5, 1991, version 1.0 * Date: July 29, 1991, version 1.1 * Date: October 5, 1991, version 1.2 * Date: January 20, 1992, version 1.3 * Date: February 17, 1992, version 1.4 * Date: April 1, 1992, version 1.5 * Date: June 5, 1992, version 2.0 * Date: October 31, 1992, version 2.1 * Date: April 1, 1993, version 2.2 * Date: June 5, 1993, version 3.0 * Date: August 29, 1993, version 3.1 * Date: November 13, 1993, version 3.2 * Date: June 5, 1994, version 4.0 * Date: December 5, 1998, version 5.0 (jmh) * * This modification of Douglas Thomson's code is released into the * public domain, Frank Davis. You may distribute it freely. */#include <time.h>#include "tdestr.h"#include "common.h"#include "tdefunc.h"#include "define.h"/* * Name: format_time * Purpose: format the time according to a format string * Author: Jason Hood * Date: May 21, 1998 * Passed: format: format string * buffer: output string * t: time to convert, or NULL for current * Notes: buffer is assumed to be big enough to hold the string. * * 010617: fixed a bug with "%%" (didn't increment past the 2nd one). * 010624: added month and day word alignment. * 030320: added t parameter (for file times). */void format_time( const char *format, char *buffer, struct tm *t ){time_t epoch;int num;const char * const *ptr;static const char * const formats[] = { "%d", "%02d", "%2d" };static const char * const aligns[] = { "%-*s", "%*s" };int f, a;int wid;int j, len;char *b = buffer; if (t || (epoch = time( NULL )) != -1) { if (t || (t = localtime( &epoch )) != NULL) { len = strlen( format ); for (j = 0; j < len; ++j) { if (format[j] != '%') *b++ = format[j]; else { if (format[++j] == '%') *b++ = '%'; else { num = -1; ptr = NULL; f = a = 0; wid = 0; if (format[j] == '0') { f = 1; ++j; } else if (format[j] == '2') { f = 2; ++j; } else if (format[j] == '+') { a = 1; ++j; } else if (format[j] == '-') { a = 2; ++j; } switch (format[j]) { case TS_DAYMONTH: num = t->tm_mday; break; case TS_DAYWEEK: ptr = days[(f != 0)]; num = t->tm_wday; wid = longest_day; break; case TS_ENTER: *b++ = '\n'; break; case TS_12HOUR: num = t->tm_hour; if (num > 12) num -= 12; else if (num == 0) num = 12; break; case TS_24HOUR: num = t->tm_hour; break; case TS_MONTHNUM: num = t->tm_mon + 1; break; case TS_MONTHWORD: ptr = months[(f != 0)]; num = t->tm_mon; wid = longest_month; break; case TS_MINUTES: num = t->tm_min; break; case TS_MERIDIAN: ptr = time_ampm; num = (t->tm_hour >= 12); break; case TS_SECONDS: num = t->tm_sec; break; case TS_TAB: *b++ = '\t'; break; case TS_YEAR2: num = t->tm_year % 100; f = 1; break; case TS_YEAR: num = t->tm_year + 1900; break; case TS_ZONE: #if !defined( __DJGPP__ ) # if defined( __WIN32__ ) ptr = (const char**)_tzname; # else ptr = (const char**)tzname; # endif num = t->tm_isdst; #else ptr = (const char **)&t->tm_zone; num = 0; #endif break; default: *b++ = '%'; *b++ = format[j]; } if (ptr != NULL) { if (!a) b += sprintf( b, "%s", ptr[num] ); else b += sprintf( b, aligns[a-1], wid, ptr[num] ); } else if (num != -1) b += sprintf( b, formats[f], num ); } } } } } *b = '\0';}/* * Name: show_modes * Purpose: show current editor modes in lite bar at bottom of screen * Date: June 5, 1991 * Modified: November 13, 1993, Frank Davis per Byrial Jensen (file_win_mem) * jmh 981129: update the "temporary" modes. * jmh 981130: split file_win_mem into file_win and mem_eq. */void show_modes( void ){ eol_clear( 0, g_display.mode_line, Color( Mode ) ); show_graphic_chars( ); /* file & window count */ show_cur_dir( ); /* memory */ if (mode.record) show_recording( ); else { show_tab_modes( ); show_indent_mode( ); show_search_case( ); show_sync_mode( ); } show_wordwrap_mode( ); if (mode.draw) show_draw_mode( ); show_trailing( ); show_control_z( ); show_insert_mode( ); if (mode.display_cwd) show_cwd( );}/* * Name: show_file_count * Purpose: show number of open files in lite bar at bottom of screen * Date: June 5, 1991 * jmh 981129: do nothing if graphic characters are on */void show_file_count( void ){char temp[4]; if (mode.graphics <= 0) { sprintf( temp, "%-3d", g_status.file_count ); s_output( temp, g_display.mode_line, 3, Color( Mode ) ); }}/* * Name: show_window_count * Purpose: show total number of windows in lite bar at bottom of screen * Passed: wc: window count - visible and hidden. * Date: September 13, 1991 * jmh 981129: do nothing if graphic characters are on */void show_window_count( void ){char temp[4]; if (mode.graphics <= 0) { sprintf( temp, "%-3d", g_status.window_count ); s_output( temp, g_display.mode_line, 8, Color( Mode ) ); }}/* * Name: show_avail_mem * Purpose: show available free memory in lite bar at bottom of screen * Date: June 5, 1991 * jmh 981129: do nothing if cursor direction is not normal */void show_avail_mem( void ){long avail_mem;char temp[12];char suffix;int i; if (mode.cur_dir == CUR_RIGHT) { /* * reverse the sign if avail_mem is larger than a long. */ avail_mem = my_heapavail( ); if (avail_mem < 0) avail_mem = -avail_mem; if (avail_mem < 1048577L) suffix = ' '; else if (avail_mem < 67108865L) { avail_mem >>= 10; /* / 1024L */ suffix = 'k'; } else { avail_mem >>= 20; /* / 1048576L */ suffix = 'M'; } my_ltoa( avail_mem, temp, 10 ); i = numlen( avail_mem ); temp[i] = suffix; while (++i < 8) temp[i] = ' '; temp[8] = '\0'; s_output( temp, g_display.mode_line, 14, Color( Mode ) ); }}/* * Name: show_tab_modes * Purpose: show smart tab mode in lite bar at bottom of screen * Date: October 31, 1992 * * jmh 990501: in smart tab mode, display physical tab size; * in fixed tab mode, display logical tab size. * jmh 030329: use sprintf, instead of individual strings. */void show_tab_modes( void ){char tab[12]; sprintf( tab, "%s%c%c%-3d", tabs, smart[mode.smart_tab], tab_mode[g_status.current_file->inflate_tabs], mode.smart_tab ? g_status.current_file->ptab_size : g_status.current_file->ltab_size ); s_output( tab, g_display.mode_line, 22, Color( Mode ) );}/* * Name: show_indent_mode * Purpose: show indent mode in lite bar at bottom of screen * Date: June 5, 1991 */void show_indent_mode( void ){ s_output( indent_mode[mode.indent], g_display.mode_line, 32, Color( Mode ) );}/* * Name: show_search_case * Purpose: show search mode in lite bar * Date: June 5, 1991 */void show_search_case( void ){ s_output( case_mode[mode.search_case - 1], g_display.mode_line, 40, Color( Mode ) );}/* * Name: show_sync_mode * Purpose: show sync mode in lite bar * Date: January 15, 1992 */void show_sync_mode( void ){ s_output( sync_mode[mode.sync], g_display.mode_line, 48, Color( Mode ) );}/* * Name: show_wordwrap_mode * Purpose: display state of word wrap mode * Date: June 5, 1991 */void show_wordwrap_mode( void ){ s_output( ww_mode[mode.word_wrap], g_display.mode_line, 54, Color( Mode ) );}/* * Name: show_trailing * Purpose: show state of trailing flag * Date: June 5, 1991 * Modified: November 13, 1993, Frank Davis per Byrial Jensen */void show_trailing( void ){ c_output( mode.trailing ? MODE_TRAILING : ' ', 65, g_display.mode_line, Color( Mode ) );}/* * Name: show_control_z * Purpose: show state of control z flag * Date: June 5, 1991 * Modified: November 13, 1993, Frank Davis per Byrial Jensen */void show_control_z( void ){ c_output( mode.control_z ? MODE_CONTROL_Z : ' ', 77, g_display.mode_line, Color( Mode ) );}/* * Name: show_insert_mode * Purpose: show insert mode in lite bar * Date: June 5, 1991 * Modified: November 13, 1993, Frank Davis per Byrial Jensen * jmh 990404: added set_cursor_size() from toggle_overwrite(). * jmh 010808: removed the UNIX define. */void show_insert_mode( void ){ c_output( mode.insert ? MODE_INSERT : MODE_OVERWRITE, 79, g_display.mode_line, Color( Mode ) ); set_cursor_size( mode.insert ? g_display.insert_cursor : g_display.overw_cursor );}/* * Name: show_graphic_chars * Purpose: show state of graphic characters * Author: Jason Hood * Date: July 24, 1998 * jmh 981129: overwrite the file/window count with a flashing message. * jmh 031123: restore curses cursor position. */void show_graphic_chars( void ){#if defined( __UNIX__ )int x, y; getyx( stdscr, y, x );#endif if (mode.graphics <= 0) { s_output( file_win, g_display.mode_line, 1, Color( Mode ) ); show_file_count( ); show_window_count( ); } else { graphic_mode[GRAPHIC_SLOT] = graphic_char[mode.graphics-1][5]; s_output( graphic_mode, g_display.mode_line, 1, Color( Special ) ); }#if defined( __UNIX__ ) move( y, x );#endif}/* * Name: show_cur_dir * Purpose: show the cursor update direction * Author: Jason Hood * Date: November 29, 1998 * Notes: Overwrite the memory display with a flashing direction string. */void show_cur_dir( void ){ if (mode.cur_dir == CUR_RIGHT) { s_output( mem_eq, g_display.mode_line, 12, Color( Mode ) ); show_avail_mem( ); } else { c_repeat( ' ', 10, 12, g_display.mode_line, Color( Mode ) ); s_output( cur_dir_mode[mode.cur_dir], g_display.mode_line, 12, Color( Special ) ); }}/* * Name: show_draw_mode * Purpose: indicate draw mode is active * Author: Jason Hood * Date: October 18, 1999 * Notes: overwrite the current character display */void show_draw_mode( void ){ if (mode.draw) s_output( draw_mode, g_display.mode_line, 58, Color( Special ) ); else show_line_col( g_status.current_window );}/* * Name: show_undo_mode * Purpose: indicate whether undo is group or individual * Author: Jason Hood
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -