접속된 터미널(terminal) 화면 지우기(clear)

antz의 이미지

안녕하세요.
C 를사용해서 프로그램을 짜고 있습니다. (gcc 2.96)

서버의 상태 모니터링하는 프로그램으로,
log를 접속한 클라이언트에 보내고 있습니다.

서버의 쓰레드가 Active 되었는지 Deactive 되었는지를 봐야하는데요.

스크롤로 올라가지 않고, 보기 편하게,
watch와 같이 주기적으로 로그를 감시하고 싶습니다.

접속된 터미널에 어떻게 제어를 하면, 텍스트가 지워지고,
프롬프트가 위로 갈까요??? (clear, clrscr과 같이...)

부탁드리겠습니다.

Prentice의 이미지

Ctrl-L을 누르면 보통 화면이 클리어되는 것으로 알고 있습니다. ncurses같은 라이브러리 등에서 Ctrl-L을 어떻게 처리하는지를 참고하시면 어떨까요..?

ironiris의 이미지

ctrl+L 이 안되면
clear 를 타이핑해보세용~

antz의 이미지

Quote:
$ rpm -qf `which clear`
ncurses-5.2-12

clear 가 ncurses 패키지에 있어서,
소스를 보고 추가를 하려는데 잘 되지 않는군요.

#include <progs.priv.h>

#include <curses.h>

MODULE_ID("$Id: clear.c,v 1.8 1998/09/26 11:42:50 tom Exp $")

static int putch(int c)
{
        return putchar(c);
}

int main(
        int argc GCC_UNUSED,
        char *argv[] GCC_UNUSED)
{
        setupterm((char *) 0, STDOUT_FILENO, (int *) 0);
        return (tputs(clear_screen, lines > 0 ? lines : 1, putch) == ERR)
                ? EXIT_FAILURE
                : EXIT_SUCCESS;
}

간단해서 잘 수정을 하면,
접속한 클라이언트에 clear를 보낼 수 있을것 같은데.
내공이 부족한 관계로 힘드네요.

현재 ncurses 버전은 다음과 같고,

Quote:
$ rpm -q ncurses
ncurses-5.2-12

소스는 5.4 version를 받아서 소스를 봤습니다.

부탁 드리겠습니다.

antz의 이미지

joinc(http://www.joinc.co.kr)에서 minzkn님의 도움으로
알게 되었습니다.

참고해서 터미널로 코드를 보내는걸로 고쳐봤습니다.
작동을 잘하는군요. :D

void clearclient(int cli_sock)
{
        char send_buffer[SIZEBUFFER1K];

        memset(send_buffer, 0x00, SIZEBUFFER1K);
        strcpy(send_buffer, "x1b[2Jx1b[0;0H");
        send(cli_sock, send_buffer, strlen(send_buffer), 0);
}

더 좋은 생각있으시면, 답글 부탁드립니다.

FruitsCandy의 이미지

저렇게 터미널로 보내면 클라이언트에서 stdout로 보내도록 만들어야 할 것 같은데요.

차라리 클라이언트 프로그램 내부에 다음 코드를 넣고 서버에서 화면

클리어 명령을 보내주면 클라이언트에서에서 직접 clear해주는것이 좋을 것 같습니다.

fprintf(stdout, "\x1b[2J\x1b[0;0H");
fflush(stdout);

아지랑이류 초환상 공콤 화랑... 포기하다.. T.T

sjpark의 이미지

터미널에서
clear > ansi_clear

코드에서
ansi_clear에 있는걸 복사해서

printf("복사한거 붙여넣고");
fflushing...

antz의 이미지

darkpgm wrote:
터미널에서
clear > ansi_clear

코드에서
ansi_clear에 있는걸 복사해서

printf("복사한거 붙여넣고");
fflushing...


안씨코드를 따로 외울필요가 없겠군요.
감사합니다. :)

Quote:
$ cat ansi_clear

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.