2018-10-30 13:59:29 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-12-03 01:51:44 +01:00
|
|
|
#include "DoubleBuffer.h"
|
2019-10-20 19:12:00 +13:00
|
|
|
#include <AK/CircularDeque.h>
|
2019-04-03 12:36:40 +02:00
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
2019-01-23 05:13:17 +01:00
|
|
|
#include <Kernel/UnixTypes.h>
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2018-11-16 13:11:21 +01:00
|
|
|
class Process;
|
|
|
|
|
2018-10-30 13:59:29 +01:00
|
|
|
class TTY : public CharacterDevice {
|
|
|
|
public:
|
|
|
|
virtual ~TTY() override;
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
|
|
|
|
virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
|
2019-06-07 09:36:51 +02:00
|
|
|
virtual bool can_read(FileDescription&) const override;
|
|
|
|
virtual bool can_write(FileDescription&) const override;
|
|
|
|
virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override final;
|
|
|
|
virtual String absolute_path(const FileDescription&) const override { return tty_name(); }
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2019-10-18 14:13:43 +02:00
|
|
|
virtual StringView tty_name() const = 0;
|
2018-10-30 15:33:37 +01:00
|
|
|
|
2018-11-29 03:45:23 +01:00
|
|
|
unsigned short rows() const { return m_rows; }
|
|
|
|
unsigned short columns() const { return m_columns; }
|
|
|
|
|
2018-11-02 13:14:25 +01:00
|
|
|
void set_pgid(pid_t pgid) { m_pgid = pgid; }
|
|
|
|
pid_t pgid() const { return m_pgid; }
|
|
|
|
|
2019-01-23 06:53:01 +01:00
|
|
|
void set_termios(const termios&);
|
2018-11-11 15:36:40 +01:00
|
|
|
bool should_generate_signals() const { return m_termios.c_lflag & ISIG; }
|
|
|
|
bool should_echo_input() const { return m_termios.c_lflag & ECHO; }
|
2018-11-16 18:12:22 +01:00
|
|
|
bool in_canonical_mode() const { return m_termios.c_lflag & ICANON; }
|
2018-11-11 15:36:40 +01:00
|
|
|
|
2018-12-07 01:19:02 +01:00
|
|
|
void set_default_termios();
|
2019-02-05 12:55:19 +01:00
|
|
|
void hang_up();
|
2018-12-07 01:19:02 +01:00
|
|
|
|
2018-10-30 13:59:29 +01:00
|
|
|
protected:
|
2019-07-03 21:17:35 +02:00
|
|
|
virtual ssize_t on_tty_write(const u8*, ssize_t) = 0;
|
2018-11-29 03:45:23 +01:00
|
|
|
void set_size(unsigned short columns, unsigned short rows);
|
2018-10-30 22:03:02 +01:00
|
|
|
|
2018-10-30 13:59:29 +01:00
|
|
|
TTY(unsigned major, unsigned minor);
|
2019-07-03 21:17:35 +02:00
|
|
|
void emit(u8);
|
2019-10-20 19:12:00 +13:00
|
|
|
virtual void echo(u8) = 0;
|
|
|
|
|
|
|
|
bool can_do_backspace() const;
|
|
|
|
void do_backspace();
|
|
|
|
void erase_word();
|
|
|
|
void kill_line();
|
|
|
|
|
|
|
|
bool is_eol(u8) const;
|
|
|
|
bool is_eof(u8) const;
|
|
|
|
bool is_kill(u8) const;
|
|
|
|
bool is_erase(u8) const;
|
|
|
|
bool is_werase(u8) const;
|
2018-10-30 15:33:37 +01:00
|
|
|
|
2019-02-05 12:55:19 +01:00
|
|
|
void generate_signal(int signal);
|
|
|
|
|
2019-10-20 19:12:00 +13:00
|
|
|
int m_available_lines { 0 };
|
|
|
|
|
2018-11-16 20:18:58 +01:00
|
|
|
private:
|
|
|
|
// ^CharacterDevice
|
2018-12-03 00:39:25 +01:00
|
|
|
virtual bool is_tty() const final override { return true; }
|
2018-10-30 15:33:37 +01:00
|
|
|
|
2019-10-20 19:12:00 +13:00
|
|
|
CircularDeque<u8, 1024> m_input_buffer;
|
2018-11-02 13:14:25 +01:00
|
|
|
pid_t m_pgid { 0 };
|
2019-01-23 06:53:01 +01:00
|
|
|
termios m_termios;
|
2018-11-29 03:45:23 +01:00
|
|
|
unsigned short m_rows { 0 };
|
|
|
|
unsigned short m_columns { 0 };
|
2018-10-30 13:59:29 +01:00
|
|
|
};
|