version 0.5.0_alpha
git-svn-id: svn://db.shs.com.ru/pip@8 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Code model generator
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "picli.h"
|
||||
#include "picodeparser.h"
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
|
||||
void usage() {
|
||||
piCout << Bold << "PIP Code model generator";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Code model generator
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Remote console viewer
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -19,15 +19,15 @@
|
||||
|
||||
#include "pip.h"
|
||||
|
||||
void key_event(char key, void * );
|
||||
void key_event(PIKbdListener::KeyEvent key, void * );
|
||||
|
||||
PIConsole console(false, key_event);
|
||||
PIStringList as;
|
||||
bool selected = false;
|
||||
|
||||
void key_event(char key, void * ) {
|
||||
if (key < '1' || key > '9') return;
|
||||
int ind = key - '1';
|
||||
void key_event(PIKbdListener::KeyEvent key, void * ) {
|
||||
if (key.key < '1' || key.key > '9') return;
|
||||
int ind = key.key - '1';
|
||||
if (ind < 0 || ind >= as.size_s()) return;
|
||||
selected = true;
|
||||
console.connectToServer(as[ind]);
|
||||
|
||||
@@ -8,20 +8,25 @@ Daemon::Daemon(): PIPeer("_pisd_" + PISystemInfo::instance()->hostname + "_" + P
|
||||
timer.setName("__S__Daemon_timer");
|
||||
enabled = false;
|
||||
mode = offset = cur = height = 0;
|
||||
CONNECTU(&console, keyPressed, this, keyEvent)
|
||||
//CONNECTU(&console, keyPressed, this, keyEvent)
|
||||
CONNECTU(&timer, tickEvent, this, timerEvent)
|
||||
timer.addDelimiter(5);
|
||||
timer.start(200);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::keyEvent(char key) {
|
||||
PIScreenTile * Daemon::tile() const {
|
||||
return new PIScreenTile();
|
||||
}
|
||||
|
||||
|
||||
void Daemon::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
if (!enabled) return;
|
||||
int num = key - '0';
|
||||
int num = key.key - '0';
|
||||
switch (mode) {
|
||||
case 0:
|
||||
if (num >= 0 && num <= 9) {
|
||||
connectToDaemon(dnames.value(key - '0'));
|
||||
connectToDaemon(dnames.value(key.key - '0'));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -33,7 +38,7 @@ void Daemon::keyEvent(char key) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (key) {
|
||||
switch (key.key) {
|
||||
case PIKbdListener::UpArrow:
|
||||
/*cur--;
|
||||
if (cur < 0) cur = 0;
|
||||
@@ -205,14 +210,14 @@ void Daemon::updateConsole() {
|
||||
|
||||
|
||||
void Daemon::tabConnectedHeader(int cols) {
|
||||
console.addString("Connected to: " + connectedDaemon(), 1, PIConsole::BackGreen | PIConsole::Bold);
|
||||
/*console.addString("Connected to: " + connectedDaemon(), 1, PIConsole::BackGreen | PIConsole::Bold);
|
||||
for (int i = 2; i <= cols; ++i)
|
||||
console.addString(" ", i, PIConsole::Green | PIConsole::Inverse);
|
||||
console.addString(" ", i, PIConsole::Green | PIConsole::Inverse);*/
|
||||
}
|
||||
|
||||
|
||||
void Daemon::tabConnect() {
|
||||
startTab();
|
||||
/*startTab();
|
||||
console.addString("Available daemons:");
|
||||
int num = 0;
|
||||
dnames.clear();
|
||||
@@ -221,23 +226,23 @@ void Daemon::tabConnect() {
|
||||
dnames[num] = p;
|
||||
console.addString(" " + PIString(num++) + " - " + p);
|
||||
}
|
||||
finishTab();
|
||||
finishTab();*/
|
||||
}
|
||||
|
||||
|
||||
void Daemon::tabFeature() {
|
||||
startTab();
|
||||
/*startTab();
|
||||
tabConnectedHeader();
|
||||
console.addString("What do you wish to do with this daemon?");
|
||||
console.addString(" 0 - show host info");
|
||||
console.addString(" 1 - file manager");
|
||||
console.addString(" 2 - execute command");
|
||||
finishTab();
|
||||
finishTab();*/
|
||||
}
|
||||
|
||||
|
||||
void Daemon::tabInfo() {
|
||||
startTab(2);
|
||||
/*startTab(2);
|
||||
tabConnectedHeader(2);
|
||||
console.addString("Exec command: " + info_other.execCommand);
|
||||
console.addString(" Executed on " + info_other.execDateTime.toString());
|
||||
@@ -248,5 +253,5 @@ void Daemon::tabInfo() {
|
||||
console.addString("Architecture: " + info_other.architecture);
|
||||
console.addString(" CPU count: " + PIString::fromNumber(info_other.processorsCount));
|
||||
console.addVariable("of this process", &sys_mon_other, 2);
|
||||
finishTab();
|
||||
finishTab();*/
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef DAEMON_H
|
||||
#define DAEMON_H
|
||||
|
||||
#include "piconsole.h"
|
||||
#include "piscreentiles.h"
|
||||
#include "pipeer.h"
|
||||
#include "pisystemmonitor.h"
|
||||
|
||||
extern PIConsole console;
|
||||
extern PISystemMonitor sys_mon;
|
||||
|
||||
class Daemon: public PIPeer {
|
||||
@@ -40,6 +40,8 @@ public:
|
||||
|
||||
PIString connectedDaemon() const;
|
||||
|
||||
PIScreenTile * tile() const;
|
||||
|
||||
private:
|
||||
enum PacketType {
|
||||
RequestHostInfo = 10,
|
||||
@@ -48,7 +50,7 @@ private:
|
||||
|
||||
};
|
||||
|
||||
EVENT_HANDLER1(void, keyEvent, char, key);
|
||||
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, key);
|
||||
EVENT_HANDLER2(void, timerEvent, void * , _d, int, delim);
|
||||
EVENT(menuRequest);
|
||||
void peerDisconnected(const PIString & name);
|
||||
|
||||
@@ -2,21 +2,189 @@
|
||||
#include "shared.h"
|
||||
|
||||
|
||||
FileManager::FileManager() {
|
||||
setName("FileManager");
|
||||
offset = cur = height = 0;
|
||||
enabled = del_commit = false;
|
||||
CONNECTU(&console, keyPressed, this, keyEvent)
|
||||
|
||||
FileManager::TileDir::TileDir(): TileList() {
|
||||
label_path = 0;
|
||||
selection_mode = TileList::MultiSelection;
|
||||
dir = PIDir::current();
|
||||
//dir.setDir("/home/peri4/Documents");
|
||||
dir.setDir("/home/peri4");
|
||||
updateDir();
|
||||
resized = false;
|
||||
}
|
||||
|
||||
|
||||
void FileManager::keyEvent(char key) {
|
||||
if (!enabled) return;
|
||||
if (key == 'D') {
|
||||
bool FileManager::TileDir::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
if (key.key == PIKbdListener::Return) {
|
||||
if (cur < entries.size_s() && cur >= 0) {
|
||||
//piCout << entries[cur];
|
||||
if (entries[cur].isDir()) {
|
||||
prev_pos[dir.path()] = PIPair<int, int>(cur, offset);
|
||||
dir.cd(entries[cur].name());
|
||||
PIPair<int, int> cp = prev_pos.value(dir.path());
|
||||
cur = cp.first;
|
||||
offset = cp.second;
|
||||
selected.clear();
|
||||
updateDir();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return TileList::keyEvent(key);
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::lock() {
|
||||
if (screen && !resized) ((PIScreen*)screen)->lock();
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::unlock() {
|
||||
if (screen && !resized) ((PIScreen*)screen)->unlock();
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::updateDir() {
|
||||
//if (!enabled) return;
|
||||
entries.clear();
|
||||
lock();
|
||||
int pc = cur, po = offset;
|
||||
cur = -1;
|
||||
offset = 0;
|
||||
content.resize(1);
|
||||
content[0] = Row("... Reading ...", CellFormat());
|
||||
unlock();
|
||||
PIVector<PIFile::FileInfo> el = dir.entries(), fl, dl;
|
||||
if (el.isEmpty()) {
|
||||
PIFile::FileInfo fi;
|
||||
fi.path = "..";
|
||||
fi.flags |= PIFile::FileInfo::DotDot | PIFile::FileInfo::Dir;
|
||||
entries << fi;
|
||||
} else {
|
||||
for (int i = 0; i < el.size_s(); ++i) {
|
||||
if (el[i].name() == ".") continue;
|
||||
if (el[i].name() == "..") {
|
||||
dl.push_front(el[i]);
|
||||
continue;
|
||||
}
|
||||
if (el[i].isDir()) dl << el[i];
|
||||
else fl << el[i];
|
||||
}
|
||||
entries << dl << fl;
|
||||
}
|
||||
if (label_path) {
|
||||
label_path->content.resize(1);
|
||||
label_path->content[0].first = dir.absolutePath();
|
||||
}
|
||||
cur = pc;
|
||||
offset = po;
|
||||
buildNames();
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::buildNames() {
|
||||
//if (!enabled) return;
|
||||
lock();
|
||||
content.clear();
|
||||
PIChar t;
|
||||
CharFlags cf = 0;
|
||||
Color cc = Default;
|
||||
PIString fcol, scol;
|
||||
piForeachC (PIFile::FileInfo & e, entries) {
|
||||
if (e.isDir()) {
|
||||
t = '/';
|
||||
cf = Bold;
|
||||
scol = " dir";
|
||||
} else {
|
||||
if (e.perm_user.exec || e.perm_group.exec || e.perm_other.exec) {
|
||||
cf = Bold;
|
||||
cc = Green;
|
||||
t = '*';
|
||||
} else {
|
||||
t = ' ';
|
||||
cf = 0;
|
||||
}
|
||||
scol = PIString::readableSize(e.size);
|
||||
}
|
||||
if (e.isSymbolicLink() && (t != '*')) t = '~';
|
||||
scol = scol.expandRightTo(9, ' ') + "| " + e.time_modification.toString("dd.MM hh:mm:ss") + " | "
|
||||
+ e.perm_user.toString() + " " + e.perm_group.toString() + " " + e.perm_other.toString();
|
||||
fcol = t + e.name();
|
||||
if (fcol.size_s() >= width - 2 - scol.size_s())
|
||||
fcol = fcol.left(width - 5 - scol.size_s()) + "...";
|
||||
fcol.expandRightTo(width - 1 - scol.size_s(), ' ');
|
||||
content << Row(fcol + scol, CellFormat(cc, Transparent, cf));
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::sizeHint(int & w, int & h) const {
|
||||
w = h = 4;
|
||||
}
|
||||
|
||||
|
||||
void FileManager::TileDir::resizeEvent(int w, int h) {
|
||||
resized = true;
|
||||
buildNames();
|
||||
resized = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FileManager::FileManager() {
|
||||
setName("FileManager");
|
||||
enabled = del_commit = false;
|
||||
//CONNECTU(&console, keyPressed, this, keyEvent)
|
||||
//dir.setDir("/home/peri4/Documents");
|
||||
TileSimple * tl;
|
||||
|
||||
tile_root = new PIScreenTile();
|
||||
tile_root->direction = Vertical;
|
||||
PIScreenTile * pt = new PIScreenTile();
|
||||
pt->direction = Horizontal;
|
||||
pt->spacing = 1;
|
||||
pt->back_format.color_back = Cyan;
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
PIScreenTile * panel = new PIScreenTile();
|
||||
TileSimple * plabel = new TileSimple();
|
||||
plabel->size_policy = Fixed;
|
||||
plabel->maximumWidth = 1;
|
||||
panel->direction = Vertical;
|
||||
panels[i] = new TileDir();
|
||||
panels[i]->name = "file panel " + PIString(i);
|
||||
panels[i]->label_path = plabel;
|
||||
panel->addTile(plabel);
|
||||
panel->addTile(panels[i]);
|
||||
panels[i]->updateDir();
|
||||
pt->addTile(panel);
|
||||
}
|
||||
tile_root->addTile(pt);
|
||||
|
||||
PIScreenTile * labels = new PIScreenTile();
|
||||
labels->size_policy = Fixed;
|
||||
labels->direction = Horizontal;
|
||||
PIVector<SSPair> ll;
|
||||
ll << SSPair(" Esc", "Exit") << SSPair(" F5", "Copy") << SSPair(" F6", "Move") << SSPair(" F8", "Delete");
|
||||
piForeachC (SSPair & l, ll) {
|
||||
tl = new TileSimple(); labels->addTile(tl);
|
||||
tl->content << TileSimple::Row(l.first, CellFormat(White, Transparent, Bold));
|
||||
tl = new TileSimple(); labels->addTile(tl);
|
||||
tl->content << TileSimple::Row(l.second, CellFormat(Black, Cyan));
|
||||
}
|
||||
tl = new TileSimple(); labels->addTile(tl);
|
||||
tl->size_policy = Expanding;
|
||||
tile_root->addTile(labels);
|
||||
|
||||
}
|
||||
|
||||
|
||||
PIScreenTile * FileManager::tile() const {
|
||||
return tile_root;
|
||||
}
|
||||
|
||||
|
||||
void FileManager::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
/*if (!enabled) return;
|
||||
if (key.key == 'D') {
|
||||
if (cur >= files.size_s() || cur < 0) return;
|
||||
if (del_commit) {
|
||||
piForeachC (PIString & f, selected) {
|
||||
@@ -38,7 +206,7 @@ void FileManager::keyEvent(char key) {
|
||||
console.clearCustomStatus();
|
||||
del_commit = false;
|
||||
PIStringList nsel;
|
||||
switch (key) {
|
||||
switch (key.key) {
|
||||
case PIKbdListener::UpArrow:
|
||||
cur--;
|
||||
if (cur < 0) cur = 0;
|
||||
@@ -103,80 +271,20 @@ void FileManager::keyEvent(char key) {
|
||||
menuRequest();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void FileManager::updateConsole() {
|
||||
if (!enabled) return;
|
||||
/*if (!enabled) return;
|
||||
startTab(2);
|
||||
console.addString("File manager", 1, PIConsole::Yellow | PIConsole::Inverse);
|
||||
console.addString("Path: " + dir.absolutePath(), 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
|
||||
console.addString("Name", 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
|
||||
console.addString(" ", 2, PIConsole::Yellow | PIConsole::Inverse);
|
||||
console.addString(" ", 2, PIConsole::Green | PIConsole::Inverse);
|
||||
console.addString(" ", 2, PIConsole::Green | PIConsole::Inverse);
|
||||
console.addString("File manager", 1, Yellow | Inverse);
|
||||
console.addString("Path: " + dir.absolutePath(), 1, Green | Inverse | Bold);
|
||||
console.addString("Name", 1, Green | Inverse | Bold);
|
||||
console.addString(" ", 2, Yellow | Inverse);
|
||||
console.addString(" ", 2, Green | Inverse);
|
||||
console.addString(" ", 2, Green | Inverse);
|
||||
buildNames();
|
||||
console.addString("A - select all, D - remove, R - refresh, Esc - exit", 1, PIConsole::Green | PIConsole::Inverse | PIConsole::Bold);
|
||||
finishTab();
|
||||
console.addString("A - select all, D - remove, R - refresh, Esc - exit", 1, Green | Inverse | Bold);
|
||||
finishTab();*/
|
||||
}
|
||||
|
||||
|
||||
void FileManager::buildNames() {
|
||||
if (!enabled) return;
|
||||
height = console.windowHeight() - 10;
|
||||
int is = piClampi(offset, 0, piMaxi(0, files.size_s() - 1)), ie = piClampi(offset + height, 0, files.size_s());
|
||||
console.addString((is > 0) ? (PIString(" /\\ ").repeat(console.windowWidth() / 8)) : " ", 1, PIConsole::Green | PIConsole::Bold);
|
||||
console.addString(" ", 2);
|
||||
PIChar t;
|
||||
PIConsole::FormatFlags f = 0;
|
||||
PIString scol;
|
||||
piCout << cur;
|
||||
for (int i = is; i < ie; ++i) {
|
||||
if (files[i].isDir()) {
|
||||
t = '/';
|
||||
f = PIConsole::Bold;
|
||||
scol = " dir";
|
||||
} else {
|
||||
if (files[i].perm_user.exec || files[i].perm_group.exec || files[i].perm_other.exec) {
|
||||
f = PIConsole::Green | PIConsole::Bold;
|
||||
t = '*';
|
||||
} else {
|
||||
t = ' ';
|
||||
f = 0;
|
||||
}
|
||||
scol = PIString::readableSize(files[i].size);
|
||||
}
|
||||
if (files[i].isSymbolicLink() && (t != '*')) t = '~';
|
||||
scol = scol.expandRightTo(9, ' ') + "| " + files[i].time_modification.toString("dd.MM hh:mm:ss") + " | "
|
||||
+ files[i].perm_user.toString() + " " + files[i].perm_group.toString() + " " + files[i].perm_other.toString();
|
||||
if (i == cur) f |= PIConsole::BackBlue;
|
||||
if (selected.contains(files[i].path)) f |= PIConsole::Yellow | PIConsole::Bold;
|
||||
console.addString(t + files[i].name(), 1, f);
|
||||
console.addString(scol, 2, f);
|
||||
}
|
||||
console.addString((ie < files.size_s()) ? (PIString(" \\/ ").repeat(console.windowWidth() / 8)) : " ", 1, PIConsole::Green | PIConsole::Bold);
|
||||
console.addString(" ", 2);
|
||||
}
|
||||
|
||||
|
||||
void FileManager::updateDir() {
|
||||
if (!enabled) return;
|
||||
files.clear();
|
||||
PIVector<PIFile::FileInfo> el = dir.entries(), fl, dl;
|
||||
for (int i = 0; i < el.size_s(); ++i) {
|
||||
if (el[i].path == ".") continue;
|
||||
if (el[i].path == "..") {
|
||||
dl.push_front(el[i]);
|
||||
continue;
|
||||
}
|
||||
if (el[i].isDir()) dl << el[i];
|
||||
else fl << el[i];
|
||||
}
|
||||
files << dl << fl;
|
||||
if (cur >= files.size_s()) cur = files.size_s() - 1;
|
||||
if (offset >= files.size_s() - height) offset = files.size_s() - height;
|
||||
if (cur < 0) cur = 0;
|
||||
if (offset < 0) offset = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,44 @@
|
||||
#ifndef FILE_MANAGER_H
|
||||
#define FILE_MANAGER_H
|
||||
|
||||
#include "piconsole.h"
|
||||
#include "piscreentiles.h"
|
||||
#include "pidir.h"
|
||||
|
||||
extern PIConsole console;
|
||||
|
||||
class FileManager: public PIObject {
|
||||
PIOBJECT(FileManager)
|
||||
public:
|
||||
FileManager();
|
||||
|
||||
void enable() {enabled = true; updateDir(); updateConsole();}
|
||||
void disable() {enabled = false;}
|
||||
PIScreenTile * tile() const;
|
||||
|
||||
private:
|
||||
EVENT_HANDLER1(void, keyEvent, char, key);
|
||||
class TileDir: public TileList {
|
||||
public:
|
||||
TileDir();
|
||||
void updateDir();
|
||||
void buildNames();
|
||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
||||
void sizeHint(int & w, int & h) const;
|
||||
void resizeEvent(int w, int h);
|
||||
void lock();
|
||||
void unlock();
|
||||
TileSimple * label_path;
|
||||
PIVector<PIFile::FileInfo> entries;
|
||||
PIDir dir;
|
||||
PIMap<PIString, PIPair<int, int> > prev_pos;
|
||||
bool resized;
|
||||
};
|
||||
|
||||
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, key);
|
||||
EVENT(menuRequest);
|
||||
void updateConsole();
|
||||
void updateDir();
|
||||
void buildNames();
|
||||
|
||||
int offset, cur, height;
|
||||
bool enabled, del_commit;
|
||||
PIDir dir;
|
||||
PIVector<PIFile::FileInfo> files;
|
||||
PIMap<PIString, int> prev_pos, prev_off;
|
||||
TileDir * panels[2];
|
||||
PIScreenTile * tile_root;
|
||||
PIStringList selected;
|
||||
typedef PIPair<PIString, PIString> SSPair;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Remote console viewer
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -24,57 +24,117 @@
|
||||
#include "daemon.h"
|
||||
#include "shared.h"
|
||||
|
||||
void key_event(char key, void * );
|
||||
|
||||
class _Init {
|
||||
public:
|
||||
_Init() {srand(PISystemTime::current().toMicroseconds());}
|
||||
};
|
||||
_Init _pisd_init;
|
||||
|
||||
PIConsole console(false, key_event);
|
||||
PIScreen screen(false);
|
||||
PISystemMonitor sys_mon;
|
||||
FileManager file_manager;
|
||||
Daemon daemon_;
|
||||
int mode = 0, oldmode = -1;
|
||||
|
||||
class MenuOperator: public PIObject {
|
||||
PIOBJECT(MenuOperator)
|
||||
|
||||
class MainMenu: public PIObject {
|
||||
PIOBJECT(MainMenu)
|
||||
public:
|
||||
MenuOperator() {
|
||||
MainMenu() {
|
||||
TileSimple * tile = new TileSimple("title");
|
||||
tile->content << TileSimple::Row("pisd (PI System Daemon, PIP version " + PIPVersion() + ")", CellFormat(Black, Transparent));
|
||||
tile->back_format.color_back = Yellow;
|
||||
tile->size_policy = Fixed;
|
||||
screen.rootTile()->addTile(tile);
|
||||
|
||||
PIScreenTile * center = new PIScreenTile("center");
|
||||
center->back_format.color_back = Cyan;
|
||||
center->size_policy = Expanding;
|
||||
center->setMargins(2, 2, 1, 1);
|
||||
screen.rootTile()->addTile(center);
|
||||
|
||||
PIScreenTile * mt = tmenu = menuTile();
|
||||
mt->show(); mt->name = "main menu";
|
||||
center->addTile(mt); mtiles << mt;
|
||||
|
||||
mt = tinfo = infoTile();
|
||||
mt->hide(); mt->name = "local info";
|
||||
center->addTile(mt); mtiles << mt;
|
||||
|
||||
mt = tfm = file_manager.tile();
|
||||
mt->hide(); mt->name = "file manager";
|
||||
center->addTile(mt); mtiles << mt;
|
||||
|
||||
mt = tdaemon = daemon_.tile();
|
||||
mt->hide(); mt->name = "daemon";
|
||||
center->addTile(mt); mtiles << mt;
|
||||
|
||||
CONNECTU(&screen, tileEvent, this, tileEvent)
|
||||
CONNECTU(&screen, keyPressed, this, keyEvent)
|
||||
CONNECTU(&file_manager, menuRequest, this, menuRequest)
|
||||
CONNECTU(&daemon_, menuRequest, this, menuRequest)
|
||||
}
|
||||
EVENT_HANDLER(void, menuRequest) {mode = 0;}
|
||||
};
|
||||
|
||||
MenuOperator menu_operator;
|
||||
|
||||
void key_event(char key, void * ) {
|
||||
if (key == PIKbdListener::Esc) {
|
||||
;//mode = 0;
|
||||
} else {
|
||||
if (mode != 3) {
|
||||
if (key < '0' || key > '9') return;
|
||||
mode = key - '0';
|
||||
PIScreenTile * menuTile() {
|
||||
TileList * ret = new TileList();
|
||||
ret->content << TileList::Row("Show local info", CellFormat());
|
||||
ret->content << TileList::Row("Local file manager", CellFormat());
|
||||
ret->content << TileList::Row("Connect to another daemon", CellFormat());
|
||||
ret->selection_mode = TileList::NoSelection;
|
||||
return ret;
|
||||
}
|
||||
PIScreenTile * infoTile() {
|
||||
TileSimple * ret = new TileSimple();
|
||||
ret->content << TileSimple::Row("Exec command: " + PISystemInfo::instance()->execCommand, CellFormat());
|
||||
ret->content << TileSimple::Row(" Executed on " + PISystemInfo::instance()->execDateTime.toString(), CellFormat());
|
||||
ret->content << TileSimple::Row(" Hostname: " + PISystemInfo::instance()->hostname, CellFormat());
|
||||
ret->content << TileSimple::Row(" Username: " + PISystemInfo::instance()->user, CellFormat());
|
||||
ret->content << TileSimple::Row(" OS name: " + PISystemInfo::instance()->OS_name, CellFormat());
|
||||
ret->content << TileSimple::Row(" OS version: " + PISystemInfo::instance()->OS_version, CellFormat());
|
||||
ret->content << TileSimple::Row("Architecture: " + PISystemInfo::instance()->architecture, CellFormat());
|
||||
ret->content << TileSimple::Row(" CPU count: " + PIString::fromNumber(PISystemInfo::instance()->processorsCount), CellFormat());
|
||||
return ret;
|
||||
}
|
||||
EVENT_HANDLER(void, menuRequest) {
|
||||
piForeach (PIScreenTile * t, mtiles)
|
||||
t->hide();
|
||||
tmenu->show();
|
||||
tmenu->setFocus();
|
||||
}
|
||||
EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e) {
|
||||
if (t == tmenu) {
|
||||
if (e.type == TileList::RowPressed) {
|
||||
piForeach (PIScreenTile * t, mtiles)
|
||||
t->hide();
|
||||
switch (e.data.toInt()) {
|
||||
case 0: tinfo->show(); break;
|
||||
case 1: tfm->show(); break;
|
||||
case 2: tdaemon->show(); break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, e) {
|
||||
if (e.key == PIKbdListener::Esc) menuRequest();
|
||||
//piCout << "key" << e.key;
|
||||
}
|
||||
PIScreenTile * tmenu, * tinfo, * tfm, * tdaemon;
|
||||
PIVector<PIScreenTile * > mtiles;
|
||||
};
|
||||
|
||||
|
||||
void tabMenu() {
|
||||
startTab();
|
||||
/*startTab();
|
||||
console.addString("Select with numeric key:");
|
||||
console.addString(" 0 - this screen");
|
||||
console.addString(" 1 - show host info");
|
||||
console.addString(" 2 - local file manager");
|
||||
console.addString(" 3 - connect to another daemon");
|
||||
finishTab();
|
||||
finishTab();*/
|
||||
}
|
||||
|
||||
|
||||
void tabInfo() {
|
||||
startTab();
|
||||
/*startTab();
|
||||
console.addString("Exec command: " + PISystemInfo::instance()->execCommand);
|
||||
console.addString(" Executed on " + PISystemInfo::instance()->execDateTime.toString());
|
||||
console.addString(" Hostname: " + PISystemInfo::instance()->hostname);
|
||||
@@ -83,9 +143,8 @@ void tabInfo() {
|
||||
console.addString(" OS version: " + PISystemInfo::instance()->OS_version);
|
||||
console.addString("Architecture: " + PISystemInfo::instance()->architecture);
|
||||
console.addString(" CPU count: " + PIString::fromNumber(PISystemInfo::instance()->processorsCount));
|
||||
console.addString(" ", 2, PIConsole::Yellow | PIConsole::Inverse);
|
||||
console.addVariable("of this process", &sys_mon, 2);
|
||||
finishTab();
|
||||
finishTab();*/
|
||||
}
|
||||
|
||||
|
||||
@@ -210,15 +269,16 @@ int main(int argc, char * argv[]) {
|
||||
return 0;*/
|
||||
|
||||
//piCout << Hex << uint(ret) << tm.elapsed_m();
|
||||
piDebug = false;
|
||||
PICLI cli(argc, argv);
|
||||
//cli.addArgument("");
|
||||
sys_mon.startOnSelf();
|
||||
console.enableExitCapture();
|
||||
console.setDefaultAlignment(PIConsole::Right);
|
||||
console.start();
|
||||
//WAIT_FOR_EXIT
|
||||
screen.enableExitCapture(PIKbdListener::F10);
|
||||
MainMenu menu;
|
||||
screen.start();
|
||||
screen.waitForFinish();
|
||||
//return 0;
|
||||
while (!PIKbdListener::exiting) {
|
||||
/*while (!PIKbdListener::exiting) {
|
||||
if (oldmode != mode) {
|
||||
file_manager.disable();
|
||||
daemon_.disable();
|
||||
@@ -239,6 +299,6 @@ int main(int argc, char * argv[]) {
|
||||
}
|
||||
}
|
||||
piMSleep(100);
|
||||
}
|
||||
}*/
|
||||
return 0;
|
||||
};
|
||||
|
||||
@@ -1,22 +1,4 @@
|
||||
#include "piconsole.h"
|
||||
#include "piscreen.h"
|
||||
#include "piscreentiles.h"
|
||||
|
||||
extern PIConsole console;
|
||||
|
||||
inline void header(int cols = 1) {
|
||||
console.addString("PIP System Daemon (PIP " + PIPVersion() + ")", 1, PIConsole::Yellow | PIConsole::Inverse);
|
||||
for (int i = 2; i <= cols; ++i)
|
||||
console.addString(" ", i, PIConsole::Yellow | PIConsole::Inverse);
|
||||
}
|
||||
|
||||
inline void startTab(int cols = 1) {
|
||||
console.pause(true);
|
||||
console.clearTab(0);
|
||||
console.lock();
|
||||
header(cols);
|
||||
}
|
||||
|
||||
inline void finishTab() {
|
||||
console.unlock();
|
||||
console.pause(false);
|
||||
console.update();
|
||||
}
|
||||
using namespace PIScreenTypes;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
System tests program
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -22,12 +22,12 @@
|
||||
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
#ifdef WINDOWS
|
||||
cout << "This program is useless for Windows" << endl;
|
||||
#if defined(WINDOWS) || defined(MAC_OS)
|
||||
piCout << "This program is useless for Windows";
|
||||
return 0;
|
||||
#else
|
||||
if (getuid() != 0) {
|
||||
cout << "You should run this program as root!" << endl;
|
||||
piCout << "You should run this program as root!";
|
||||
return 0;
|
||||
}
|
||||
PIConfig conf(
|
||||
@@ -45,9 +45,9 @@ int main(int argc, char * argv[]) {
|
||||
clock_getres(CLOCK_REALTIME, &ts);
|
||||
stc = long(ts.tv_sec) * 1000000000l + long(ts.tv_nsec);
|
||||
conf.setValue("time_resolution_ns", stc);
|
||||
cout << "Timer resolution is " << stc << " ns" << endl;
|
||||
piCout << "Timer resolution is " << stc << " ns";
|
||||
|
||||
cout << "\"PITimer.elapsed_*\" test ... " << flush;
|
||||
piCout << "\"PITimer.elapsed_*\" test ... ";
|
||||
stc = 0;
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 1000;
|
||||
@@ -73,9 +73,9 @@ int main(int argc, char * argv[]) {
|
||||
}
|
||||
sts /= stc;
|
||||
conf.setValue("time_elapsed_ns", long(sts));
|
||||
cout << "ok, cost " << sts << " ns, average in " << stc << " series (" << (stc * 3 * times.size_s()) << " executes)" << endl;
|
||||
piCout << "ok, cost" << sts << "ns, average in" << stc << "series (" << (stc * 3 * times.size_s()) << "executes)";
|
||||
|
||||
cout << "\"usleep\" offset test ... " << flush;
|
||||
piCout << "\"usleep\" offset test ... ";
|
||||
PISystemTests::time_elapsed_ns = sts;
|
||||
tm.reset();
|
||||
stc = 0;
|
||||
@@ -98,7 +98,7 @@ int main(int argc, char * argv[]) {
|
||||
}
|
||||
sts /= stc;
|
||||
conf.setValue("usleep_offset_us", long(sts));
|
||||
cout << "ok, " << sts << " us, average in " << stc << " series (" << (stc * times.size_s()) << " executes)" << endl;
|
||||
piCout << "ok," << sts << "us, average in" << stc << "series (" << (stc * times.size_s()) << "executes)";
|
||||
|
||||
//WAIT_FOR_EXIT
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user