Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yongchaofan committed Jun 30, 2020
1 parent af9d919 commit cbc601b
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 107 deletions.
23 changes: 11 additions & 12 deletions src/Fl_Browser_Input.cxx
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -15,7 +15,6 @@
// https://github.com/yongchaofan/tinyTerm2/issues/new
//
#include "Fl_Browser_Input.h"
#include <string.h>
#ifdef __APPLE__
#define FL_CMD FL_META
#else
Expand All @@ -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);
Expand All @@ -58,15 +57,15 @@ 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() )
return browser->text(id);
else
return NULL;
}
const char * Fl_Browser_Input::next( )
const char * Fl_Browser_Input::next()
{
if ( id<browser->size() )
return browser->text(++id);
Expand All @@ -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 };
Expand Down Expand Up @@ -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;
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/Fl_Browser_Input.h
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -22,7 +22,6 @@

#ifndef _BROWSER_INPUT_H_
#define _BROWSER_INPUT_H_

class Fl_Browser_Input: public Fl_Input {
private:
Fl_Menu_Window *browserWin;
Expand All @@ -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
#endif //_BROWSER_INPUT_H_
40 changes: 23 additions & 17 deletions src/Fl_Term.cxx
Original file line number Diff line number Diff line change
@@ -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
//
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand All @@ -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;
Expand Down Expand Up @@ -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; i<iTimeOut*10 && !bPrompt; i++ ) {
Expand All @@ -1093,7 +1098,7 @@ int Fl_Term::recv(char **preply)
return len;
}

void Fl_Term::connect( const char *hostname )
void Fl_Term::connect(const char *hostname)
{
if ( host!=NULL ) {
if ( host->live() ) return;
Expand Down Expand Up @@ -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 \
";
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
26 changes: 13 additions & 13 deletions src/Fl_Term.h
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down Expand Up @@ -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);
Expand All @@ -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; }
Expand All @@ -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();

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/host.cxx
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down
Loading

0 comments on commit cbc601b

Please sign in to comment.