📄 hview.c
字号:
/* * hview.c * * Author: David Scott * Date Started: 25-Aug-2000 * * Modification history: * * .000830 initial beta release */#include <curses.h>#include <unistd.h>#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include "hview.h"/* * main * input: argument count * argument vector */int main( int argc, char *argv[] ){ WINDOW *wp; wp = setupscr(); process( wp, argc, ++argv ); return( endscr() ); }/* * setup window and all globals */WINDOW *setupscr(){ WINDOW *wp; wp = initscr(); cbreak(); getmaxyx(wp, screen_y, screen_x); buffer = malloc(screen_y*16*sizeof(int)); keypad(wp, TRUE); color = has_colors(); return wp;}/* * end screen * output: return value of endwin */int endscr(){ free(buffer); return(endwin());}/* * process the file and * input: pointer to current window * argument count * argument vector * * currently I only handle the first arg so * argc is unused, but in the future I may add * a way to process multiple files, so I'm leaving * it in. */int process( WINDOW *wp, int argc, char *argv[] ){ FILE *in; struct stat statbuf; if( (in = fopen( argv[0], "r+" )) == NULL ) { printerr(wp,strerror(errno),"Press any key to exit");/* printerr(wp,"File doesn't exist","Press any key to exit"); */ return -1; } stat(argv[0], &statbuf); totalbytes= statbuf.st_size;/* mode = statbuff.st_mode; */ if(color) { start_color(); init_pair(1,COLOR_BLACK, COLOR_WHITE); init_pair(2,COLOR_WHITE, COLOR_BLUE); wattron(wp, COLOR_PAIR(1)); } move(0,0); printw("%*c",80,' '); move(screen_y-2,0); printw("%*c",80,' '); move(0,3); printw("%s", argv[0]); printheader( wp, 0 ); move(screen_y-2,3); wattron(wp, COLOR_PAIR(2)); printw("Q)uit"); move(screen_y-2,9); printw("M)odify"); move(screen_y-2,17); printw("W)rite block"); move(screen_y-2,30); printw("^V-page down"); move(screen_y-2,43); printw("^Y-page up"); move(screen_y-2,54); printw("^R-refresh"); refresh(); if(color) wattroff(wp, COLOR_PAIR(2)); message_loop(wp, in); fclose(in); return 0;}/* * print header * input: pointer to the current window * offset to start at * * prints the header (the top line in the window) */void printheader( WINDOW *wp, int offset) { if(color) { start_color(); init_pair(1,COLOR_BLACK, COLOR_WHITE); init_pair(2,COLOR_WHITE, COLOR_BLUE); wattron(wp, COLOR_PAIR(1)); } move(0,60); printw("%X/%X bytes\n",offset,totalbytes); if(color) wattroff(wp, COLOR_PAIR(2));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -