shithub: nc

ref: cf16e9489a1a90e3a4b17bb03021969d4ea5faed
dir: /a.h/

View raw version
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <mouse.h>
#include <keyboard.h>
#include <thread.h>
#include <plumb.h>
#include <bio.h>


typedef struct Dirview Dirview;
typedef struct Dirpanel Dirpanel;
typedef struct Dirmodel Dirmodel;
typedef struct Text Text;
typedef struct Actionbar Actionbar;
typedef struct Binding Binding;

typedef void(*Action)(void);

struct Dirview
{
	Rectangle	r;
	Image*		b;
	Channel*	c;
	Rectangle	leftr;
	Dirpanel*	leftp;
	Rectangle	rightr;
	Dirpanel*	rightp;
};

struct Dirpanel
{
	Rectangle	r;
	Image*		b;
	Channel*	c;
	Dirmodel*	model;
	int			focused;
	int			nlines;
	int			offset;
	int			cursor;
	Rectangle	intr;
	Rectangle	titler;
	Rectangle	filesr;
	int			colw[3];
};

struct Dirmodel
{
	Channel*	c;
	char*		path;
	int			isroot;
	Dir*		dirs;
	long		ndirs;
	uchar*		sel;
	char*		filter;
	Dir*		fdirs;
	long		fndirs;
};

enum
{
	Maxlines = 65535,
};

struct Text
{
	Image*		b;
	Channel*	c;
	Rectangle	r;
	Rectangle	intr;
	Rectangle	titler;
	Rectangle	textr;
	int			vlines;
	int			offset;
	char*		title;
	char*		data;
	usize		ndata;
	usize		lines[Maxlines];
	int			nlines;
	int			s0;
	int			s1;
};

struct Actionbar
{
	Rectangle	r;
	Image*		b;
	char*		labels[10];
	Action		actions[10];
};

struct Binding
{
	Rune	k;
	Action	f;
};

Dirview*	mkdirview(char*);
void		dirviewsetrect(Dirview*, Rectangle);
void		dirviewredraw(Dirview*);
void		dirviewemouse(Dirview*, Mouse);
Dirpanel*	dirviewcurrentpanel(Dirview*);
Dirpanel*	dirviewotherpanel(Dirview*);

Dirmodel*	mkdirmodel(char*);
Dir			dirmodelgetdir(Dirmodel*, int);
long		dirmodelcount(Dirmodel*);
void		dirmodelreload(Dirmodel*);
void		dirmodelcd(Dirmodel*, char*);
void		dirmodelfilter(Dirmodel*, char*);

Dirpanel*	mkdirpanel(Dirmodel*);
void		dirpanelsetrect(Dirpanel*, Rectangle);
void		dirpanelredraw(Dirpanel*);
void		dirpanelredrawnotify(Dirpanel*);
void		dirpanelemouse(Dirpanel*, Mouse);
void		dirpanelresetcursor(Dirpanel*);
int			dirpanelselectedindex(Dirpanel*);

Text*		mktext(void);
void		textsetrect(Text*, Rectangle);
void		textredraw(Text*);
void		textemouse(Text*, Mouse);
void		textscroll(Text*, int);
void		textset(Text*, char*, char*, usize);

Actionbar*	mkactionbar(void);
void		actionbarsetrect(Actionbar*, Rectangle);
void		actionbarredraw(Actionbar*);
void		actionbaremouse(Actionbar*, Mouse);
void		actionbarclear(Actionbar*);
void		actionbarset(Actionbar*, int, char*, Action);

void		setmode(int);
void		setupdirviewbindings(void);
void		setupviewerbindings(void);

int			match(char*, char*);

Rectangle	boundsrect(Rectangle);
Image*		ealloccolor(ulong);
void*		emalloc(ulong);
void*		erealloc(void*, ulong);
char*		slurp(char*);
char*		homedir(void);
char*		abspath(char*, char*);
int			mkdir(char*, char*);

enum
{
	Mdir,
	Mhelp,
	Mview,
};

enum
{
	Cbg,
	Cfg,
	Clfg,
	Ctitle,
	Cborder,
	Csel,
	Ncols
};
extern Image*		cols[Ncols];
extern Mousectl*	mc;
extern Keyboardctl*	kc;
extern int			mode;
extern Dirview*		dview;
extern Text*		text;
extern Actionbar*	abar;
extern Binding*		bindings;
extern char*		help;