diff --git a/src/Fl_Browser_Input.cxx b/src/Fl_Browser_Input.cxx index 1ac1bf7..571d17f 100644 --- a/src/Fl_Browser_Input.cxx +++ b/src/Fl_Browser_Input.cxx @@ -1,9 +1,9 @@ // -// "$Id: Fl_Browser_Input.cxx 3792 2020-06-08 13:48:10 $" +// "$Id: Fl_Browser_Input.cxx 3803 2020-06-21 13:48:10 $" // // Fl_Input widget extended with auto completion // -// Copyright 2017-2018 by Yongchao Fan. +// Copyright 2017-2020 by Yongchao Fan. // // This library is free software distributed under GNU GPL 3.0, // see the license at: @@ -15,7 +15,6 @@ // https://github.com/yongchaofan/tinyTerm2/issues/new // #include "Fl_Browser_Input.h" -#include #ifdef __APPLE__ #define FL_CMD FL_META #else @@ -35,14 +34,14 @@ Fl_Browser_Input::Fl_Browser_Input(int X,int Y,int W,int H,const char* L) browserWin->resizable(browser); id = 0; } -void Fl_Browser_Input::resize( int X, int Y, int W, int H ) +void Fl_Browser_Input::resize(int X, int Y, int W, int H) { Fl_Input::resize(X, Y, W, H); browserWin->resize( parent()->x()+X, parent()->y()+Y+( (Y<104) ? h()+1:-104 ), w(), 104); } -int Fl_Browser_Input::add( const char *cmd ) +int Fl_Browser_Input::add(const char *cmd) { if ( *cmd==0 ) return 0; if ( browser->size()==0 ) browser->add(cmd); @@ -58,7 +57,7 @@ int Fl_Browser_Input::add( const char *cmd ) id = i; return i; } -const char * Fl_Browser_Input::first( ) +const char * Fl_Browser_Input::first() { id = 1; if ( id<=browser->size() ) @@ -66,7 +65,7 @@ const char * Fl_Browser_Input::first( ) else return NULL; } -const char * Fl_Browser_Input::next( ) +const char * Fl_Browser_Input::next() { if ( idsize() ) return browser->text(++id); @@ -77,7 +76,7 @@ void Fl_Browser_Input::close() { browserWin->hide(); } -int Fl_Browser_Input::handle( int e ) +int Fl_Browser_Input::handle(int e) { if ( e!=FL_KEYDOWN ) return Fl_Input::handle(e); char cmd[2]={ 0, 0 }; @@ -144,10 +143,10 @@ int Fl_Browser_Input::handle( int e ) browser->middleline(id); value(browser->text(id)); position(p, size()); - if ( !browserWin->shown() ) { - browserWin->show(); - take_focus(); - } + // if ( !browserWin->shown() ) {//show list when there is match + // browserWin->show(); + // take_focus(); + // } break; } } diff --git a/src/Fl_Browser_Input.h b/src/Fl_Browser_Input.h index 7c56db1..d4109ad 100644 --- a/src/Fl_Browser_Input.h +++ b/src/Fl_Browser_Input.h @@ -1,9 +1,9 @@ // -// "$Id: Fl_Browser_Input.h 977 2019-05-09 13:48:10 $" +// "$Id: Fl_Browser_Input.h 980 2020-06-30 13:48:10 $" // // Fl_Input widget extended with auto completion // -// Copyright 2017-2018 by Yongchao Fan. +// Copyright 2017-2020 by Yongchao Fan. // // This library is free software distributed under GNU GPL 3.0, // see the license at: @@ -22,7 +22,6 @@ #ifndef _BROWSER_INPUT_H_ #define _BROWSER_INPUT_H_ - class Fl_Browser_Input: public Fl_Input { private: Fl_Menu_Window *browserWin; @@ -31,11 +30,11 @@ class Fl_Browser_Input: public Fl_Input { public: Fl_Browser_Input(int X,int Y,int W,int H,const char* L=0); ~Fl_Browser_Input() {} - void resize( int X, int Y, int W, int H ); - int handle( int e ); - int add( const char *cmd ); + void resize(int X, int Y, int W, int H); + int handle(int e); + int add(const char *cmd); const char *first(); const char *next(); void close(); }; -#endif //acInput \ No newline at end of file +#endif //_BROWSER_INPUT_H_ \ No newline at end of file diff --git a/src/Fl_Term.cxx b/src/Fl_Term.cxx index ae5bbcb..166519c 100644 --- a/src/Fl_Term.cxx +++ b/src/Fl_Term.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Term.cxx 39318 2020-06-20 10:08:20 $" +// "$Id: Fl_Term.cxx 39430 2020-06-30 10:08:20 $" // // Fl_Term -- A terminal simulator widget // @@ -24,7 +24,7 @@ using namespace std; int move_editor(int x, int y, int w, int h);//defined in tiny2.cxx #ifndef WIN32 -void Sleep(int ms); //defined in ssh2.cxx +#define Sleep(x) usleep((x)*1000); #endif void host_cb0(void *data, const char *buf, int len) @@ -94,6 +94,8 @@ Fl_Term::Fl_Term(int X,int Y,int W,int H,const char *L) : Fl_Widget(X,Y,W,H,L) textsize(16); size_x = w()/font_width; size_y = h()/font_height; + roll_top = 0; + roll_bot = size_y-1; color(FL_BLACK); clear(); for ( int i=0; i<4; i++ ) rclick_menu[i].labelsize(16); @@ -131,7 +133,7 @@ void Fl_Term::clear() Fl::unlock(); } -void Fl_Term::resize( int X, int Y, int W, int H ) +void Fl_Term::resize(int X, int Y, int W, int H) { Fl_Widget::resize(X,Y,W,H); size_x = w()/font_width; @@ -142,21 +144,20 @@ void Fl_Term::resize( int X, int Y, int W, int H ) if ( host!=NULL ) host->send_size(size_x, size_y); redraw(); } -void Fl_Term::textfont( Fl_Font fontface ) +void Fl_Term::textfont(Fl_Font fontface) { font_face = fontface; fl_font(font_face, font_size); font_width = fl_width("abcdefghij")/10; font_height = fl_height(); } -void Fl_Term::textsize( int fontsize ) +void Fl_Term::textsize(int fontsize) { font_size = fontsize; fl_font(font_face, font_size); font_width = fl_width("abcdefghij")/10; font_height = fl_height(); } - const unsigned int VT_attr[] = { 0x00000000, 0xc0000000, 0x00c00000, 0xc0c00000, //0,1,2,3 0x2060c000, 0xc000c000, 0x00c0c000, 0xc0c0c000, //4,5,6,7 @@ -205,7 +206,9 @@ void Fl_Term::draw() } fl_color( font_color ); } - fl_draw( buff+j, n-j, dx, dy ); + int m = (buff[n-1]==0x0a) ? n-1 : n; //don't draw LF, + //which will result in little squares on some platforms + fl_draw( buff+j, m-j, dx, dy ); dx += wi; j=n; } @@ -240,7 +243,8 @@ void Fl_Term::draw() fl_rectf(x()+w()-8, y()+slider_y-8, 8, 16); } } -int Fl_Term::handle( int e ) { +int Fl_Term::handle(int e) +{ switch (e) { case FL_FOCUS: redraw(); return 1; case FL_MOUSEWHEEL: @@ -486,7 +490,8 @@ void Fl_Term::next_line() Fl::unlock(); } } -void Fl_Term::append( const char *newtext, int len ){ +void Fl_Term::append( const char *newtext, int len ) +{ const unsigned char *p = (const unsigned char *)newtext; const unsigned char *zz = p+len; @@ -657,7 +662,7 @@ void Fl_Term::check_cursor_y() cursor_y = screen_y+roll_bot; } } -const unsigned char *Fl_Term::vt100_Escape( const unsigned char *sz, int cnt ) +const unsigned char *Fl_Term::vt100_Escape(const unsigned char *sz, int cnt) { const unsigned char *zz = sz+cnt; bEscape = true; @@ -1016,7 +1021,7 @@ const unsigned char *Fl_Term::vt100_Escape( const unsigned char *sz, int cnt ) } return sz; } -void Fl_Term::logg( const char *fn ) +void Fl_Term::logg(const char *fn) { if ( fpLogFile!=NULL ) { fclose( fpLogFile ); @@ -1032,7 +1037,7 @@ void Fl_Term::logg( const char *fn ) } } } -void Fl_Term::srch( const char *sstr ) +void Fl_Term::srch(const char *sstr) { int l = strlen(sstr); char *p = buff+sel_left; @@ -1066,7 +1071,7 @@ char *Fl_Term::mark_prompt() recv0 = cursor_x; return buff+cursor_x; } -int Fl_Term::waitfor_prompt( ) +int Fl_Term::waitfor_prompt() { int oldlen = recv0; for ( int i=0; ilive() ) return; @@ -1229,7 +1234,8 @@ int Fl_Term::command(const char *cmd, char **preply) } return rc; } -void Fl_Term::put_xml(const char *buf, int len) { +void Fl_Term::put_xml(const char *buf, int len) +{ const char *p=buf, *q; const char spaces[256]="\r\n \ "; @@ -1298,7 +1304,7 @@ void Fl_Term::scripter(char *cmds) free(cmds); bScriptRun = bScriptPause = false; } -void Fl_Term::pause_script( ) +void Fl_Term::pause_script() { if ( bScriptRun ) { bScriptPause = true; @@ -1308,7 +1314,7 @@ void Fl_Term::pause_script( ) quit_script( ); } } -void Fl_Term::quit_script( ) +void Fl_Term::quit_script() { if ( bScriptRun ) { bScriptRun = bScriptPause = false; diff --git a/src/Fl_Term.h b/src/Fl_Term.h index acd4904..f4ce3cc 100644 --- a/src/Fl_Term.h +++ b/src/Fl_Term.h @@ -1,5 +1,5 @@ // -// "$Id: Fl_Term.h 4922 2020-06-18 13:08:10 $" +// "$Id: Fl_Term.h 4900 2020-06-30 13:08:10 $" // // Fl_Term -- A terminal simulation widget // @@ -84,7 +84,7 @@ class Fl_Term : public Fl_Widget { FILE *fpLogFile; HOST *host; -protected: +protected: void draw(); void next_line(); void buff_clear(int offset, int len); @@ -99,11 +99,11 @@ class Fl_Term : public Fl_Widget { Fl_Term(int X,int Y,int W,int H,const char* L=0); ~Fl_Term(); void clear(); - int handle( int e ); - void resize( int X, int Y, int W, int H ); - void textfont( Fl_Font fontface ); - void textsize( int fontsize ); - void buffsize( int lines ); + int handle(int e); + void resize(int X, int Y, int W, int H); + void textfont(Fl_Font fontface); + void textsize(int fontsize); + void buffsize(int lines); const char *title() { return sTitle; } int logg() { return fpLogFile!=NULL; } @@ -112,13 +112,13 @@ class Fl_Term : public Fl_Widget { int rows() { return size_y; } int sizeX() { return size_x*font_width; } int sizeY() { return size_y*font_height; } - void echo( int e ) { bEcho = e; } - void logg( const char *fn ); - void srch( const char *word ); + void echo(int e) { bEcho = e; } + void logg(const char *fn); + void srch(const char *word); int connected() { return host!=NULL ? host->live() : false; } - void connect( const char *hostname ); - void host_cb( const char *buf, int len ); + void connect(const char *hostname); + void host_cb(const char *buf, int len); char *gets(const char *prompt, int echo); void disconn(); @@ -139,7 +139,7 @@ class Fl_Term : public Fl_Widget { void scripter(char *cmds); void run_script(char *script); - void pause_script( ); + void pause_script(); void quit_script(); void term_pwd(char *dst); diff --git a/src/host.cxx b/src/host.cxx index 55b8a50..40bf0e8 100644 --- a/src/host.cxx +++ b/src/host.cxx @@ -1,5 +1,5 @@ // -// "$Id: Hosts.cxx 28386 2020-06-19 12:15:10 $" +// "$Id: Hosts.cxx 28380 2020-06-30 12:15:10 $" // // HOST tcpHost comHost pipeHost and daemon hosts // @@ -40,7 +40,7 @@ void HOST::connect() reader.swap(new_reader); } } -void HOST::print( const char *fmt, ... ) +void HOST::print(const char *fmt, ...) { char buff[4096]; va_list args; @@ -377,7 +377,6 @@ int tcpHost::read() while ( (cch=recv(sock, buf, 1536, 0))>0 ) { do_callback(buf, cch); } - status( HOST_IDLE ); do_callback("Disconnected", -1); } @@ -386,9 +385,10 @@ int tcpHost::read() sock = -1; } reader.detach(); + status(HOST_IDLE); return 0; } -int tcpHost::write(const char *buf, int len ) +int tcpHost::write(const char *buf, int len) { if ( sock!=-1 ) { int total=0, cch=0; diff --git a/src/host.h b/src/host.h index 3e61779..3b92054 100644 --- a/src/host.h +++ b/src/host.h @@ -1,12 +1,12 @@ // -// "$Id: Hosts.h 4460 2020-06-19 21:12:15 $" +// "$Id: Hosts.h 4458 2020-06-30 21:12:15 $" // // HOST pipeHost comHost tcpHost ftpd tftpd // // host implementation for terminal simulator // to be used with the Fl_Term widget. // -// Copyright 2017-2019 by Yongchao Fan. +// Copyright 2017-2020 by Yongchao Fan. // // This library is free software distributed under GNU GPL 3.0, // see the license at: @@ -77,7 +77,7 @@ class HOST { } int live() { return reader.joinable(); } int status() { return state; } - void status( int s) { state = s; } + void status(int s) { state = s; } void print(const char *fmt, ...); }; @@ -206,4 +206,4 @@ class tftpdHost : public HOST { }; #endif //WIN32 */ -#endif //_HOST_H_ +#endif //_HOST_H_ \ No newline at end of file diff --git a/src/ssh2.cxx b/src/ssh2.cxx index 7fd9c5f..7593fd6 100644 --- a/src/ssh2.cxx +++ b/src/ssh2.cxx @@ -1,5 +1,5 @@ // -// "$Id: ssh2.cxx 38448 2020-06-20 11:55:10 $" +// "$Id: ssh2.cxx 38446 2020-06-30 11:55:10 $" // // sshHost sftpHost // @@ -27,10 +27,7 @@ #include #include #include -void Sleep(int ms) -{ - usleep(ms*1000); -} +#define Sleep(x) usleep((x)*1000); #else #include int wchar_to_utf8(WCHAR *wbuf, int wcnt, char *buf, int cnt) @@ -317,7 +314,6 @@ void sshHost::write_keys(const char *buf, int len) if ( buf[i]=='\015' ) { keys[cursor++]=0; bReturn=true; - do_callback("\r\n", 2); } else if ( buf[i]=='\177' || buf[i]=='\b' ) { if ( cursor>0 ) { @@ -333,7 +329,7 @@ void sshHost::write_keys(const char *buf, int len) } } } -char* sshHost::ssh_gets( const char *prompt, int echo ) +char* sshHost::ssh_gets(const char *prompt, int echo) { do_callback(prompt, strlen(prompt)); cursor=0; @@ -341,12 +337,15 @@ char* sshHost::ssh_gets( const char *prompt, int echo ) bReturn = false; bPassword = !echo; int old_cursor = cursor; - for ( int i=0; i<3000&&bGets; i++ ) { - if ( bReturn ) return keys; - if ( cursor>old_cursor ) { old_cursor=cursor; i=0; } + for ( int i=0; i<600&&bGets&&(!bReturn); i++ ) { + if ( cursor>old_cursor ) { + old_cursor=cursor; + i=0; + } Sleep(100); } - return NULL; + do_callback("\r\n", 2); + return bReturn ? keys : NULL; } int sshHost::ssh_authentication() @@ -355,6 +354,7 @@ int sshHost::ssh_authentication() if ( *username==0 ) { const char *p = ssh_gets("\r\nusername: ", true); if ( p==NULL ) return rc; + if ( *p==0 ) return rc; strncpy(username, p, 31); } char *authlist=libssh2_userauth_list(session, username, strlen(username)); @@ -487,7 +487,6 @@ int sshHost::read() break; } } - status( HOST_IDLE ); do_callback("Disconnected", -1); tun_closeall(); *username = 0; @@ -509,6 +508,7 @@ int sshHost::read() } TCP_Close: closesocket(sock); + status(HOST_IDLE); reader.detach(); return 0; } @@ -790,7 +790,7 @@ int sshHost::scp_write(char *lpath, char *rpath) } return 0; } -TUNNEL *sshHost::tun_add( int tun_sock, LIBSSH2_CHANNEL *tun_channel, +TUNNEL *sshHost::tun_add(int tun_sock, LIBSSH2_CHANNEL *tun_channel, char *localip, unsigned short localport, char *remoteip, unsigned short remoteport) { @@ -1084,19 +1084,19 @@ int sftpHost::sftp_lcd(char *cmd) if ( cmd==NULL || *cmd==0 ) { char buf[4096]; if ( getcwd(buf, 4096)!=NULL ) { - print("\t\033[32m%s \033[37mis current local directory\n", cmd); + print("\033[32m%s \033[37mis current local directory\n", cmd); } else { - print("\t\033[31mCouldn't get current local directory\n"); + print("\033[31mCouldn't get current local directory\n"); } } else { while ( *cmd==' ' ) cmd++; if ( chdir(cmd)==0 ) { - print("\t\033[32m%s\033[37m is now local directory!\n", cmd); + print("\033[32m%s\033[37m is now local directory!\n", cmd); } else { - print("\t\033[31mCouldn't change local dir to \033[32m%s\n", cmd); + print("\033[31mCouldn't change local dir to \033[32m%s\n", cmd); } } return 0; @@ -1108,14 +1108,14 @@ int sftpHost::sftp_cd(char *path) LIBSSH2_SFTP_HANDLE *sftp_handle; sftp_handle = libssh2_sftp_opendir(sftp_session, path); if (!sftp_handle) { - print("\t\033[31mCouldn't change dir to \033[32m%s\n", path); + print("\033[31mCouldn't change dir to \033[32m%s\n", path); return 0; } libssh2_sftp_closedir(sftp_handle); int rc = libssh2_sftp_realpath(sftp_session, path, newpath, 1024); if ( rc>0 ) strcpy( realpath, newpath ); } - print("\033[32m%s\033[37m\n", realpath); + print("%s\n", realpath); return 0; } int sftpHost::sftp_ls(char *path, int ll) @@ -1126,7 +1126,7 @@ int sftpHost::sftp_ls(char *path, int ll) LIBSSH2_SFTP_HANDLE *sftp_handle = libssh2_sftp_opendir(sftp_session, path); if (!sftp_handle) { if ( strchr(path, '*')==NULL && strchr(path, '?')==NULL ) { - print("\t\033[31mUnable to open dir\033[32m%s\n", path); + print("\033[31mUnable to open dir\033[32m%s\n", path); return 0; } pattern = strrchr(path, '/'); @@ -1139,7 +1139,7 @@ int sftpHost::sftp_ls(char *path, int ll) sftp_handle = libssh2_sftp_opendir(sftp_session, "/"); } if ( !sftp_handle ) { - print("\t\033[31munable to open dir\033[32m%s\n", path); + print("\033[31munable to open dir\033[32m%s\n", path); return 0; } } @@ -1147,7 +1147,7 @@ int sftpHost::sftp_ls(char *path, int ll) while ( libssh2_sftp_readdir_ex(sftp_handle, mem, sizeof(mem), longentry, sizeof(longentry), &attrs)>0 ) { if ( pattern==NULL || fnmatch(pattern, mem, 0)==0 ) - print("\t%s\n", ll ? longentry : mem); + print("%s\n", ll ? longentry : mem); } libssh2_sftp_closedir(sftp_handle); return 0; @@ -1156,7 +1156,7 @@ int sftpHost::sftp_rm(char *path) { if ( strchr(path, '*')==NULL && strchr(path, '?')==NULL ) { if ( libssh2_sftp_unlink(sftp_session, path) ) - print("\t\033[31mcouldn't delete file\033[32m%s\n", path); + print("\033[31mcouldn't delete file\033[32m%s\n", path); return 0; } char mem[512], rfile[1024]; @@ -1166,7 +1166,7 @@ int sftpHost::sftp_rm(char *path) if ( pattern!=path ) *pattern++ = 0; sftp_handle = libssh2_sftp_opendir(sftp_session, path); if ( !sftp_handle ) { - print("\t\033[31munable to open dir\033[32m%s\n", path); + print("\033[31munable to open dir\033[32m%s\n", path); return 0; } @@ -1176,7 +1176,7 @@ int sftpHost::sftp_rm(char *path) strcat(rfile, "/"); strcat(rfile, mem); if ( libssh2_sftp_unlink(sftp_session, rfile) ) - print("\t\033[31mcouldn't delete file\033[32m%s\n", rfile); + print("\033[31mcouldn't delete file\033[32m%s\n", rfile); } } libssh2_sftp_closedir(sftp_handle); @@ -1189,7 +1189,7 @@ int sftpHost::sftp_md(char *path) LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IXGRP| LIBSSH2_SFTP_S_IROTH|LIBSSH2_SFTP_S_IXOTH); if ( rc ) { - print("\t\033[31mcouldn't create directory\033[32m%s\n", path); + print("\033[31mcouldn't create directory\033[32m%s\n", path); } return 0; } @@ -1197,7 +1197,7 @@ int sftpHost::sftp_rd(char *path) { int rc = libssh2_sftp_rmdir(sftp_session, path); if ( rc ) { - print("\t\033[31mcouldn't remove directory\033[32m%s\n", path); + print("\033[31mcouldn't remove directory\033[32m%s\n", path); } return 0; } @@ -1205,7 +1205,7 @@ int sftpHost::sftp_ren(char *src, char *dst) { int rc = libssh2_sftp_rename(sftp_session, src, dst); if ( rc ) - print("\t\033[31mcouldn't rename file\033[32m%s\n", src); + print("\033[31mcouldn't rename file\033[32m%s\n", src); return 0; } int sftpHost::sftp_get_one(char *src, char *dst) @@ -1214,16 +1214,16 @@ int sftpHost::sftp_get_one(char *src, char *dst) src, LIBSSH2_FXF_READ, 0); if (!sftp_handle) { - print("\t\033[31mUnable to read file\033[32m%s\n", src); + print("\033[31mUnable to read file\033[32m%s\n", src); return 0; } FILE *fp = fopen(dst, "wb"); if ( fp==NULL ) { - print("\t\033[31munable to create local file\033[32m%s\n", dst); + print("\033[31munable to create local file\033[32m%s\n", dst); libssh2_sftp_close(sftp_handle); return 0; } - print("\t\033[32m%s ", dst); + print("\033[32m%s ", dst); char mem[1024*64]; unsigned int rc, block=0; long total=0; @@ -1247,15 +1247,15 @@ int sftpHost::sftp_put_one(char *src, char *dst) LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR| LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH); if (!sftp_handle) { - print("\t\033[31mcouldn't open remote file\033[32m%s\n", dst); + print("\033[31mcouldn't open remote file\033[32m%s\n", dst); return 0; } FILE *fp = fopen(src, "rb"); if ( fp==NULL ) { - print("\t\033[31mcouldn't open local file\033[32m%s\n", src); + print("\033[31mcouldn't open local file\033[32m%s\n", src); return 0; } - print("\t\033[32m%s ", dst); + print("\033[32m%s ", dst); char mem[1024*64]; int nread, block=0; long total=0; @@ -1301,7 +1301,7 @@ int sftpHost::sftp_get(char *src, char *dst) *pattern++ = 0; sftp_handle = libssh2_sftp_opendir(sftp_session, src); if ( !sftp_handle ) { - print("\t\033[31mcould't open remote \033[32m%s\n", src); + print("\033[31mcould't open remote \033[32m%s\n", src); return 0; } @@ -1352,7 +1352,7 @@ int sftpHost::sftp_put(char *src, char *dst) } if ( (dir=opendir(lfile) ) == NULL ){ - print("\t\033[31mcouldn't open \033[32m%s\n",lfile); + print("\033[31mcouldn't open \033[32m%s\n",lfile); return 0; } strcat(lfile, "/"); @@ -1419,7 +1419,7 @@ int sftpHost::sftp(char *cmd) else if ( strncmp(cmd, "put",3)==0 ) sftp_put(p1, dst); else if ( strncmp(cmd, "bye",3)==0 ) return -1; else if ( *cmd ) - print("\t\033[31m%s is not supported command, %s\n\t%s\n", + print("\033[31m%s is not supported command, %s\n\t%s\n", cmd, "\033[37mtry lcd, lpwd, cd, pwd,", "ls, dir, get, put, ren, rm, del, mkdir, rmdir, bye"); return 0; @@ -1458,13 +1458,14 @@ int sftpHost::read() status( HOST_CONNECTED ); do_callback("Connected", 0); - const char *p; - do { - print("sftp %s", realpath); - if ( (p=ssh_gets("> ", true))==NULL ) break; - } while ( sftp((char *)p)!=-1 ); + const char *cmd; + for (int i=0; i<10; i++) { + cmd = ssh_gets("\033[32msftp> \033[37m", true); + if ( cmd==NULL ) continue; + if ( sftp((char *)cmd)==-1 ) break; + i = 0; + } libssh2_sftp_shutdown(sftp_session); - status( HOST_IDLE ); do_callback("Disonnected", -1); *username = 0; @@ -1477,6 +1478,7 @@ int sftpHost::read() session = NULL; } TCP_Close: + status(HOST_IDLE); closesocket(sock); reader.detach(); return 0; diff --git a/src/ssh2.h b/src/ssh2.h index 246738f..8d71faf 100644 --- a/src/ssh2.h +++ b/src/ssh2.h @@ -1,12 +1,12 @@ // -// "$Id: ssh2.h 3253 2019-05-21 23:48:10 $" +// "$Id: ssh2.h 3252 2020-06-30 13:48:10 $" // // sshHost sftpHost // // host implementation for terminal simulator // to be used with the Fl_Term widget. // -// Copyright 2017-2019 by Yongchao Fan. +// Copyright 2017-2020 by Yongchao Fan. // // This library is free software distributed under GNU GPL 3.0, // see the license at: @@ -62,7 +62,7 @@ class sshHost : public tcpHost { int scp_read_one(const char *rpath, const char *lpath); int scp_write_one(const char *lpath, const char *rpath); - TUNNEL *tun_add( int tun_sock, LIBSSH2_CHANNEL *tun_channel, + TUNNEL *tun_add(int tun_sock, LIBSSH2_CHANNEL *tun_channel, char *localip, unsigned short localport, char *remoteip, unsigned short remoteport); void tun_del(int tun_sock); diff --git a/src/tiny2.cxx b/src/tiny2.cxx index 81f6bfe..a29417b 100644 --- a/src/tiny2.cxx +++ b/src/tiny2.cxx @@ -1,5 +1,5 @@ // -// "$Id: tiny2.cxx 26528 2020-06-20 20:05:10 $" +// "$Id: tiny2.cxx 26440 2020-06-30 10:05:10 $" // // tinyTerm2 -- FLTK based terminal emulator // @@ -694,9 +694,7 @@ void load_dict(const char *fn) _chdir("Documents\\tinyTerm"); } #else - char *homedir = getenv("HOME"); - if ( homedir==NULL ) homedir = getpwuid(getuid())->pw_dir; - if ( chdir(homedir)==0 ) { + if ( chdir(getenv("HOME"))==0 ) { mkdir("tinyTerm", 0755); chdir("tinyTerm"); }