Commit 40458b2c authored by Seblu's avatar Seblu
Browse files

new history system (no history classes)

history can now be save in file and load from file
options load environ
error class are now used
some fixes
parent d93c109b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -6,8 +6,8 @@ slc_SOURCES= src/slc.hh \
		src/options.hh		\
		src/screen.hh		\
		src/screen.cc		\
		src/history.hh		\
		src/history.cc
		src/error.hh		\
		src/error.cc

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

+1 −2
Original line number Diff line number Diff line
Gestion du redimensionnements
Gestion de plus de touche
sauvegarde de l'history dans un fichier
Tout le reste...

slc/trunk/src/history.cc

deleted100644 → 0
+0 −31
Original line number Diff line number Diff line
#include "slc.hh"
#include "history.hh"

History::History(size_t size) : size_(size) {}

History::~History() {
  // save into file;
}

void History::add(const string &line) {
  if (line.empty())
    return;
  if (table_.size() + 1 > size_)
    table_.erase(table_.begin());
  table_.push_back(line);
  ++size_;
}

const string &History::get(size_t off) const {
  assert(table_.size() > 0);
  assert(off < table_.size());
  return table_[table_.size() - 1 - off];
}

const string &History::get() const {
  return table_.back();
}

size_t History::size() const {
  return table_.size();
}

slc/trunk/src/history.hh

deleted100644 → 0
+0 −26
Original line number Diff line number Diff line
#ifndef HISTORY_HH
# define HISTORY_HH

# include <vector>

# define HISTORY_MAX_SIZE 256

class History {
public:
  History(size_t size);
  ~History();

  const string &get(size_t off) const;
  const string &get() const;
  void add(const string &line);
  size_t size() const;

  void save(const string &filename);

private:
  string filename_;
  std::vector<string> table_;
  size_t size_;
};

#endif
+15 −6
Original line number Diff line number Diff line
@@ -2,9 +2,12 @@
#include "options.hh"

#include <getopt.h>
#include <stdlib.h>

Options::Options() {
  port = 18136;
  history_size = 100;
  history_file = (string) getenv("HOME") + "/.slc_history";
}

void Options::usage(const char *name, ostream &out) const {
@@ -56,10 +59,16 @@ Options &Options::load(int argc, char *argv[]) {
  return *this;
}

ostream &operator<< (ostream &s, const Options &o) {
  return s << "server: " << o.server << std::endl
	   << "port: " << o.port << std::endl
	   << "host login: " << o.login << std::endl
	   << "host pass: " << o.pass << std::endl;
}
Options &Options::loadenv() {
  const char *senv;

  // Get history path
  if ((senv = getenv("SLC_HISTORY_FILE")) != 0 && *senv != 0)
    history_file = senv;

  // Get history size
  if ((senv = getenv("SLC_HISTORY_SIZE")) != 0 && *senv != 0)
    history_size = atoi(senv);

  return *this;
}
Loading