18static std::string replace(
const Term::Buffer::int_type& c)
22 if(
static_cast<char>(c) ==
'\n') ret =
"\r\n";
24 ret.push_back(
static_cast<char>(c));
28 ret.push_back(
static_cast<char>(c));
33static bool newline_sequence(
const std::string& str)
35 if(str.back() ==
'\n' || str.back() ==
'\r' || str.back() ==
'\036' || str.back() ==
'\036' || str.back() ==
'\025')
return true;
52 case Type::Unbuffered: setbuf(
nullptr, 0);
break;
53 case Type::LineBuffered:
54 case Type::FullBuffered: setbuf(&m_buffer[0], size);
break;
62 if(s !=
nullptr) m_buffer.reserve(
static_cast<std::size_t
>(n));
78 if(ret[0] ==
'\x7f' || ret[0] ==
'\b')
81 if(!m_buffer.empty()) m_buffer.erase(m_buffer.size() - 1);
83 else if(ret[0] ==
'\033')
87 else if(ret[0] <= 31 && ret[0] !=
'\t' && ret[0] !=
'\b' && ret[0] != 127 && ret[0] !=
' ' && ret[0] !=
'\n' && ret[0] !=
'\r') {
continue; }
94 }
while(m_buffer.empty() || !newline_sequence(m_buffer));
102 }
while(m_buffer.empty());
104 setg(&m_buffer[0], &m_buffer[0], &m_buffer[0] + m_buffer.size());
105 return traits_type::to_int_type(m_buffer.at(0));
109 return traits_type::eof();
115 if(c != std::char_traits<Term::Buffer::char_type>::eof())
119 case Type::Unbuffered:
124 case Type::LineBuffered:
126 m_buffer += replace(c);
127 if(
static_cast<char>(c) ==
'\n')
134 case Type::FullBuffered:
136 if(m_buffer.size() >= m_buffer.capacity())
141 m_buffer += replace(c);
void setType(const Term::Buffer::Type &type)
int_type underflow() override
std::streambuf * setbuf(char *s, std::streamsize n) override
Buffer(const Term::Buffer::Type &type=Term::Buffer::Type::LineBuffered, const std::streamsize &size=BUFSIZ)
int_type overflow(int c=std::char_traits< Term::Buffer::char_type >::eof()) override
bool has(const Option &option) const noexcept
std::size_t write(const std::string &str) const
Term::Options getOptions() const noexcept
@ Raw
Set terminal in raw mode.
Term::Terminal & terminal