Skip to content
screen.hh 2.11 KiB
Newer Older
Seblu's avatar
Seblu committed
/*
  This file is part of SLC.
Seblu's avatar
Seblu committed
  Copyright (C) 2008 Sebastien LUTTRINGER <contact@seblu.net>
Seblu's avatar
Seblu committed

  SLC is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
Seblu's avatar
Seblu committed
  the Free Software Foundation; version 2 of the License.
Seblu's avatar
Seblu committed

  SLC is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with SLC; if not, write to the Free Software
Seblu's avatar
Seblu committed
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Seblu's avatar
Seblu committed
*/

Seblu's avatar
Seblu committed
#ifndef SCREEN_HH
# define SCREEN_HH_

# include <ncurses.h>
# include <sstream>
Seblu's avatar
Seblu committed
# include <deque>
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
#define KEY_RETURN 10
#define KEY_EOF 4

typedef std::stringstream sstream;

Seblu's avatar
Seblu committed
class Screen {
public:
Seblu's avatar
Seblu committed
  typedef std::deque<string> t_lines;
Seblu's avatar
Seblu committed
public:
  Screen();
  void init();
  void login();
  void dialog();
  void eventsloop();
  void msg_println(const string &s);
  void msg_println(int i);
  void msg_print(const string &s);
  void msg_print(int i);
Seblu's avatar
Seblu committed
  void socket_reader();
Seblu's avatar
Seblu committed

private:
  void create_windows();
  void cmd_draw();
  void msg_draw();
  void msg_add(const string &s);
  void msg_load(const string &filename);
  void msg_save(const string &filename) const;
  const string &msg_get(size_t i) const;
  size_t msg_size() const;

  bool add_char(char c, char *string, ssize_t offset, size_t buf_len);
  bool del_char(char *string, ssize_t offset, size_t buf_len);
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
private:
  // msg window
Seblu's avatar
Seblu committed
  WINDOW *msg_;
  t_lines msg_table_;
  sstream msg_buffer_;
  char *msg_win_buffer_;
Seblu's avatar
Seblu committed

  // cmd window
Seblu's avatar
Seblu committed
  WINDOW *cmd_;
  char cmd_buffer_[MAX_LINE_SIZE];
  char cmd_history_buffer_[MAX_LINE_SIZE];
  size_t cmd_buf_off_;
  size_t cmd_win_off_;
Seblu's avatar
Seblu committed
  size_t cmd_history_off_;
Screen &operator<< (Screen &, const string &s);
Screen &operator<< (Screen &, int i);
Seblu's avatar
Seblu committed
// exec commands

namespace cmd {
  void exec(const char *);
  void login();
  void logout();
  void user(const char *);
  void pass(const char *);
  void help();
}

Seblu's avatar
Seblu committed
#endif