Има ли...

4 отговора 226 прегледа
#1

Има ли...

Съществува ли начин в ANSI C++ (тоест без нестандартни библиотеки) да изтриеш екрана на кнозолата, също така да позиционираш курсура на определено място или да смениш цвета на текста или фона?

Отговор
в отговор на Necromancer #2

Re: Има ли...

в Borland C има едно conio.h но това в никакъв начин не е съвместимо със ANSI стандарта. Впрочем отговорън на въпроса който поставяш е не.
Но пък ако пишеш програма за DOS можеш да ползваш conio.h. Това си е почти стандарт за DOS компилаторите. Ако пък пишеш за UNIX бъди сигурен че във всеки ще намериш (n)curses библиотеките които са алтернативата на conio.h за UNIX (макар и да са доста по-advanced)

Отговор
в отговор на Necromancer #3

Re: Има ли...


#include <stdio.h>
int
main()
{
printf("\033[2J");
}

това ти е за clrscr (и за тези които ще ме апострофират,
да знам че има случаи в които няма да сработи -
ако не е VT-100 терминал) както и да е,
в повечето това върши работа.

Погледни и това:

/* Program Sample
# include <stdio.h>

/* Declare Pointer Variables
static char *IS, *CL, *ME, *MR, *MD;
/* these are: Initialize String (*IS)
Clear Screen (*CL)
Attributes OFF (*ME)
Reverse ON (*MR)
Bold ON (*MD)
static char *ptr;
static char *tv_stype;
extern char *tgetstr();
extern void tputs();

/* Subroutine to "read" the requested "labels" from termcap buffer
static char *
qgetstr(ref)
char *ref
{
register char *tmp;
if ((tmp = fgetstr(ref,&ptr)) == NULL) {
printf("/etc/termcap terminal %s must have a %s= entry\n",
tv_stype,ref);
}
return(tmp);
}

/* Subroutine to open the termcap and read into 1024 Byte Buffer
/* this will speed up the "lookup" process if it's loaded into mem

static void
tcapopen()
{
extern char *getenv(),*realloc();
char *tcapbuf;
char tcbuf[1024];
if ((tv_stype = getenv("TERM")) == NULL) {
printf("TERM type not defined\n"):
exit(1);
}
if ((tgetent(tcbuf,tv_stype) != 1) {
printf("Terminal type not in termcap\n");
exit(1);
}
if ((ptr = tcapbub = malloc(1024)) == NULL) {
printf("Out of memory space\n");
exit(1);
}

/* get the needed "labels from the buffer.

IS = qgetstr("is"); /* Get the initialize string
CL = qgetstr("cl"); /* Get the clear screen command
ME = qgetstr("me"); /* Get the attribute off command
MR = qgetstr("mr"); /* Get the Reverse ON command
MD = qgetstr("md"); /* Get the Bold ON command
}

/* Subroutines to send the label's command to terminal

static void
ttputc(c)
{
fputc(c,stdout);
}

void
putpad(str)
char *str
{
tputs(str,1,ttputc);
}

main()
{
tcapopen(); /* open the termcap
putpad(IS); /* send the initialize string
putpad(MR); /* start reverse attribute
printf("This is in reverse attribute mode/n");
putpad(ME); /* turn off the attribute
putpad(MD); /* start bold attribute
printf("This is in bold attribute mode\n");
putpad(ME); /* turn off the attribute
}

The last eight lines of the sample program ( main() ) is
a very short example, illustrating how the labels in a termcap
are called from a program.



Успех
Отговор
в отговор на bofh #4

И още нещо

Ако решиш да ползваш termcap (ако само ще местиш курсора) ето ти линк с информация

[линк]

bofh

И към горния пример(този с printf-a) , както ми напомниха е хубаво да сложиш fflush(stdout)

Редактирано от bofh на

Отговор
в отговор на bofh #5

Re: Има ли...

Прости ми за невежеството, но къде мога да прочета за тези кодове ('\33 ...). По-конкретно ме интересува '\033[5i' - start local printer и '\033[4i' - stop local printer.
Благодаря!

Отговор