tedit.c
来自「Software Development in C: A Practical A」· C语言 代码 · 共 112 行
C
112 行
#include "Tbuffer.h"
#include <stdio.h>
#define CONTROL_D (char)4
#define CONTROL_U (char)21
#define MAX_DISPLAY_LINES 25
#define ClearScreen() \
{ \
int i; \
\
for (i=0;i<MAX_DISPLAY_LINES;i++) \
{ \
printf("\n"); \
} \
}
int main()
{
text_buffer buffer;
text_string tempString;
int i,j,top;
char tempChar;
const int LINES_PER_SCREENFUL = 20;
const int LINES_TO_SCROLL_PER_PAGE = LINES_PER_SCREENFUL -1;
// Fill the text buffer.
for (i=0,tempChar='A';i<TEXT_BUFFER_LENGTH;i++)
{
// Initialize each row.
TextStringInitString(buffer[i]);
// Fill the row with characters.
for (j=0;j<TEXT_STRING_MAX_LENGTH-1;j++)
{
// Put the character in the buffer.
TextStringAppendCharacter(buffer[i],tempChar++);
if (tempChar>'z')
{
tempChar = 'A';
}
}
}
// While the user does not want to quit...
for (tempChar = ' ',top=0;
(tempChar!='Q') && (tempChar!='q');
scanf("%c",&tempChar))
{
if (tempChar!='\n')
{
switch (tempChar)
{
// If the user typed ^D...
case CONTROL_D:
/* Adjust the top display line downward one
screefull. */
top += LINES_TO_SCROLL_PER_PAGE;
break;
// If the user typed ^U...
case CONTROL_U:
/* Adjust the top display line upward one
screefull. */
top -= LINES_TO_SCROLL_PER_PAGE;
break;
default:
/*Warning the wrong input */
printf("%c", (char)7);
break;
}
// If the top line is before beginning of the buffer...
if (top<0)
{
// Adjust it.
top = 0;
}
// Else if the user scrolled too far toward the end...
else if (top > TEXT_BUFFER_LENGTH-LINES_PER_SCREENFUL)
{
// Adjust the top line
top = TEXT_BUFFER_LENGTH-LINES_PER_SCREENFUL;
}
// Print the contents of the buffer
ClearScreen();
for (i=0;
(i<LINES_PER_SCREENFUL) && (top+i<TEXT_BUFFER_LENGTH);
i++)
{
/* Print the buffer line number and the display line
number. */
printf("%d,%d: ",top+i,i);
TextBufferGetRow(buffer,top+i,tempString);
TextStringPrintString(tempString);
printf("\n");
}
// Print a prompt for the user.
printf("Enter a command >>>");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?