ssh chat:@www.vitalipom.com ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ (์ด์ œ ์‚ฌ์šฉ์ž ์ด๋ฆ„์ด ์žˆ์Šต๋‹ˆ๋‹ค!)

5009 ๋‹จ์–ด showdevvimwebdevlinux
์•ˆ๋…•,
Curses ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋กœ๊ทธ๋ž˜๋จธ๋ฅผ ์œ„ํ•œ SSH ์ฑ„ํŒ…์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

์ œ๋ฐœ, ์ œ๋ฐœ, ์ €๋ฅผ ๋ฐฉ๋ฌธํ•ด์ฃผ์„ธ์š”. ์šฐ๋ฆฌ ์ง‘์— ์žˆ๋Š” ์„œ๋ฒ„, ์ธํ„ฐ๋„ท์— ์—ฐ๊ฒฐ๋œ ์‹ค์ œ ์„œ๋ฒ„ ์ปดํ“จํ„ฐ์ž…๋‹ˆ๋‹ค. ์ €๋„ ์ตœ๊ทผ์— ํ˜ผ์ž ์ž๋™์Šคํฌ๋กค ๊ตฌํ˜„ํ–ˆ๋Š”๋ฐ ์ด ์†Œ์Šค์ฝ”๋“œ๋„ ๊ณต์œ ํ• ๊ฒŒ์š”. ๋ฐฉ๋ฌธํ•˜์—ฌ ๋ฉ”์‹œ์ง€๋ฅผ ๋‚จ๊ธฐ๊ณ  ์ œ ์ €์žฅ์†Œ์— ๋ณ„ํ‘œ๋ฅผ ๋‚จ๊ฒจ์ฃผ์„ธ์š”.

์—ฌ๊ธฐ์—์„œ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ์ฐพ์œผ์‹ญ์‹œ์˜ค.

https://github.com/VitaliPom/chatapp/blob/master/perl.pl

๊ทธ๋ฆฌ๊ณ  CMD์—์„œ ํ•œ ์ค„ ๋ช…๋ น์œผ๋กœ ์ฑ„ํŒ…์— ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค.

ssh chat:@www.vitalipom.com

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
๋น„ํƒˆ๋ฆฌ ํฌ๋งˆ๋‹ˆ์ธ ํ‚ค

ํŽธ์ง‘: ~~~~ ์†Œ์Šค ์ฝ”๋“œ ~~~~

#! /home/linuxbrew/.linuxbrew/opt/[email protected]/bin/perl -w

use strict;
use Curses;
use Curses::UI;
use Curses::UI::Common;


# create a new C::UI object
my $key_up = 0;

my $cui = Curses::UI->new( -clear_on_exit => 1,

                           );

my $win = $cui->add('window_id', 'Window');

my $height = `tput rows`;
$height-=1;

my $textentry = $win->add(
    'mytextentry', 'TextEntry',
    -y => $height,  
    -text => 'Username: '
    );

my $SERVER = "192.168.1.13/chat.php";

my $USERNAME = "";

my $text = `curl $SERVER`;
$text =~ s#""#"#g;
$text =~ s#``#`#g;
$text =~ s#''#'#g;


my $textviewer = $win->add( 
     'mytextviewer', 'TextViewer',
        -text => $text, 
    -vscrollbar => 1

                );


$textentry->focus();

#$text = $textentry->get();

#$textentry->set_routine('loose-focus',"\r");
#$cui->set_routine('none',KEY_UP);
#$cui->set_routine('none',KEY_DOWN);

$cui->set_binding( sub {
     $text = $textentry->get();
     $text =~ s#"#""#g;
     $text =~ s#`#``#g;  
     $text =~ s#'#''#g; 

     if(not defined $text or $text eq ""){
        return;
     }
     my $is_log = 0;
     if($USERNAME eq ""){
        my $tmp_username = $text;
        if($tmp_username =~ /Username:\s*/){ 
            $tmp_username =~ s#Username:\s*##; 
            if($tmp_username ne ""){
                $USERNAME = $tmp_username;
                $USERNAME =~ s#"##g;   
                $USERNAME =~ s#`##g;  
                $USERNAME =~ s#'##g; 

                $text = "$USERNAME has logged in!";
                $is_log = 1;
            }
        }
     }

     $USERNAME =~ s#"#""#g;   
     $USERNAME =~ s#`#``#g;  
     $USERNAME =~ s#'#''#g; 

     if($USERNAME ne ""){
         if(not $is_log){
             $text = $USERNAME . ": " . $text; 
         }
         my $new_text = $text;
         $USERNAME =~ s#"#""#g;    
         $USERNAME =~ s#`#``#g;  
         $USERNAME =~ s#'#''#g; 
         $new_text =~ s#$USERNAME: ##;
         $new_text =~ s#Username:\s*##;

         if($new_text eq ":q"){
             exit 0;   
         }
         `curl $SERVER -d "message=$text"`;
         $text = `curl $SERVER`;
         $text =~ s#""#"#g; 
             $text =~ s#``#`#g;
         $text =~ s#''#'#g;

         $textviewer->text($text);
         $textentry->text(""); 
     }else{
         $textentry->text("Username: "); 
     }

    }, KEY_ENTER()); 

#$cui->set_binding( sub {
#     $text = `curl $SERVER`;
#     $textviewer->text($text);
#
#                $cui->draw(1);
#     
##     $textviewer->{-yscrpos}++;
#     $textviewer->layout_content();
##     $textentry->focus();
#
#        }, "5" ); 

$cui->set_timer(
        'timer',
        sub {
                 $text = `curl $SERVER`;
                 $text =~ s#""#"#g;
                 $text =~ s#``#`#g;
                 $text =~ s#''#'#g;

                 $textviewer->text($text);
#                $textentry->focus();

                 if($key_up == 0){
                    for(my $i = 0; $i<2000; $i++){
                          $textviewer->cursor_down()
                     }
                 }

                $cui->draw(1);
                return;
        },
        1,
);
for(my $i =0; $i<2000; $i++){
    $textviewer->cursor_down(); 
}


$textviewer->set_binding( sub {
        $key_up--;
        $textviewer->cursor_up()

        }, KEY_UP() );

$textentry->set_binding( sub {
        $key_up--;
        $textviewer->focus();
        $textviewer->cursor_up();
        $textentry->focus();

        }, KEY_UP() );

$textentry->set_binding( sub {
        if($key_up < 0){
            $key_up++;
        }

        $textviewer->focus();
        $textviewer->cursor_down();
        $textentry->focus();

        }, KEY_DOWN() );


$textviewer->set_binding( sub {
        if($key_up < 0){
            $key_up++;
        }
        $textviewer->cursor_down()

        }, KEY_DOWN() );

$cui->set_binding( sub {exit 0;}, "\e" );

$cui->mainloop;


์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ