Commit 3491fc61 authored by Seblu's avatar Seblu
Browse files

Developpement de l'interface

parent 098b1537
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -3,7 +3,9 @@ bin_PROGRAMS= slc
slc_SOURCES=	src/slc.hh		\
		src/slc.cc		\
		src/options.cc		\
		src/options.hh
		src/options.hh		\
		src/screen.hh		\
		src/screen.cc

CLEANFILES= *~ '\#*' .*.swp .*~

+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ AC_ARG_WITH([efence],
  ]
)

LDFLAGS="$LDFLAGS -lssl -lncurses"
LDFLAGS="$LDFLAGS -lssl -lncurses -lpthread"

AC_SUBST([CXXFLAGS])
AC_SUBST([LDFLAGS])

slc/trunk/src/error.cc

0 → 100644
+69 −0
Original line number Diff line number Diff line
#include "error.hh"

Error::Error(int i, const string s)
{
  val_ = i;
  msg_ << s;
}

Error::Error(const Error &e)
{
  val_ = e.val_;
  msg_ << e.msg_.str();
}

void Error::print() const
{
  if (msg_.str() != "")
    std::cerr << msg_.str() << "." << std::endl;
}

string Error::message() const
{
  return msg_.str();
}

int Error::code() const
{
  return val_;
}

void Error::code(int v)
{
  val_ = v;
}

Error &Error::operator=(const Error &rhs)
{
  val_ = rhs.val_;
  msg_.str("");
  msg_ << rhs.msg_.str();
  return *this;
}

ostream &operator<<(ostream &o, const Error &e)
{
  o << e.msg_.str();
  return o;
}

Error &operator<<(Error &e, int val)
{
  e.msg_ << val;
  return e;
}

Error &operator<<(Error &e, const string &s)
{
  e.msg_ << s;
  return e;
}

Error &operator>>(Error &e, const string &s)
{
  string buf = s + e.msg_.str();

  e.msg_.str("");
  e.msg_ << buf;
  return e;
}

slc/trunk/src/error.hh

0 → 100644
+31 −0
Original line number Diff line number Diff line
#ifndef ERROR_HH
# define ERROR_HH

# include <ios>
# include <iostream>
# include <sstream>

typedef std::string string;
typedef std::stringstream sstream;
typedef std::ostream ostream;

class Error
{
public:
  Error(int i, string s = "");
  Error(const Error &e);
  void print() const;
  string message() const;
  int code() const;
  void code(int);
  Error &operator=(const Error &rhs);
  friend ostream &operator<<(ostream &o, const Error &e);
  friend Error &operator<<(Error &e, const string &s);
  friend Error &operator>>(Error &e, const string &s);
  friend Error &operator<<(Error &e, int val);
protected:
  sstream msg_;
  int val_;
};

#endif
+77 −0
Original line number Diff line number Diff line
#include "slc.hh"
#include "screen.hh"

Screen::Screen() {
  msg_ = 0;
  cmd_ = 0;
}

void Screen::init() {
  // Init ncurses
  initscr();

  // register end stop ncurses before exit
  atexit((void (*)(void)) endwin);

  // Set good parameters
  cbreak();
  noecho();
  keypad(stdscr, TRUE);

  refresh();

  //wrefresh(stdscr);
  // Get term dimension
  int row, col;
  getmaxyx(stdscr, row, col);

  // Create msg window
  msg_ = newwin(row - 3, col, 0, 0);
  box(msg_, 0, 0);

  wrefresh(msg_);

  // Create cmd window
  cmd_ = newwin(3, col, row - 3, 0);
  box(cmd_, 0 , 0);

  wmove(cmd_, 1, 1);
  wrefresh(cmd_);

}

void Screen::run() {
  int key;
  int x,y;
  while (1) {
    key = getch();
    getyx(cmd_, y,x);
    switch(key) {
    case KEY_LEFT:
      wmove(cmd_, y, --x);
      break;
    case KEY_RIGHT:
      wmove(cmd_, y, ++x);
      break;
    case 10:
      werase(cmd_);
      box(cmd_, 0, 0);
      wmove(cmd_, 1, 1);
      // exec command
      break;
    case KEY_BACKSPACE:
      if (x <= 1) break;
      wmove(cmd_, y, --x);
      waddch(cmd_, ' ');
      wmove(cmd_, y, x);
      break;
    case KEY_RESIZE:
      wrefresh(cmd_);
      wrefresh(msg_);
      break;
    default:
      waddch(cmd_, key | A_BOLD);
    }
    wrefresh(cmd_);
  }
}
Loading